initial commit
This commit is contained in:
76
internal/delivery/http/backoffice/back_office.go
Normal file
76
internal/delivery/http/backoffice/back_office.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package backoffice
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog"
|
||||
"go.uber.org/fx"
|
||||
|
||||
"base/config"
|
||||
appProfileRole "base/internal/application/profilerole"
|
||||
"base/internal/server/middleware"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
logger zerolog.Logger
|
||||
middleware middleware.Middleware
|
||||
config *config.AppConfig
|
||||
e *gin.Engine
|
||||
profileRoleService appProfileRole.Service
|
||||
}
|
||||
|
||||
type Param struct {
|
||||
Logger zerolog.Logger
|
||||
Engine *gin.Engine
|
||||
Middleware middleware.Middleware
|
||||
Config *config.AppConfig
|
||||
ProfileRoleService appProfileRole.Service
|
||||
|
||||
fx.In
|
||||
}
|
||||
|
||||
func New(lc fx.Lifecycle, param Param) *Controller {
|
||||
c := &Controller{
|
||||
logger: param.Logger,
|
||||
middleware: param.Middleware,
|
||||
config: param.Config,
|
||||
e: param.Engine,
|
||||
profileRoleService: param.ProfileRoleService,
|
||||
}
|
||||
|
||||
lc.Append(
|
||||
fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
c.SetupRouter()
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// getMaxFileSize returns the maximum file size in bytes from configuration
|
||||
func (ctl *Controller) getMaxFileSize() int64 {
|
||||
return ctl.config.Server.GetMaxFileSizeBytes()
|
||||
}
|
||||
|
||||
func (ctl *Controller) SetupRouter() {
|
||||
router := ctl.e.Group("/api/v1")
|
||||
ctl.registerRoutes(router)
|
||||
}
|
||||
|
||||
func (ctl *Controller) registerRoutes(router *gin.RouterGroup) {
|
||||
backofficeRouter := router.Group("/backoffice")
|
||||
profileRoleRouter := backofficeRouter.Group("/profile-roles")
|
||||
profileRoleRouter.GET("", ctl.ListProfileRoles)
|
||||
profileRoleRouter.GET("/:id", ctl.GetProfileRole)
|
||||
protected := profileRoleRouter.Use(ctl.middleware.AuthShield())
|
||||
protected.POST("", ctl.CreateProfileRole)
|
||||
protected.PUT("/:id", ctl.UpdateProfileRole)
|
||||
protected.DELETE("/:id", ctl.DeleteProfileRole)
|
||||
}
|
||||
Reference in New Issue
Block a user