kontenhumas-be/app/module/custom_static_pages/custom_static_pages.module.go

55 lines
1.7 KiB
Go

package custom_static_pages
import (
"github.com/gofiber/fiber/v2"
"go.uber.org/fx"
"netidhub-saas-be/app/module/custom_static_pages/controller"
"netidhub-saas-be/app/module/custom_static_pages/repository"
"netidhub-saas-be/app/module/custom_static_pages/service"
)
// struct of CustomStaticPagesRouter
type CustomStaticPagesRouter struct {
App fiber.Router
Controller *controller.Controller
}
// register bulky of CustomStaticPages module
var NewCustomStaticPagesModule = fx.Options(
// register repository of CustomStaticPages module
fx.Provide(repository.NewCustomStaticPagesRepository),
// register service of CustomStaticPages module
fx.Provide(service.NewCustomStaticPagesService),
// register controller of CustomStaticPages module
fx.Provide(controller.NewController),
// register router of CustomStaticPages module
fx.Provide(NewCustomStaticPagesRouter),
)
// init CustomStaticPagesRouter
func NewCustomStaticPagesRouter(fiber *fiber.App, controller *controller.Controller) *CustomStaticPagesRouter {
return &CustomStaticPagesRouter{
App: fiber,
Controller: controller,
}
}
// register routes of CustomStaticPages module
func (_i *CustomStaticPagesRouter) RegisterCustomStaticPagesRoutes() {
// define controllers
customStaticPagesController := _i.Controller.CustomStaticPages
// define routes
_i.App.Route("/custom-static-pages", func(router fiber.Router) {
router.Get("/", customStaticPagesController.All)
router.Get("/:id", customStaticPagesController.Show)
router.Get("/slug/:slug", customStaticPagesController.ShowBySlug)
router.Post("/", customStaticPagesController.Save)
router.Put("/:id", customStaticPagesController.Update)
router.Delete("/:id", customStaticPagesController.Delete)
})
}