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"
"sorbet/internal/entities"
"sorbet/internal/services/company/request"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type CompanyController struct {
app.Controller[entities.Company, request.CompanyUpsertRequest]
crud.Controller[entities.Company, request.CompanyUpsertRequest]
}
func (ctr *CompanyController) InitRoutes(r *echo.Group) {

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

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

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

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

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

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

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

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

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

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

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

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

@ -2,7 +2,7 @@ package feature
import (
"sorbet/internal/services/feature/controller"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
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.FeatureConfigController{})
ctx.Routes(&controller.FeatureContentChapterController{})

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

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

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

@ -10,12 +10,14 @@ import (
"sorbet/internal/services/feature"
"sorbet/internal/services/resource"
"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 {
if applet.Name() == service.Name() {
return errors.New("service already registered")
@ -25,8 +27,8 @@ func Register(service app.Service) error {
return nil
}
func Init() {
services = []app.Service{
func Init(ctx context.Context) error {
services = []crud.Service{
&config.Service{},
&company.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 nil
}
func Bootstrap(ctx context.Context) error {
e := ctx.Value("echo_framework").(*echo.Echo)
e := ctx.Value(ContextEchoKey).(*echo.Echo)
for _, service := range services {
err := service.Init(app.NewContext(ctx, e.Group("")))
err := service.Init(crud.NewContext(ctx, e.Group("")))
if err != nil {
return err
}

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

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

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

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

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

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

@ -2,7 +2,7 @@ package system
import (
"sorbet/internal/services/system/controller"
"sorbet/pkg/app"
"sorbet/pkg/crud"
)
type Service struct{}
@ -15,7 +15,7 @@ func (*Service) Priority() int {
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.SystemMenuController{})
ctx.Routes(&controller.SystemPermissionController{})

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

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

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

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