业务模块化

main
熊二 1 year ago
parent b7f1f714ce
commit b3c82d7d6d
  1. 17
      internal/services/config/controller/config_group_controller.go
  2. 34
      internal/services/config/request/config_group_upsert_request.go
  3. 23
      internal/services/config/service.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)
}

@ -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,
}
}

@ -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
}
Loading…
Cancel
Save