优化结构

This commit is contained in:
Yvan
2026-08-21 08:54:29 +08:00
parent c968f9f24e
commit 77e192b6c0
167 changed files with 3657 additions and 1528 deletions
+12 -13
View File
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type AuthorityService struct{ uc *biz.AuthorityUsecase }
@@ -13,9 +12,9 @@ func NewAuthorityService(uc *biz.AuthorityUsecase) *AuthorityService {
return &AuthorityService{uc: uc}
}
func authorityDTO(value *biz.Authority) *dto.AuthorityResponse {
func authorityDTO(value *biz.Authority) *AuthorityResponse {
out := convertAuthority(*value)
children := make([]*dto.AuthorityResponse, 0, len(value.Children))
children := make([]*AuthorityResponse, 0, len(value.Children))
for _, child := range value.Children {
children = append(children, authorityDTO(child))
}
@@ -23,31 +22,31 @@ func authorityDTO(value *biz.Authority) *dto.AuthorityResponse {
return out
}
func authorityDomain(req *dto.AuthorityRequest) *biz.Authority {
func authorityDomain(req *AuthorityRequest) *biz.Authority {
return &biz.Authority{AuthorityID: req.AuthorityID, AuthorityName: req.AuthorityName, ParentID: req.ParentID, DataScope: req.DataScope, DefaultRouter: req.DefaultRouter}
}
func authorityResponse(value *biz.Authority) *dto.AuthorityResponse {
var menus []*dto.MenuResponse
func authorityResponse(value *biz.Authority) *AuthorityResponse {
var menus []*MenuResponse
if value.Menus != nil {
menus = menuResponses(value.Menus)
}
return &dto.AuthorityResponse{CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: value.DeletedAt, AuthorityID: value.AuthorityID, AuthorityName: value.AuthorityName, ParentID: value.ParentID, Children: nil, Menus: menus, DataScope: value.DataScope, DefaultRouter: value.DefaultRouter}
return &AuthorityResponse{CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: value.DeletedAt, AuthorityID: value.AuthorityID, AuthorityName: value.AuthorityName, ParentID: value.ParentID, Children: nil, Menus: menus, DataScope: value.DataScope, DefaultRouter: value.DefaultRouter}
}
func (s *AuthorityService) Authorities(ctx context.Context) ([]*dto.AuthorityResponse, error) {
func (s *AuthorityService) Authorities(ctx context.Context) ([]*AuthorityResponse, error) {
items, err := s.uc.AuthorityTree(ctx)
if err != nil {
return nil, err
}
roots := make([]*dto.AuthorityResponse, 0, len(items))
roots := make([]*AuthorityResponse, 0, len(items))
for _, value := range items {
roots = append(roots, authorityDTO(value))
}
return roots, nil
}
func (s *AuthorityService) CreateAuthorityRequest(ctx context.Context, req *dto.AuthorityRequest) (*dto.AuthorityResponse, error) {
func (s *AuthorityService) CreateAuthorityRequest(ctx context.Context, req *AuthorityRequest) (*AuthorityResponse, error) {
value := authorityDomain(req)
if err := s.uc.CreateAuthority(ctx, value); err != nil {
return nil, err
@@ -55,17 +54,17 @@ func (s *AuthorityService) CreateAuthorityRequest(ctx context.Context, req *dto.
return authorityResponse(value), nil
}
func (s *AuthorityService) CopyAuthorityRequest(ctx context.Context, req *dto.CopyAuthorityRequest) (*dto.AuthorityResponse, error) {
func (s *AuthorityService) CopyAuthorityRequest(ctx context.Context, req *CopyAuthorityRequest) (*AuthorityResponse, error) {
value := authorityDomain(&req.Authority)
if err := s.uc.CopyAuthority(ctx, req.OldAuthorityID, value); err != nil {
return nil, err
}
result := authorityResponse(value)
result.Children = []*dto.AuthorityResponse{}
result.Children = []*AuthorityResponse{}
return result, nil
}
func (s *AuthorityService) UpdateAuthorityRequest(ctx context.Context, req *dto.AuthorityRequest) (*dto.AuthorityResponse, error) {
func (s *AuthorityService) UpdateAuthorityRequest(ctx context.Context, req *AuthorityRequest) (*AuthorityResponse, error) {
value := authorityDomain(req)
if err := s.uc.UpdateAuthority(ctx, value); err != nil {
return nil, err