refactor: split backend transport and domain modules
This commit is contained in:
@@ -15,69 +15,18 @@ type API struct {
|
||||
Method string
|
||||
}
|
||||
|
||||
type MenuButton struct {
|
||||
ID uint
|
||||
Name string
|
||||
Description string
|
||||
MenuID uint
|
||||
AuthorityID uint
|
||||
}
|
||||
|
||||
type MenuParameter struct {
|
||||
ID uint
|
||||
MenuID uint
|
||||
Type string
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
type Department struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
ParentID uint
|
||||
Ancestors string
|
||||
Sort int
|
||||
LeaderID uint
|
||||
Status bool
|
||||
Children []*Department
|
||||
}
|
||||
|
||||
type Position struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
Code string
|
||||
Sort int
|
||||
Status bool
|
||||
Remark string
|
||||
}
|
||||
|
||||
type AccessRepo interface {
|
||||
CreateAuthority(context.Context, *Authority) error
|
||||
CopyAuthority(context.Context, uint, *Authority) error
|
||||
UpdateAuthority(context.Context, *Authority) error
|
||||
DeleteAuthority(context.Context, uint) error
|
||||
ListAuthorities(context.Context) ([]*Authority, error)
|
||||
SetAuthorityMenus(context.Context, uint, []uint) error
|
||||
AuthorityMenuIDs(context.Context, uint) ([]uint, error)
|
||||
SetAuthorityUsers(context.Context, uint, []uint) error
|
||||
AuthorityUserIDs(context.Context, uint) ([]uint, error)
|
||||
SetDataScope(context.Context, uint, int, []uint) error
|
||||
DataScopeDepartmentIDs(context.Context, uint) ([]uint, error)
|
||||
ResolveDataScope(context.Context, uint, uint) (DataScope, error)
|
||||
|
||||
CreateMenu(context.Context, *Menu) error
|
||||
UpdateMenu(context.Context, *Menu) error
|
||||
DeleteMenu(context.Context, uint) error
|
||||
FindMenu(context.Context, uint) (*Menu, error)
|
||||
ListMenus(context.Context) ([]*Menu, error)
|
||||
MenuRoleIDs(context.Context, uint) ([]uint, error)
|
||||
SetMenuRoles(context.Context, uint, []uint) error
|
||||
ReplaceMenuButtons(context.Context, uint, []*MenuButton) error
|
||||
|
||||
CreateAPI(context.Context, *API) error
|
||||
UpdateAPI(context.Context, *API) error
|
||||
DeleteAPIs(context.Context, []uint) error
|
||||
@@ -98,24 +47,6 @@ type AccessRepo interface {
|
||||
SelectedButtons(context.Context, uint, uint) ([]uint, error)
|
||||
SetSelectedButtons(context.Context, uint, uint, []uint) error
|
||||
CanRemoveButton(context.Context, uint) (bool, error)
|
||||
|
||||
CreateDepartment(context.Context, *Department) error
|
||||
UpdateDepartment(context.Context, *Department) error
|
||||
DeleteDepartment(context.Context, uint) error
|
||||
FindDepartment(context.Context, uint) (*Department, error)
|
||||
ListDepartments(context.Context, string) ([]*Department, error)
|
||||
DepartmentUserIDs(context.Context, uint) ([]uint, error)
|
||||
SetDepartmentUsers(context.Context, uint, []uint) error
|
||||
SetUserDepartments(context.Context, uint, []uint, uint) error
|
||||
|
||||
CreatePosition(context.Context, *Position) error
|
||||
UpdatePosition(context.Context, *Position) error
|
||||
DeletePosition(context.Context, uint) error
|
||||
FindPosition(context.Context, uint) (*Position, error)
|
||||
ListPositions(context.Context, int, int, *Position) ([]*Position, int64, error)
|
||||
PositionUserIDs(context.Context, uint) ([]uint, error)
|
||||
SetPositionUsers(context.Context, uint, []uint) error
|
||||
SetUserPositions(context.Context, uint, []uint) error
|
||||
}
|
||||
|
||||
type AccessUsecase struct{ repo AccessRepo }
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ package biz
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSet is biz providers.
|
||||
var ProviderSet = wire.NewSet(NewSystemUsecase, NewAccessUsecase, NewSettingsUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewTaskUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase)
|
||||
var ProviderSet = wire.NewSet(NewSystemUsecase, NewAccessUsecase, NewMenuUsecase, NewOrganizationUsecase, NewSettingsUsecase, NewVersionUsecase, NewExportUsecase, NewAuditUsecase, NewTaskUsecase, NewMediaUsecase, NewAnnouncementUsecase, NewEmailUsecase)
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package biz
|
||||
|
||||
import "context"
|
||||
|
||||
type MenuButton struct {
|
||||
ID uint
|
||||
Name string
|
||||
Description string
|
||||
MenuID uint
|
||||
AuthorityID uint
|
||||
}
|
||||
|
||||
type MenuParameter struct {
|
||||
ID uint
|
||||
MenuID uint
|
||||
Type string
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
ID uint
|
||||
ParentID uint
|
||||
Path string
|
||||
Name string
|
||||
Hidden bool
|
||||
Component string
|
||||
Sort int
|
||||
ActiveName string
|
||||
KeepAlive bool
|
||||
DefaultMenu bool
|
||||
Title string
|
||||
Icon string
|
||||
CloseTab bool
|
||||
TransitionType string
|
||||
Children []*Menu
|
||||
Buttons []*MenuButton
|
||||
Parameters []*MenuParameter
|
||||
}
|
||||
|
||||
type MenuRepo interface {
|
||||
Create(context.Context, *Menu) error
|
||||
Update(context.Context, *Menu) error
|
||||
Delete(context.Context, uint) error
|
||||
Find(context.Context, uint) (*Menu, error)
|
||||
List(context.Context) ([]*Menu, error)
|
||||
SetAuthorityMenus(context.Context, uint, []uint) error
|
||||
AuthorityMenuIDs(context.Context, uint) ([]uint, error)
|
||||
MenuRoleIDs(context.Context, uint) ([]uint, error)
|
||||
SetMenuRoles(context.Context, uint, []uint) error
|
||||
}
|
||||
|
||||
type MenuUsecase struct{ repo MenuRepo }
|
||||
|
||||
func NewMenuUsecase(repo MenuRepo) *MenuUsecase { return &MenuUsecase{repo: repo} }
|
||||
|
||||
func (uc *MenuUsecase) List(ctx context.Context) ([]*Menu, error) {
|
||||
return uc.repo.List(ctx)
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) Tree(ctx context.Context) ([]*Menu, error) {
|
||||
items, err := uc.repo.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
byID := make(map[uint]*Menu, len(items))
|
||||
for _, item := range items {
|
||||
item.Children = []*Menu{}
|
||||
byID[item.ID] = item
|
||||
}
|
||||
roots := make([]*Menu, 0)
|
||||
for _, item := range items {
|
||||
if parent := byID[item.ParentID]; parent != nil {
|
||||
parent.Children = append(parent.Children, item)
|
||||
} else {
|
||||
roots = append(roots, item)
|
||||
}
|
||||
}
|
||||
return roots, nil
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) Create(ctx context.Context, menu *Menu) error {
|
||||
return uc.repo.Create(ctx, menu)
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) Update(ctx context.Context, menu *Menu) error {
|
||||
return uc.repo.Update(ctx, menu)
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) Delete(ctx context.Context, id uint) error {
|
||||
return uc.repo.Delete(ctx, id)
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) Find(ctx context.Context, id uint) (*Menu, error) {
|
||||
return uc.repo.Find(ctx, id)
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) SetAuthorityMenus(ctx context.Context, authorityID uint, ids []uint) error {
|
||||
return uc.repo.SetAuthorityMenus(ctx, authorityID, ids)
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) AuthorityMenus(ctx context.Context, authorityID uint) ([]*Menu, error) {
|
||||
ids, err := uc.repo.AuthorityMenuIDs(ctx, authorityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items, err := uc.repo.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selected := make(map[uint]struct{}, len(ids))
|
||||
for _, id := range ids {
|
||||
selected[id] = struct{}{}
|
||||
}
|
||||
result := make([]*Menu, 0, len(ids))
|
||||
for _, item := range items {
|
||||
if _, ok := selected[item.ID]; ok {
|
||||
// The authority-menu endpoint returns menu relations only. Keep its
|
||||
// existing contract: button details are loaded by the dedicated
|
||||
// authority-button endpoints.
|
||||
item.Buttons = nil
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) RoleIDs(ctx context.Context, menuID uint) ([]uint, error) {
|
||||
return uc.repo.MenuRoleIDs(ctx, menuID)
|
||||
}
|
||||
|
||||
func (uc *MenuUsecase) SetRoles(ctx context.Context, menuID uint, ids []uint) error {
|
||||
return uc.repo.SetMenuRoles(ctx, menuID, ids)
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Department struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
ParentID uint
|
||||
Ancestors string
|
||||
Sort int
|
||||
LeaderID uint
|
||||
Status bool
|
||||
Children []*Department
|
||||
}
|
||||
|
||||
type Position struct {
|
||||
ID uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string
|
||||
Code string
|
||||
Sort int
|
||||
Status bool
|
||||
Remark string
|
||||
}
|
||||
|
||||
type OrganizationRepo interface {
|
||||
CreateDepartment(context.Context, *Department) error
|
||||
UpdateDepartment(context.Context, *Department) error
|
||||
DeleteDepartment(context.Context, uint) error
|
||||
FindDepartment(context.Context, uint) (*Department, error)
|
||||
ListDepartments(context.Context, string) ([]*Department, error)
|
||||
DepartmentUserIDs(context.Context, uint) ([]uint, error)
|
||||
SetDepartmentUsers(context.Context, uint, []uint) error
|
||||
SetUserDepartments(context.Context, uint, []uint, uint) error
|
||||
CreatePosition(context.Context, *Position) error
|
||||
UpdatePosition(context.Context, *Position) error
|
||||
DeletePosition(context.Context, uint) error
|
||||
FindPosition(context.Context, uint) (*Position, error)
|
||||
ListPositions(context.Context, int, int, *Position) ([]*Position, int64, error)
|
||||
PositionUserIDs(context.Context, uint) ([]uint, error)
|
||||
SetPositionUsers(context.Context, uint, []uint) error
|
||||
SetUserPositions(context.Context, uint, []uint) error
|
||||
}
|
||||
|
||||
type OrganizationUsecase struct{ repo OrganizationRepo }
|
||||
|
||||
func NewOrganizationUsecase(repo OrganizationRepo) *OrganizationUsecase {
|
||||
return &OrganizationUsecase{repo: repo}
|
||||
}
|
||||
|
||||
func (uc *OrganizationUsecase) Departments(ctx context.Context, name string) ([]*Department, error) {
|
||||
return uc.repo.ListDepartments(ctx, name)
|
||||
}
|
||||
func (uc *OrganizationUsecase) CreateDepartment(ctx context.Context, value *Department) error {
|
||||
return uc.repo.CreateDepartment(ctx, value)
|
||||
}
|
||||
func (uc *OrganizationUsecase) UpdateDepartment(ctx context.Context, value *Department) error {
|
||||
return uc.repo.UpdateDepartment(ctx, value)
|
||||
}
|
||||
func (uc *OrganizationUsecase) DeleteDepartment(ctx context.Context, id uint) error {
|
||||
return uc.repo.DeleteDepartment(ctx, id)
|
||||
}
|
||||
func (uc *OrganizationUsecase) Department(ctx context.Context, id uint) (*Department, error) {
|
||||
return uc.repo.FindDepartment(ctx, id)
|
||||
}
|
||||
func (uc *OrganizationUsecase) DepartmentUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return uc.repo.DepartmentUserIDs(ctx, id)
|
||||
}
|
||||
func (uc *OrganizationUsecase) SetDepartmentUsers(ctx context.Context, id uint, ids []uint) error {
|
||||
return uc.repo.SetDepartmentUsers(ctx, id, ids)
|
||||
}
|
||||
func (uc *OrganizationUsecase) SetUserDepartments(ctx context.Context, id uint, ids []uint, primary uint) error {
|
||||
return uc.repo.SetUserDepartments(ctx, id, ids, primary)
|
||||
}
|
||||
func (uc *OrganizationUsecase) Positions(ctx context.Context, page, size int, filter *Position) ([]*Position, int64, error) {
|
||||
return uc.repo.ListPositions(ctx, page, size, filter)
|
||||
}
|
||||
func (uc *OrganizationUsecase) CreatePosition(ctx context.Context, value *Position) error {
|
||||
return uc.repo.CreatePosition(ctx, value)
|
||||
}
|
||||
func (uc *OrganizationUsecase) UpdatePosition(ctx context.Context, value *Position) error {
|
||||
return uc.repo.UpdatePosition(ctx, value)
|
||||
}
|
||||
func (uc *OrganizationUsecase) DeletePosition(ctx context.Context, id uint) error {
|
||||
return uc.repo.DeletePosition(ctx, id)
|
||||
}
|
||||
func (uc *OrganizationUsecase) Position(ctx context.Context, id uint) (*Position, error) {
|
||||
return uc.repo.FindPosition(ctx, id)
|
||||
}
|
||||
func (uc *OrganizationUsecase) PositionUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
||||
return uc.repo.PositionUserIDs(ctx, id)
|
||||
}
|
||||
func (uc *OrganizationUsecase) SetPositionUsers(ctx context.Context, id uint, ids []uint) error {
|
||||
return uc.repo.SetPositionUsers(ctx, id, ids)
|
||||
}
|
||||
func (uc *OrganizationUsecase) SetUserPositions(ctx context.Context, id uint, ids []uint) error {
|
||||
return uc.repo.SetUserPositions(ctx, id, ids)
|
||||
}
|
||||
@@ -48,26 +48,6 @@ type Authority struct {
|
||||
DefaultRouter string
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
ID uint
|
||||
ParentID uint
|
||||
Path string
|
||||
Name string
|
||||
Hidden bool
|
||||
Component string
|
||||
Sort int
|
||||
ActiveName string
|
||||
KeepAlive bool
|
||||
DefaultMenu bool
|
||||
Title string
|
||||
Icon string
|
||||
CloseTab bool
|
||||
TransitionType string
|
||||
Children []*Menu
|
||||
Buttons []*MenuButton
|
||||
Parameters []*MenuParameter
|
||||
}
|
||||
|
||||
type SystemRepo interface {
|
||||
IsInitialized(context.Context) (bool, error)
|
||||
Initialize(context.Context, *DatabaseConfig) error
|
||||
|
||||
Reference in New Issue
Block a user