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

65 lines
2.0 KiB
Go
Raw Normal View History

2025-09-19 07:40:54 +00:00
package chat_history
import (
"narasi-ahli-be/app/module/chat_history/controller"
"narasi-ahli-be/app/module/chat_history/repository"
"narasi-ahli-be/app/module/chat_history/service"
"github.com/gofiber/fiber/v2"
"go.uber.org/fx"
)
// struct of ChatHistoryRouter
type ChatHistoryRouter struct {
App fiber.Router
Controller controller.ChatHistoryController
}
// register bulky of Chat History module
var NewChatHistoryModule = fx.Options(
// register repository of Chat History module
fx.Provide(repository.NewChatHistoryRepository),
// register service of Chat History module
fx.Provide(service.NewChatHistoryService),
// register controller of Chat History module
fx.Provide(controller.NewChatHistoryController),
// register router of Chat History module
fx.Provide(NewChatHistoryRouter),
)
// init ChatHistoryRouter
func NewChatHistoryRouter(fiber *fiber.App, controller controller.ChatHistoryController) *ChatHistoryRouter {
return &ChatHistoryRouter{
App: fiber,
Controller: controller,
}
}
// register routes of Chat History module
func (_i *ChatHistoryRouter) RegisterChatHistoryRoutes() {
// define controllers
chatHistoryController := _i.Controller
// define routes
_i.App.Route("/chat-history", func(router fiber.Router) {
// Sessions routes
router.Get("/sessions", chatHistoryController.GetUserSessions)
router.Get("/sessions/:sessionId", chatHistoryController.GetSession)
router.Post("/sessions", chatHistoryController.CreateSession)
router.Put("/sessions/:sessionId", chatHistoryController.UpdateSession)
router.Delete("/sessions/:sessionId", chatHistoryController.DeleteSession)
// Messages routes
router.Get("/sessions/:sessionId/messages", chatHistoryController.GetSessionMessages)
router.Post("/sessions/:sessionId/messages", chatHistoryController.CreateMessage)
router.Put("/messages/:messageId", chatHistoryController.UpdateMessage)
router.Delete("/messages/:messageId", chatHistoryController.DeleteMessage)
// Combined operations
router.Post("/save", chatHistoryController.SaveChatHistory)
})
}