refactor: 修改包 app 为 crud,更加符合语义

main
熊二 1 year ago
parent cd6bf1fea7
commit 5378603349
  1. 4
      internal/services/company/controller/company_controller.go
  2. 4
      internal/services/company/controller/company_department_controller.go
  3. 4
      internal/services/company/controller/company_staff_controller.go
  4. 4
      internal/services/company/service.go
  5. 4
      internal/services/config/controller/config_controller.go
  6. 4
      internal/services/config/controller/config_group_controller.go
  7. 4
      internal/services/config/service.go
  8. 4
      internal/services/feature/controller/feature_category_controller.go
  9. 4
      internal/services/feature/controller/feature_config_controller.go
  10. 4
      internal/services/feature/controller/feature_content_chapter_controller.go
  11. 4
      internal/services/feature/controller/feature_content_controller.go
  12. 4
      internal/services/feature/controller/feature_content_detail_controller.go
  13. 4
      internal/services/feature/controller/feature_controller.go
  14. 4
      internal/services/feature/service.go
  15. 4
      internal/services/resource/controller/resource_category_controller.go
  16. 4
      internal/services/resource/controller/resource_controller.go
  17. 4
      internal/services/resource/service.go
  18. 20
      internal/services/service.go
  19. 4
      internal/services/system/controller/system_log_controller.go
  20. 4
      internal/services/system/controller/system_menu_controller.go
  21. 4
      internal/services/system/controller/system_permission_controller.go
  22. 4
      internal/services/system/controller/system_role_controller.go
  23. 4
      internal/services/system/controller/system_role_power_controller.go
  24. 4
      internal/services/system/controller/system_user_controller.go
  25. 4
      internal/services/system/service.go
  26. 2
      pkg/crud/context.go
  27. 2
      pkg/crud/controller.go
  28. 2
      pkg/crud/echo_utils.go
  29. 2
      pkg/crud/service.go

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/company/request" "sorbet/internal/services/company/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type CompanyController struct { type CompanyController struct {
app.Controller[entities.Company, request.CompanyUpsertRequest] crud.Controller[entities.Company, request.CompanyUpsertRequest]
} }
func (ctr *CompanyController) InitRoutes(r *echo.Group) { func (ctr *CompanyController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/company/request" "sorbet/internal/services/company/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type CompanyDepartmentController struct { type CompanyDepartmentController struct {
app.Controller[entities.CompanyDepartment, request.CompanyDepartmentUpsertRequest] crud.Controller[entities.CompanyDepartment, request.CompanyDepartmentUpsertRequest]
} }
func (c *CompanyDepartmentController) InitRoutes(r *echo.Group) { func (c *CompanyDepartmentController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/company/request" "sorbet/internal/services/company/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type CompanyStaffController struct { type CompanyStaffController struct {
app.Controller[entities.CompanyStaff, request.CompanyStaffUpsertRequest] crud.Controller[entities.CompanyStaff, request.CompanyStaffUpsertRequest]
} }
func (c *CompanyStaffController) InitRoutes(r *echo.Group) { func (c *CompanyStaffController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package company
import ( import (
"sorbet/internal/services/company/controller" "sorbet/internal/services/company/controller"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type Service struct{} type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 1 return 1
} }
func (*Service) Init(ctx *app.Context) error { func (*Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.CompanyController{}) ctx.Routes(&controller.CompanyController{})
ctx.Routes(&controller.CompanyDepartmentController{}) ctx.Routes(&controller.CompanyDepartmentController{})
ctx.Routes(&controller.CompanyStaffController{}) ctx.Routes(&controller.CompanyStaffController{})

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/config/request" "sorbet/internal/services/config/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type ConfigController struct { type ConfigController struct {
app.Controller[entities.Config, request.ConfigUpsertRequest] crud.Controller[entities.Config, request.ConfigUpsertRequest]
} }
func (ctr *ConfigController) InitRoutes(r *echo.Group) { func (ctr *ConfigController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/config/request" "sorbet/internal/services/config/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type ConfigGroupController struct { type ConfigGroupController struct {
app.Controller[entities.ConfigGroup, request.ConfigGroupUpsertRequest] crud.Controller[entities.ConfigGroup, request.ConfigGroupUpsertRequest]
} }
// InitRoutes 实现路由注册接口 // InitRoutes 实现路由注册接口

@ -2,7 +2,7 @@ package config
import ( import (
"sorbet/internal/services/config/controller" "sorbet/internal/services/config/controller"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type Service struct{} type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 0 return 0
} }
func (*Service) Init(ctx *app.Context) error { func (*Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.ConfigGroupController{}) ctx.Routes(&controller.ConfigGroupController{})
ctx.Routes(&controller.ConfigController{}) ctx.Routes(&controller.ConfigController{})
return nil return nil

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/feature/request" "sorbet/internal/services/feature/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type FeatureCategoryController struct { type FeatureCategoryController struct {
app.Controller[entities.FeatureCategory, request.FeatureCategoryUpsertRequest] crud.Controller[entities.FeatureCategory, request.FeatureCategoryUpsertRequest]
} }
func (f *FeatureCategoryController) InitRoutes(r *echo.Group) { func (f *FeatureCategoryController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/feature/request" "sorbet/internal/services/feature/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type FeatureConfigController struct { type FeatureConfigController struct {
app.Controller[entities.FeatureConfig, request.FeatureConfigUpsertRequest] crud.Controller[entities.FeatureConfig, request.FeatureConfigUpsertRequest]
} }
func (f *FeatureConfigController) InitRoutes(r *echo.Group) { func (f *FeatureConfigController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/feature/request" "sorbet/internal/services/feature/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type FeatureContentChapterController struct { type FeatureContentChapterController struct {
app.Controller[entities.FeatureContentChapter, request.FeatureContentChapterUpsertRequest] crud.Controller[entities.FeatureContentChapter, request.FeatureContentChapterUpsertRequest]
} }
func (f *FeatureContentChapterController) InitRoutes(r *echo.Group) { func (f *FeatureContentChapterController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/feature/request" "sorbet/internal/services/feature/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type FeatureContentController struct { type FeatureContentController struct {
app.Controller[entities.FeatureContent, request.FeatureContentUpsertRequest] crud.Controller[entities.FeatureContent, request.FeatureContentUpsertRequest]
} }
func (f *FeatureContentController) InitRoutes(r *echo.Group) { func (f *FeatureContentController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/feature/request" "sorbet/internal/services/feature/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type FeatureContentDetailController struct { type FeatureContentDetailController struct {
app.Controller[entities.FeatureContentDetail, request.FeatureContentDetailUpsertRequest] crud.Controller[entities.FeatureContentDetail, request.FeatureContentDetailUpsertRequest]
} }
func (f *FeatureContentDetailController) InitRoutes(r *echo.Group) { func (f *FeatureContentDetailController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/feature/request" "sorbet/internal/services/feature/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type FeatureController struct { type FeatureController struct {
app.Controller[entities.Feature, request.FeatureUpsertRequest] crud.Controller[entities.Feature, request.FeatureUpsertRequest]
} }
func (f *FeatureController) InitRoutes(r *echo.Group) { func (f *FeatureController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package feature
import ( import (
"sorbet/internal/services/feature/controller" "sorbet/internal/services/feature/controller"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type Service struct{} type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 3 return 3
} }
func (s *Service) Init(ctx *app.Context) error { func (s *Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.FeatureCategoryController{}) ctx.Routes(&controller.FeatureCategoryController{})
ctx.Routes(&controller.FeatureConfigController{}) ctx.Routes(&controller.FeatureConfigController{})
ctx.Routes(&controller.FeatureContentChapterController{}) ctx.Routes(&controller.FeatureContentChapterController{})

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/resource/request" "sorbet/internal/services/resource/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type ResourceCategoryController struct { type ResourceCategoryController struct {
app.Controller[entities.Resource, request.ResourceCategoryUpsertRequest] crud.Controller[entities.Resource, request.ResourceCategoryUpsertRequest]
} }
func (ctr *ResourceCategoryController) InitRoutes(r *echo.Group) { func (ctr *ResourceCategoryController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/resource/request" "sorbet/internal/services/resource/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type ResourceController struct { type ResourceController struct {
app.Controller[entities.Resource, request.ResourceUpsertRequest] crud.Controller[entities.Resource, request.ResourceUpsertRequest]
} }
func (ctr *ResourceController) InitRoutes(r *echo.Group) { func (ctr *ResourceController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package resource
import ( import (
"sorbet/internal/services/resource/controller" "sorbet/internal/services/resource/controller"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type Service struct{} type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 2 return 2
} }
func (*Service) Init(ctx *app.Context) error { func (*Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.ResourceController{}) ctx.Routes(&controller.ResourceController{})
ctx.Routes(&controller.ResourceCategoryController{}) ctx.Routes(&controller.ResourceCategoryController{})
return nil return nil

@ -10,12 +10,14 @@ import (
"sorbet/internal/services/feature" "sorbet/internal/services/feature"
"sorbet/internal/services/resource" "sorbet/internal/services/resource"
"sorbet/internal/services/system" "sorbet/internal/services/system"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
var services []app.Service var services []crud.Service
func Register(service app.Service) error { const ContextEchoKey = "echo_framework"
func Register(service crud.Service) error {
for _, applet := range services { for _, applet := range services {
if applet.Name() == service.Name() { if applet.Name() == service.Name() {
return errors.New("service already registered") return errors.New("service already registered")
@ -25,8 +27,8 @@ func Register(service app.Service) error {
return nil return nil
} }
func Init() { func Init(ctx context.Context) error {
services = []app.Service{ services = []crud.Service{
&config.Service{}, &config.Service{},
&company.Service{}, &company.Service{},
&resource.Service{}, &resource.Service{},
@ -35,15 +37,17 @@ func Init() {
} }
// 按优先级排序 // 按优先级排序
slices.SortFunc(services, func(a, b app.Service) int { slices.SortFunc(services, func(a, b crud.Service) int {
return b.Priority() - a.Priority() return b.Priority() - a.Priority()
}) })
return nil
} }
func Bootstrap(ctx context.Context) error { func Bootstrap(ctx context.Context) error {
e := ctx.Value("echo_framework").(*echo.Echo) e := ctx.Value(ContextEchoKey).(*echo.Echo)
for _, service := range services { for _, service := range services {
err := service.Init(app.NewContext(ctx, e.Group(""))) err := service.Init(crud.NewContext(ctx, e.Group("")))
if err != nil { if err != nil {
return err return err
} }

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/system/request" "sorbet/internal/services/system/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type SystemLogController struct { type SystemLogController struct {
app.Controller[entities.SystemLog, request.SystemLogUpsertRequest] crud.Controller[entities.SystemLog, request.SystemLogUpsertRequest]
} }
func (s *SystemLogController) InitRoutes(r *echo.Group) { func (s *SystemLogController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/system/request" "sorbet/internal/services/system/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type SystemMenuController struct { type SystemMenuController struct {
app.Controller[entities.SystemMenu, request.SystemMenuUpsertRequest] crud.Controller[entities.SystemMenu, request.SystemMenuUpsertRequest]
} }
func (s *SystemMenuController) InitRoutes(r *echo.Group) { func (s *SystemMenuController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/system/request" "sorbet/internal/services/system/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type SystemPermissionController struct { type SystemPermissionController struct {
app.Controller[entities.SystemPermission, request.SystemPermissionUpsertRequest] crud.Controller[entities.SystemPermission, request.SystemPermissionUpsertRequest]
} }
func (s *SystemPermissionController) InitRoutes(r *echo.Group) { func (s *SystemPermissionController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/system/request" "sorbet/internal/services/system/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type SystemRoleController struct { type SystemRoleController struct {
app.Controller[entities.SystemRole, request.SystemRoleUpsertRequest] crud.Controller[entities.SystemRole, request.SystemRoleUpsertRequest]
} }
func (s *SystemRoleController) InitRoutes(r *echo.Group) { func (s *SystemRoleController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/system/request" "sorbet/internal/services/system/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type SystemRolePowerController struct { type SystemRolePowerController struct {
app.Controller[entities.SystemRolePower, request.SystemRolePowerUpsertRequest] crud.Controller[entities.SystemRolePower, request.SystemRolePowerUpsertRequest]
} }
func (s *SystemRolePowerController) InitRoutes(r *echo.Group) { func (s *SystemRolePowerController) InitRoutes(r *echo.Group) {

@ -4,11 +4,11 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"sorbet/internal/entities" "sorbet/internal/entities"
"sorbet/internal/services/system/request" "sorbet/internal/services/system/request"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type SystemUserController struct { type SystemUserController struct {
app.Controller[entities.SystemUser, request.SystemUserUpsertRequest] crud.Controller[entities.SystemUser, request.SystemUserUpsertRequest]
} }
func (s *SystemUserController) InitRoutes(r *echo.Group) { func (s *SystemUserController) InitRoutes(r *echo.Group) {

@ -2,7 +2,7 @@ package system
import ( import (
"sorbet/internal/services/system/controller" "sorbet/internal/services/system/controller"
"sorbet/pkg/app" "sorbet/pkg/crud"
) )
type Service struct{} type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
return 3 return 3
} }
func (s *Service) Init(ctx *app.Context) error { func (s *Service) Init(ctx *crud.Context) error {
ctx.Routes(&controller.SystemLogController{}) ctx.Routes(&controller.SystemLogController{})
ctx.Routes(&controller.SystemMenuController{}) ctx.Routes(&controller.SystemMenuController{})
ctx.Routes(&controller.SystemPermissionController{}) ctx.Routes(&controller.SystemPermissionController{})

@ -1,4 +1,4 @@
package app package crud
import ( import (
"context" "context"

@ -1,4 +1,4 @@
package app package crud
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"

@ -1,4 +1,4 @@
package app package crud
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"

@ -1,4 +1,4 @@
package app package crud
import "github.com/labstack/echo/v4" import "github.com/labstack/echo/v4"
Loading…
Cancel
Save