initial commit

This commit is contained in:
m.zare
2026-04-10 18:25:21 +03:30
commit 77ca6c34a3
263 changed files with 34470 additions and 0 deletions

View 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)
}