diff --git a/internal/services/config/controller/config_group_controller.go b/internal/services/config/controller/config_group_controller.go new file mode 100644 index 0000000..4ff0b53 --- /dev/null +++ b/internal/services/config/controller/config_group_controller.go @@ -0,0 +1,17 @@ +package controller + +import ( + "github.com/labstack/echo/v4" + "sorbet/internal/entities" + "sorbet/internal/services/config/request" + "sorbet/internal/util" +) + +type ConfigGroupController struct { + util.Controller[entities.ConfigGroup, request.ConfigGroupUpsertRequest] +} + +// InitRoutes 实现路由注册接口 +func (ctr *ConfigGroupController) InitRoutes(r *echo.Group) { + ctr.RegisterRoutes("/config/groups", r) +} diff --git a/internal/services/config/request/config_group_upsert_request.go b/internal/services/config/request/config_group_upsert_request.go new file mode 100644 index 0000000..d94ce17 --- /dev/null +++ b/internal/services/config/request/config_group_upsert_request.go @@ -0,0 +1,34 @@ +package request + +import ( + "sorbet/internal/entities" + "sorbet/pkg/db" +) + +type ConfigGroupUpsertRequest struct { + ID uint `json:"id" xml:"id" path:"id"` + Name string `json:"name" xml:"name" form:"name"` + Description string `json:"description" xml:"description" form:"description"` + Sort int32 `json:"sort" xml:"sort" form:"sort"` +} + +func (c *ConfigGroupUpsertRequest) GetID() any { + return c.ID +} + +func (c *ConfigGroupUpsertRequest) ToEntity() *entities.ConfigGroup { + return &entities.ConfigGroup{ + Name: c.Name, + Description: c.Description, + Sort: c.Sort, + Version: db.Version{Int64: 1, Valid: true}, + } +} + +func (c *ConfigGroupUpsertRequest) ToMap() map[string]any { + return map[string]any{ + "name": c.Name, + "description": c.Description, + "sort": c.Sort, + } +} diff --git a/internal/services/config/service.go b/internal/services/config/service.go new file mode 100644 index 0000000..896abae --- /dev/null +++ b/internal/services/config/service.go @@ -0,0 +1,23 @@ +package config + +import ( + "sorbet/internal/services/config/controller" + "sorbet/pkg/app" +) + +type Service struct { +} + +func (s *Service) Init(ctx *app.Context) error { + ctx.Routes(&controller.ConfigGroupController{}) + ctx.Routes(&controller.ConfigController{}) + return nil +} + +func (s *Service) Start() error { + return nil +} + +func (s *Service) Stop() error { + return nil +}