From b3c82d7d6d486bea8b6b3d1194d8af057c805ef1 Mon Sep 17 00:00:00 2001 From: hupeh Date: Tue, 19 Sep 2023 23:59:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=A8=A1=E5=9D=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/config_group_controller.go | 17 ++++++++++ .../request/config_group_upsert_request.go | 34 +++++++++++++++++++ internal/services/config/service.go | 23 +++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 internal/services/config/controller/config_group_controller.go create mode 100644 internal/services/config/request/config_group_upsert_request.go create mode 100644 internal/services/config/service.go 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 +}