narasiahli-be/app/module/chat/chat.module.go

101 lines
3.7 KiB
Go
Raw Normal View History

2025-09-22 13:05:40 +00:00
package chat
import (
"narasi-ahli-be/app/module/chat/controller"
"narasi-ahli-be/app/module/chat/repository"
"narasi-ahli-be/app/module/chat/service"
"github.com/gofiber/fiber/v2"
"go.uber.org/fx"
)
// struct of ChatRouter
type ChatRouter struct {
App fiber.Router
Controller *controller.Controller
}
// register bulky of Chat module
var NewChatModule = fx.Options(
// register repository of Chat module
fx.Provide(repository.NewChatRepository),
2025-09-22 18:47:06 +00:00
fx.Provide(repository.NewChatScheduleRepository),
fx.Provide(repository.NewChatScheduleFileRepository),
2025-09-22 13:05:40 +00:00
// register service of Chat module
fx.Provide(service.NewChatService),
2025-09-22 18:47:06 +00:00
fx.Provide(service.NewChatScheduleService),
fx.Provide(service.NewChatScheduleFileService),
2025-09-22 13:05:40 +00:00
// register controller of Chat module
fx.Provide(controller.NewController),
2025-09-22 18:47:06 +00:00
fx.Provide(controller.NewChatScheduleController),
fx.Provide(controller.NewChatScheduleFileController),
2025-09-22 13:05:40 +00:00
// register router of Chat module
fx.Provide(NewChatRouter),
)
// init ChatRouter
func NewChatRouter(fiber *fiber.App, controller *controller.Controller) *ChatRouter {
return &ChatRouter{
App: fiber,
Controller: controller,
}
}
// register routes of Chat module
func (_i *ChatRouter) RegisterChatRoutes() {
// define controllers
chatController := _i.Controller.Chat
2025-09-22 18:47:06 +00:00
chatScheduleController := _i.Controller.ChatSchedule
chatScheduleFileController := _i.Controller.ChatScheduleFile
2025-09-22 13:05:40 +00:00
// define routes
_i.App.Route("/chat", func(router fiber.Router) {
// Chat Session routes
router.Route("/sessions", func(sessionRouter fiber.Router) {
sessionRouter.Get("/", chatController.GetAllChatSessions)
sessionRouter.Get("/:id", chatController.GetChatSessionByID)
sessionRouter.Post("/", chatController.CreateChatSession)
sessionRouter.Put("/:id", chatController.UpdateChatSession)
sessionRouter.Delete("/:id", chatController.DeleteChatSession)
// Chat Participant routes
sessionRouter.Post("/:chatSessionId/participants", chatController.AddParticipantToChat)
sessionRouter.Delete("/:chatSessionId/participants", chatController.RemoveParticipantFromChat)
})
// Chat Message routes
router.Route("/messages", func(messageRouter fiber.Router) {
messageRouter.Get("/", chatController.GetAllChatMessages)
messageRouter.Get("/:id", chatController.GetChatMessageByID)
messageRouter.Post("/", chatController.CreateChatMessage)
messageRouter.Put("/:id", chatController.UpdateChatMessage)
messageRouter.Delete("/:id", chatController.DeleteChatMessage)
})
2025-09-22 18:47:06 +00:00
// Chat Schedule routes
router.Route("/schedules", func(scheduleRouter fiber.Router) {
scheduleRouter.Get("/", chatScheduleController.GetAllChatSchedules)
scheduleRouter.Get("/upcoming", chatScheduleController.GetUpcomingSchedules)
scheduleRouter.Get("/status/:status", chatScheduleController.GetSchedulesByStatus)
scheduleRouter.Get("/:id", chatScheduleController.GetChatScheduleByID)
scheduleRouter.Post("/", chatScheduleController.CreateChatSchedule)
scheduleRouter.Put("/:id", chatScheduleController.UpdateChatSchedule)
scheduleRouter.Delete("/:id", chatScheduleController.DeleteChatSchedule)
scheduleRouter.Post("/:id/reminder", chatScheduleController.SendScheduleReminder)
})
// Chat Schedule File routes
router.Route("/schedule-files", func(fileRouter fiber.Router) {
fileRouter.Get("/", chatScheduleFileController.GetChatScheduleFiles)
fileRouter.Get("/:id", chatScheduleFileController.GetChatScheduleFileByID)
fileRouter.Post("/:chatScheduleId", chatScheduleFileController.UploadChatScheduleFile)
fileRouter.Put("/:id", chatScheduleFileController.UpdateChatScheduleFile)
fileRouter.Delete("/:id", chatScheduleFileController.DeleteChatScheduleFile)
fileRouter.Get("/viewer/:filename", chatScheduleFileController.Viewer)
})
2025-09-22 13:05:40 +00:00
})
}