优化结构

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
+8 -9
View File
@@ -6,7 +6,6 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type AnnouncementInput struct {
@@ -23,8 +22,8 @@ func NewAnnouncementService(uc *biz.AnnouncementUsecase) *AnnouncementService {
return &AnnouncementService{uc: uc}
}
func announcementDTO(item *biz.Announcement) *dto.AnnouncementResponse {
return &dto.AnnouncementResponse{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, DeletedAt: nil, Title: item.Title, Content: item.Content, UserID: item.UserID, Attachments: json.RawMessage(item.Attachments)}
func announcementDTO(item *biz.Announcement) *AnnouncementResponse {
return &AnnouncementResponse{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, DeletedAt: nil, Title: item.Title, Content: item.Content, UserID: item.UserID, Attachments: json.RawMessage(item.Attachments)}
}
func announcementDO(in AnnouncementInput) *biz.Announcement {
@@ -47,7 +46,7 @@ func (s *AnnouncementService) DeleteByIDs(ctx context.Context, ids []string) err
return s.uc.DeleteByIDs(ctx, ids)
}
func (s *AnnouncementService) Find(ctx context.Context, id string) (*dto.AnnouncementResponse, error) {
func (s *AnnouncementService) Find(ctx context.Context, id string) (*AnnouncementResponse, error) {
item, err := s.uc.Find(ctx, id)
if err != nil {
return nil, err
@@ -55,26 +54,26 @@ func (s *AnnouncementService) Find(ctx context.Context, id string) (*dto.Announc
return announcementDTO(item), nil
}
func (s *AnnouncementService) List(ctx context.Context, page, pageSize int, start, end *time.Time) ([]*dto.AnnouncementResponse, int64, error) {
func (s *AnnouncementService) List(ctx context.Context, page, pageSize int, start, end *time.Time) ([]*AnnouncementResponse, int64, error) {
items, total, err := s.uc.List(ctx, biz.AnnouncementFilter{Page: page, PageSize: pageSize, StartCreatedAt: start, EndCreatedAt: end})
if err != nil {
return nil, 0, err
}
result := make([]*dto.AnnouncementResponse, 0, len(items))
result := make([]*AnnouncementResponse, 0, len(items))
for _, item := range items {
result = append(result, announcementDTO(item))
}
return result, total, nil
}
func (s *AnnouncementService) UserOptions(ctx context.Context) ([]*dto.SelectOptionResponse, error) {
func (s *AnnouncementService) UserOptions(ctx context.Context) ([]*SelectOptionResponse, error) {
items, err := s.uc.UserOptions(ctx)
if err != nil {
return nil, err
}
result := make([]*dto.SelectOptionResponse, 0, len(items))
result := make([]*SelectOptionResponse, 0, len(items))
for _, item := range items {
result = append(result, &dto.SelectOptionResponse{Label: item.Label, Value: item.Value})
result = append(result, &SelectOptionResponse{Label: item.Label, Value: item.Value})
}
return result, nil
}
+19 -20
View File
@@ -5,7 +5,6 @@ import (
"strings"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type APIService struct {
@@ -24,23 +23,23 @@ func (s *APIService) NormalizeRoutePath(path string) string {
return NormalizeRoutePath(path, s.settings.RouterPrefix())
}
func (s *APIService) apiDomain(value *dto.APIRequest) *biz.API {
func (s *APIService) apiDomain(value *APIRequest) *biz.API {
return &biz.API{ID: value.ID, Path: s.NormalizeRoutePath(value.Path), Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
}
func apiResponse(value *biz.API) *dto.APIResponse {
return &dto.APIResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Path: value.Path, Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
func apiResponse(value *biz.API) *APIResponse {
return &APIResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Path: value.Path, Description: value.Description, APIGroup: value.APIGroup, Method: value.Method}
}
func apiResponses(items []*biz.API) []*dto.APIResponse {
out := make([]*dto.APIResponse, 0, len(items))
func apiResponses(items []*biz.API) []*APIResponse {
out := make([]*APIResponse, 0, len(items))
for _, item := range items {
out = append(out, apiResponse(item))
}
return out
}
func (s *APIService) ListAPI(ctx context.Context, req *dto.APIListRequest) ([]*dto.APIResponse, int64, error) {
func (s *APIService) ListAPI(ctx context.Context, req *APIListRequest) ([]*APIResponse, int64, error) {
items, total, err := s.uc.ListAPIs(ctx, req.Page, req.PageSize, &biz.API{Path: req.Path, Description: req.Description, APIGroup: req.APIGroup, Method: req.Method, OrderKey: req.OrderKey, Desc: req.Desc})
if err != nil {
return nil, 0, err
@@ -48,7 +47,7 @@ func (s *APIService) ListAPI(ctx context.Context, req *dto.APIListRequest) ([]*d
return apiResponses(items), total, nil
}
func (s *APIService) AllAPI(ctx context.Context, strict bool) ([]*dto.APIResponse, error) {
func (s *APIService) AllAPI(ctx context.Context, strict bool) ([]*APIResponse, error) {
items, _, err := s.uc.ListAPIs(ctx, 0, 0, &biz.API{StrictAll: strict})
if err != nil {
return nil, err
@@ -80,24 +79,24 @@ func (s *APIService) Groups(ctx context.Context) ([]string, map[string]string, e
return groups, groupAPIMap, nil
}
func (s *APIService) CreateAPIRequest(ctx context.Context, req *dto.APIRequest) (*dto.APIResponse, error) {
func (s *APIService) CreateAPIRequest(ctx context.Context, req *APIRequest) (*APIResponse, error) {
value := s.apiDomain(req)
if err := s.uc.CreateAPI(ctx, value); err != nil {
return nil, err
}
return apiResponse(value), nil
}
func (s *APIService) UpdateAPIRequest(ctx context.Context, req *dto.APIRequest) error {
func (s *APIService) UpdateAPIRequest(ctx context.Context, req *APIRequest) error {
return s.uc.UpdateAPI(ctx, s.apiDomain(req))
}
func (s *APIService) FindAPIResponse(ctx context.Context, id uint) (*dto.APIResponse, error) {
func (s *APIService) FindAPIResponse(ctx context.Context, id uint) (*APIResponse, error) {
value, err := s.uc.FindAPI(ctx, id)
if err != nil {
return nil, err
}
return apiResponse(value), nil
}
func (s *APIService) ApplyAPISyncRequest(ctx context.Context, req *dto.ApplyAPISyncRequest) error {
func (s *APIService) ApplyAPISyncRequest(ctx context.Context, req *ApplyAPISyncRequest) error {
added := make([]*biz.API, 0, len(req.NewAPIs))
deleted := make([]*biz.API, 0, len(req.DeleteAPIs))
for i := range req.NewAPIs {
@@ -108,28 +107,28 @@ func (s *APIService) ApplyAPISyncRequest(ctx context.Context, req *dto.ApplyAPIS
}
return s.uc.ApplyAPISync(ctx, added, deleted)
}
func (s *APIService) SetPolicyPathsRequest(ctx context.Context, req *dto.SetPolicyPathsRequest) error {
func (s *APIService) SetPolicyPathsRequest(ctx context.Context, req *SetPolicyPathsRequest) error {
paths := make([]*biz.API, 0, len(req.Infos))
for _, value := range req.Infos {
paths = append(paths, &biz.API{Path: value.Path, Method: value.Method})
}
return s.uc.SetPolicyPaths(ctx, req.AuthorityID, paths)
}
func (s *APIService) PolicyPathResponses(ctx context.Context, authorityID uint) ([]dto.PolicyPathRequest, error) {
func (s *APIService) PolicyPathResponses(ctx context.Context, authorityID uint) ([]PolicyPathRequest, error) {
items, err := s.uc.PolicyPaths(ctx, authorityID)
if err != nil {
return nil, err
}
var out []dto.PolicyPathRequest
var out []PolicyPathRequest
if len(items) > 0 {
out = make([]dto.PolicyPathRequest, 0, len(items))
out = make([]PolicyPathRequest, 0, len(items))
}
for _, item := range items {
out = append(out, dto.PolicyPathRequest{Path: item.Path, Method: item.Method})
out = append(out, PolicyPathRequest{Path: item.Path, Method: item.Method})
}
return out, nil
}
func (s *APIService) SyncAPIResponses(ctx context.Context, routes []dto.APIRequest) (*dto.APISyncResponse, error) {
func (s *APIService) SyncAPIResponses(ctx context.Context, routes []APIRequest) (*APISyncResponse, error) {
items := make([]*biz.API, 0, len(routes))
for i := range routes {
routes[i].Path = s.NormalizeRoutePath(routes[i].Path)
@@ -156,12 +155,12 @@ func (s *APIService) SetAPIRoles(ctx context.Context, path, method string, ids [
func (s *APIService) FreshCasbin(ctx context.Context) error {
return s.uc.FreshCasbin(ctx)
}
func (s *APIService) SyncAPIs(ctx context.Context, routes []*biz.API) (*dto.APISyncResponse, error) {
func (s *APIService) SyncAPIs(ctx context.Context, routes []*biz.API) (*APISyncResponse, error) {
diff, err := s.uc.SyncAPIs(ctx, routes)
if err != nil {
return nil, err
}
return &dto.APISyncResponse{NewAPIs: apiResponses(diff.Added), DeleteAPIs: apiResponses(diff.Deleted), IgnoreAPIs: apiResponses(diff.Ignored)}, nil
return &APISyncResponse{NewAPIs: apiResponses(diff.Added), DeleteAPIs: apiResponses(diff.Deleted), IgnoreAPIs: apiResponses(diff.Ignored)}, nil
}
func (s *APIService) SetAPIIgnored(ctx context.Context, path, method string, ignored bool) error {
return s.uc.SetAPIIgnored(ctx, s.NormalizeRoutePath(path), method, ignored)
+5 -6
View File
@@ -5,7 +5,6 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type TokenService struct {
@@ -17,12 +16,12 @@ func NewTokenService(uc *biz.TokenUsecase, issuer biz.TokenIssuer) *TokenService
return &TokenService{uc: uc, issuer: issuer}
}
func tokenDTO(v *biz.APIToken) *dto.APITokenResponse {
var user *dto.UserResponse
func tokenDTO(v *biz.APIToken) *APITokenResponse {
var user *UserResponse
if v.User != nil {
user = convertUser(v.User)
}
return &dto.APITokenResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, UserID: v.UserID, AuthorityID: v.AuthorityID, Token: v.Token, Status: v.Status, ExpiresAt: v.ExpiresAt, Remark: v.Remark, User: user}
return &APITokenResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, UserID: v.UserID, AuthorityID: v.AuthorityID, Token: v.Token, Status: v.Status, ExpiresAt: v.ExpiresAt, Remark: v.Remark, User: user}
}
func (s *TokenService) CreateAPIToken(ctx context.Context, userID, authorityID uint, days int, remark string) (string, error) {
@@ -40,12 +39,12 @@ func (s *TokenService) CreateAPIToken(ctx context.Context, userID, authorityID u
}
return issued.Value, nil
}
func (s *TokenService) APITokens(ctx context.Context, page, size int, userID uint, status *bool) ([]*dto.APITokenResponse, int64, error) {
func (s *TokenService) APITokens(ctx context.Context, page, size int, userID uint, status *bool) ([]*APITokenResponse, int64, error) {
items, total, err := s.uc.ListAPITokens(ctx, page, size, userID, status)
if err != nil {
return nil, 0, err
}
out := make([]*dto.APITokenResponse, 0, len(items))
out := make([]*APITokenResponse, 0, len(items))
for _, v := range items {
out = append(out, tokenDTO(v))
}
+20 -21
View File
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type AuditService struct{ uc *biz.AuditUsecase }
@@ -18,31 +17,31 @@ func NewAuditRecorder(uc *biz.AuditRecorderUsecase) *AuditRecorder { return &Aud
func (s *AuditRecorder) RecordOperation(ctx context.Context, v *biz.OperationRecord) error {
return s.uc.RecordOperation(ctx, v)
}
func (s *AuditRecorder) RecordOperationRequest(ctx context.Context, value *dto.OperationRecordRequest) error {
func (s *AuditRecorder) RecordOperationRequest(ctx context.Context, value *OperationRecordRequest) error {
return s.RecordOperation(ctx, &biz.OperationRecord{IP: value.IP, Method: value.Method, Path: value.Path, Status: value.Status, LatencyMS: value.LatencyMS, Agent: value.Agent, ErrorMessage: value.ErrorMessage, Body: value.Body, Response: value.Response, UserID: value.UserID, RequestID: value.RequestID, TraceID: value.TraceID, DeviceID: value.DeviceID})
}
func (s *AuditService) OperationsFilter(ctx context.Context, page, size int, path, method string, status int) ([]*dto.OperationRecordResponse, int64, error) {
func (s *AuditService) OperationsFilter(ctx context.Context, page, size int, path, method string, status int) ([]*OperationRecordResponse, int64, error) {
return s.Operations(ctx, page, size, &biz.OperationRecord{Path: path, Method: method, Status: status})
}
func opDTO(v *biz.OperationRecord) *dto.OperationRecordResponse {
func opDTO(v *biz.OperationRecord) *OperationRecordResponse {
var user any = map[string]any{}
if v.User != nil {
user = convertUser(v.User)
}
return &dto.OperationRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, IP: v.IP, Method: v.Method, Path: v.Path, Status: v.Status, LatencyMS: v.LatencyMS, Agent: v.Agent, ErrorMessage: v.ErrorMessage, Body: v.Body, Response: v.Response, UserID: v.UserID, RequestID: v.RequestID, TraceID: v.TraceID, DeviceID: v.DeviceID, User: user}
return &OperationRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, IP: v.IP, Method: v.Method, Path: v.Path, Status: v.Status, LatencyMS: v.LatencyMS, Agent: v.Agent, ErrorMessage: v.ErrorMessage, Body: v.Body, Response: v.Response, UserID: v.UserID, RequestID: v.RequestID, TraceID: v.TraceID, DeviceID: v.DeviceID, User: user}
}
func (s *AuditService) Operations(ctx context.Context, page, size int, q *biz.OperationRecord) ([]*dto.OperationRecordResponse, int64, error) {
func (s *AuditService) Operations(ctx context.Context, page, size int, q *biz.OperationRecord) ([]*OperationRecordResponse, int64, error) {
items, total, err := s.uc.ListOperations(ctx, page, size, q)
if err != nil {
return nil, 0, err
}
out := make([]*dto.OperationRecordResponse, 0, len(items))
out := make([]*OperationRecordResponse, 0, len(items))
for _, v := range items {
out = append(out, opDTO(v))
}
return out, total, nil
}
func (s *AuditService) Operation(ctx context.Context, id uint) (*dto.OperationRecordResponse, error) {
func (s *AuditService) Operation(ctx context.Context, id uint) (*OperationRecordResponse, error) {
v, err := s.uc.FindOperation(ctx, id)
if err != nil {
return nil, err
@@ -56,31 +55,31 @@ func (s *AuditService) DeleteOperations(ctx context.Context, ids []int) error {
func (s *AuditRecorder) RecordLogin(ctx context.Context, v *biz.LoginLog) error {
return s.uc.RecordLogin(ctx, v)
}
func (s *AuditRecorder) RecordLoginRequest(ctx context.Context, value *dto.LoginLogRequest) error {
func (s *AuditRecorder) RecordLoginRequest(ctx context.Context, value *LoginLogRequest) error {
return s.RecordLogin(ctx, &biz.LoginLog{Username: value.Username, IP: value.IP, Status: value.Status, ErrorMessage: value.ErrorMessage, Agent: value.Agent, UserID: value.UserID})
}
func (s *AuditService) LoginsFilter(ctx context.Context, page, size int, username string, status bool) ([]*dto.LoginLogResponse, int64, error) {
func (s *AuditService) LoginsFilter(ctx context.Context, page, size int, username string, status bool) ([]*LoginLogResponse, int64, error) {
return s.Logins(ctx, page, size, &biz.LoginLog{Username: username, Status: status, FilterByStatus: status})
}
func loginDTO(v *biz.LoginLog) *dto.LoginLogResponse {
func loginDTO(v *biz.LoginLog) *LoginLogResponse {
var user any = map[string]any{}
if v.User != nil {
user = convertUser(v.User)
}
return &dto.LoginLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Username: v.Username, IP: v.IP, Status: v.Status, ErrorMessage: v.ErrorMessage, Agent: v.Agent, UserID: v.UserID, User: user}
return &LoginLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Username: v.Username, IP: v.IP, Status: v.Status, ErrorMessage: v.ErrorMessage, Agent: v.Agent, UserID: v.UserID, User: user}
}
func (s *AuditService) Logins(ctx context.Context, page, size int, q *biz.LoginLog) ([]*dto.LoginLogResponse, int64, error) {
func (s *AuditService) Logins(ctx context.Context, page, size int, q *biz.LoginLog) ([]*LoginLogResponse, int64, error) {
items, total, err := s.uc.ListLogins(ctx, page, size, q)
if err != nil {
return nil, 0, err
}
out := make([]*dto.LoginLogResponse, 0, len(items))
out := make([]*LoginLogResponse, 0, len(items))
for _, v := range items {
out = append(out, loginDTO(v))
}
return out, total, nil
}
func (s *AuditService) Login(ctx context.Context, id uint) (*dto.LoginLogResponse, error) {
func (s *AuditService) Login(ctx context.Context, id uint) (*LoginLogResponse, error) {
v, err := s.uc.FindLogin(ctx, id)
if err != nil {
return nil, err
@@ -94,21 +93,21 @@ func (s *AuditService) DeleteLogins(ctx context.Context, ids []int) error {
func (s *AuditRecorder) RecordDataAccess(ctx context.Context, v *biz.DataAccessLog) error {
return s.uc.RecordDataAccess(ctx, v)
}
func (s *AuditRecorder) RecordDataAccessRequest(ctx context.Context, value *dto.DataAccessRecordRequest) error {
func (s *AuditRecorder) RecordDataAccessRequest(ctx context.Context, value *DataAccessRecordRequest) error {
return s.RecordDataAccess(ctx, &biz.DataAccessLog{EventType: value.EventType, Operation: value.Operation, UserID: value.UserID, AuthorityID: value.AuthorityID, RequestID: value.RequestID, Method: value.Method, Path: value.Path, Detail: value.Detail})
}
func (s *AuditService) DataAccessRequest(ctx context.Context, req *dto.DataAccessListRequest) ([]*dto.DataAccessLogResponse, int64, error) {
func (s *AuditService) DataAccessRequest(ctx context.Context, req *DataAccessListRequest) ([]*DataAccessLogResponse, int64, error) {
return s.DataAccess(ctx, req.Page, req.PageSize, &biz.DataAccessLog{EventType: req.EventType, TargetTable: req.TargetTable})
}
func dataAccessDTO(v *biz.DataAccessLog) *dto.DataAccessLogResponse {
return &dto.DataAccessLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, EventType: v.EventType, TargetTable: v.TargetTable, Operation: v.Operation, UserID: v.UserID, AuthorityID: v.AuthorityID, Scope: v.Scope, RequestID: v.RequestID, Method: v.Method, Path: v.Path, Detail: v.Detail}
func dataAccessDTO(v *biz.DataAccessLog) *DataAccessLogResponse {
return &DataAccessLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, EventType: v.EventType, TargetTable: v.TargetTable, Operation: v.Operation, UserID: v.UserID, AuthorityID: v.AuthorityID, Scope: v.Scope, RequestID: v.RequestID, Method: v.Method, Path: v.Path, Detail: v.Detail}
}
func (s *AuditService) DataAccess(ctx context.Context, page, size int, q *biz.DataAccessLog) ([]*dto.DataAccessLogResponse, int64, error) {
func (s *AuditService) DataAccess(ctx context.Context, page, size int, q *biz.DataAccessLog) ([]*DataAccessLogResponse, int64, error) {
items, total, err := s.uc.ListDataAccess(ctx, page, size, q)
if err != nil {
return nil, 0, err
}
out := make([]*dto.DataAccessLogResponse, 0, len(items))
out := make([]*DataAccessLogResponse, 0, len(items))
for _, v := range items {
out = append(out, dataAccessDTO(v))
}
+11 -12
View File
@@ -5,16 +5,15 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
func errorDTO(v *biz.ErrorRecord) *dto.ErrorRecordResponse {
return &dto.ErrorRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}
func errorDTO(v *biz.ErrorRecord) *ErrorRecordResponse {
return &ErrorRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}
}
func (s *AuditRecorder) CreateError(ctx context.Context, v *biz.ErrorRecord) error {
return s.uc.CreateError(ctx, v)
}
func recordedErrorDomain(value *dto.ErrorRecordRequest) *biz.ErrorRecord {
func recordedErrorDomain(value *ErrorRecordRequest) *biz.ErrorRecord {
form, info := value.Form, value.Info
result := &biz.ErrorRecord{Form: &form, Info: &info, Level: value.Level, RequestID: value.RequestID, TraceID: value.TraceID, Status: value.Status}
if value.Solution != "" {
@@ -23,19 +22,19 @@ func recordedErrorDomain(value *dto.ErrorRecordRequest) *biz.ErrorRecord {
}
return result
}
func mutatedErrorDomain(value *dto.ErrorRecordMutationRequest) *biz.ErrorRecord {
func mutatedErrorDomain(value *ErrorRecordMutationRequest) *biz.ErrorRecord {
return &biz.ErrorRecord{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, Form: value.Form, Info: value.Info, Level: value.Level, RequestID: value.RequestID, TraceID: value.TraceID, Solution: value.Solution, Status: value.Status}
}
func (s *AuditRecorder) CreateErrorRequest(ctx context.Context, req *dto.ErrorRecordRequest) error {
func (s *AuditRecorder) CreateErrorRequest(ctx context.Context, req *ErrorRecordRequest) error {
return s.CreateError(ctx, recordedErrorDomain(req))
}
func (s *AuditRecorder) CreateErrorMutationRequest(ctx context.Context, req *dto.ErrorRecordMutationRequest) error {
func (s *AuditRecorder) CreateErrorMutationRequest(ctx context.Context, req *ErrorRecordMutationRequest) error {
return s.CreateError(ctx, mutatedErrorDomain(req))
}
func (s *AuditService) UpdateErrorRequest(ctx context.Context, req *dto.ErrorRecordMutationRequest) error {
func (s *AuditService) UpdateErrorRequest(ctx context.Context, req *ErrorRecordMutationRequest) error {
return s.UpdateError(ctx, mutatedErrorDomain(req))
}
func (s *AuditService) ErrorsFilter(ctx context.Context, page, size int, form, info string, createdAtRange []time.Time) ([]*dto.ErrorRecordResponse, int64, error) {
func (s *AuditService) ErrorsFilter(ctx context.Context, page, size int, form, info string, createdAtRange []time.Time) ([]*ErrorRecordResponse, int64, error) {
query := &biz.ErrorRecord{CreatedAtRange: createdAtRange}
if form != "" {
query.Form = &form
@@ -51,19 +50,19 @@ func (s *AuditService) UpdateError(ctx context.Context, v *biz.ErrorRecord) erro
func (s *AuditService) DeleteErrors(ctx context.Context, ids []uint) error {
return s.uc.DeleteErrors(ctx, ids)
}
func (s *AuditService) Error(ctx context.Context, id uint) (*dto.ErrorRecordResponse, error) {
func (s *AuditService) Error(ctx context.Context, id uint) (*ErrorRecordResponse, error) {
v, err := s.uc.FindError(ctx, id)
if err != nil {
return nil, err
}
return errorDTO(v), nil
}
func (s *AuditService) Errors(ctx context.Context, page, size int, q *biz.ErrorRecord) ([]*dto.ErrorRecordResponse, int64, error) {
func (s *AuditService) Errors(ctx context.Context, page, size int, q *biz.ErrorRecord) ([]*ErrorRecordResponse, int64, error) {
items, total, err := s.uc.ListErrors(ctx, page, size, q)
if err != nil {
return nil, 0, err
}
out := make([]*dto.ErrorRecordResponse, 0, len(items))
out := make([]*ErrorRecordResponse, 0, len(items))
for _, v := range items {
out = append(out, errorDTO(v))
}
+10 -11
View File
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type LogViewerService struct{ uc *biz.LogViewerUsecase }
@@ -13,32 +12,32 @@ func NewLogViewerService(uc *biz.LogViewerUsecase) *LogViewerService {
return &LogViewerService{uc: uc}
}
func (s *LogViewerService) LogDates(ctx context.Context, month string) (*dto.LogDatesResponse, error) {
func (s *LogViewerService) LogDates(ctx context.Context, month string) (*LogDatesResponse, error) {
items, err := s.uc.LogDates(ctx, month)
if err != nil {
return nil, err
}
out := make([]*dto.LogDateResponse, 0, len(items))
out := make([]*LogDateResponse, 0, len(items))
for _, v := range items {
out = append(out, &dto.LogDateResponse{Date: v.Date, FileCount: v.FileCount})
out = append(out, &LogDateResponse{Date: v.Date, FileCount: v.FileCount})
}
return &dto.LogDatesResponse{Month: month, Dates: out}, nil
return &LogDatesResponse{Month: month, Dates: out}, nil
}
func (s *LogViewerService) LogFiles(ctx context.Context, date string) (*dto.LogFilesResponse, error) {
func (s *LogViewerService) LogFiles(ctx context.Context, date string) (*LogFilesResponse, error) {
items, err := s.uc.LogFiles(ctx, date)
if err != nil {
return nil, err
}
out := make([]*dto.LogFileResponse, 0, len(items))
out := make([]*LogFileResponse, 0, len(items))
for _, v := range items {
out = append(out, &dto.LogFileResponse{Path: v.Path, Name: v.Name, Size: v.Size, ModifiedAt: v.ModifiedAt})
out = append(out, &LogFileResponse{Path: v.Path, Name: v.Name, Size: v.Size, ModifiedAt: v.ModifiedAt})
}
return &dto.LogFilesResponse{Date: date, Files: out}, nil
return &LogFilesResponse{Date: date, Files: out}, nil
}
func (s *LogViewerService) LogContent(ctx context.Context, date, path string, cursor *int64) (*dto.LogContentResponse, error) {
func (s *LogViewerService) LogContent(ctx context.Context, date, path string, cursor *int64) (*LogContentResponse, error) {
v, err := s.uc.LogContent(ctx, date, path, cursor)
if err != nil {
return nil, err
}
return &dto.LogContentResponse{Date: v.Date, Path: v.Path, Content: v.Content, LineCount: v.LineCount, NextCursor: v.NextCursor, HasMore: v.HasMore, LimitedByBytes: v.LimitedByBytes, Size: v.Size, ModifiedAt: v.ModifiedAt}, nil
return &LogContentResponse{Date: v.Date, Path: v.Path, Content: v.Content, LineCount: v.LineCount, NextCursor: v.NextCursor, HasMore: v.HasMore, LimitedByBytes: v.LimitedByBytes, Size: v.Size, ModifiedAt: v.ModifiedAt}, nil
}
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type AuthService struct {
@@ -15,11 +14,11 @@ func NewAuthService(uc *biz.AuthenticationUsecase) *AuthService {
return &AuthService{uc: uc}
}
func loginResult(value *biz.AuthenticationResult) *dto.LoginResponse {
return &dto.LoginResponse{User: convertUser(value.User), Token: value.Token, ExpiresAt: value.ExpiresAt.UnixMilli(), NeedChangePassword: value.NeedChangePassword}
func loginResult(value *biz.AuthenticationResult) *LoginResponse {
return &LoginResponse{User: convertUser(value.User), Token: value.Token, ExpiresAt: value.ExpiresAt.UnixMilli(), NeedChangePassword: value.NeedChangePassword}
}
func (s *AuthService) Login(ctx context.Context, req *dto.LoginRequest, ip, agent string) (*dto.LoginResponse, error) {
func (s *AuthService) Login(ctx context.Context, req *LoginRequest, ip, agent string) (*LoginResponse, error) {
value, err := s.uc.Login(ctx, &biz.LoginAttempt{Username: req.Username, Password: req.Password, CaptchaID: req.CaptchaID, Captcha: req.Captcha, IP: ip, Agent: agent})
if err != nil {
return nil, err
@@ -27,7 +26,7 @@ func (s *AuthService) Login(ctx context.Context, req *dto.LoginRequest, ip, agen
return loginResult(value), nil
}
func (s *AuthService) SwitchAuthority(ctx context.Context, claims *biz.AuthClaims, authorityID uint) (*dto.LoginResponse, error) {
func (s *AuthService) SwitchAuthority(ctx context.Context, claims *biz.AuthClaims, authorityID uint) (*LoginResponse, error) {
value, err := s.uc.SwitchAuthority(ctx, claims, authorityID)
if err != nil {
return nil, err
+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
+12 -13
View File
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type DepartmentService struct{ uc *biz.DepartmentUsecase }
@@ -13,10 +12,10 @@ func NewDepartmentService(uc *biz.DepartmentUsecase) *DepartmentService {
return &DepartmentService{uc: uc}
}
func departmentResponse(value *biz.Department) *dto.DepartmentResponse {
var children []*dto.DepartmentResponse
func departmentResponse(value *biz.Department) *DepartmentResponse {
var children []*DepartmentResponse
if value.Children != nil {
children = make([]*dto.DepartmentResponse, 0, len(value.Children))
children = make([]*DepartmentResponse, 0, len(value.Children))
for _, child := range value.Children {
children = append(children, departmentResponse(child))
}
@@ -25,30 +24,30 @@ func departmentResponse(value *biz.Department) *dto.DepartmentResponse {
if value.Leader != nil {
leader = convertUser(value.Leader)
}
return &dto.DepartmentResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, ParentID: value.ParentID, Ancestors: value.Ancestors, Sort: value.Sort, LeaderID: value.LeaderID, Leader: leader, Status: value.Status, Children: children, NamePath: value.NamePath}
return &DepartmentResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, ParentID: value.ParentID, Ancestors: value.Ancestors, Sort: value.Sort, LeaderID: value.LeaderID, Leader: leader, Status: value.Status, Children: children, NamePath: value.NamePath}
}
func departmentDomain(value *dto.DepartmentRequest) *biz.Department {
func departmentDomain(value *DepartmentRequest) *biz.Department {
return &biz.Department{ID: value.ID, Name: value.Name, ParentID: value.ParentID, Sort: value.Sort, LeaderID: value.LeaderID, Status: value.Status}
}
func (s *DepartmentService) Departments(ctx context.Context, name string) ([]*dto.DepartmentResponse, error) {
func (s *DepartmentService) Departments(ctx context.Context, name string) ([]*DepartmentResponse, error) {
items, err := s.uc.Departments(ctx, name)
if err != nil {
return nil, err
}
out := make([]*dto.DepartmentResponse, 0, len(items))
out := make([]*DepartmentResponse, 0, len(items))
for _, item := range items {
out = append(out, departmentResponse(item))
}
return out, nil
}
func (s *DepartmentService) Create(ctx context.Context, req *dto.DepartmentRequest) error {
func (s *DepartmentService) Create(ctx context.Context, req *DepartmentRequest) error {
return s.uc.CreateDepartment(ctx, departmentDomain(req))
}
func (s *DepartmentService) Update(ctx context.Context, req *dto.DepartmentRequest) error {
func (s *DepartmentService) Update(ctx context.Context, req *DepartmentRequest) error {
return s.uc.UpdateDepartment(ctx, departmentDomain(req))
}
@@ -56,7 +55,7 @@ func (s *DepartmentService) Delete(ctx context.Context, id uint) error {
return s.uc.DeleteDepartment(ctx, id)
}
func (s *DepartmentService) Department(ctx context.Context, id uint) (*dto.DepartmentResponse, error) {
func (s *DepartmentService) Department(ctx context.Context, id uint) (*DepartmentResponse, error) {
value, err := s.uc.Department(ctx, id)
if err != nil {
return nil, err
@@ -68,10 +67,10 @@ func (s *DepartmentService) UserIDs(ctx context.Context, id uint) ([]uint, error
return s.uc.DepartmentUserIDs(ctx, id)
}
func (s *DepartmentService) SetUsers(ctx context.Context, req *dto.SetDepartmentUsersRequest) error {
func (s *DepartmentService) SetUsers(ctx context.Context, req *SetDepartmentUsersRequest) error {
return s.uc.SetDepartmentUsers(ctx, req.DepartmentID, req.UserIDs)
}
func (s *DepartmentService) SetUserDepartments(ctx context.Context, req *dto.SetUserDepartmentsRequest) error {
func (s *DepartmentService) SetUserDepartments(ctx context.Context, req *SetUserDepartmentsRequest) error {
return s.uc.SetUserDepartments(ctx, req.ID, req.DepartmentIDs, req.Primary)
}
+32 -33
View File
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type DictionaryService struct{ uc *biz.DictionaryUsecase }
@@ -13,67 +12,67 @@ func NewDictionaryService(uc *biz.DictionaryUsecase) *DictionaryService {
return &DictionaryService{uc: uc}
}
func dictionaryDomain(value *dto.DictionaryRequest) *biz.Dictionary {
func dictionaryDomain(value *DictionaryRequest) *biz.Dictionary {
return &biz.Dictionary{ID: value.ID, Name: value.Name, Type: value.Type, Status: value.Status, Desc: value.Description, ParentID: value.ParentID}
}
func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) (*dto.DictionaryResponse, error) {
func (s *DictionaryService) CreateDictionaryRequest(ctx context.Context, req *DictionaryRequest) (*DictionaryResponse, error) {
value := dictionaryDomain(req)
if err := s.CreateDictionary(ctx, value); err != nil {
return nil, err
}
return dictionaryDTO(value), nil
}
func (s *DictionaryService) UpdateDictionaryRequest(ctx context.Context, req *dto.DictionaryRequest) error {
func (s *DictionaryService) UpdateDictionaryRequest(ctx context.Context, req *DictionaryRequest) error {
return s.UpdateDictionary(ctx, dictionaryDomain(req))
}
func dictionaryDTO(v *biz.Dictionary) *dto.DictionaryResponse {
var children []*dto.DictionaryResponse
func dictionaryDTO(v *biz.Dictionary) *DictionaryResponse {
var children []*DictionaryResponse
if v.Children != nil {
children = make([]*dto.DictionaryResponse, 0, len(v.Children))
children = make([]*DictionaryResponse, 0, len(v.Children))
for _, x := range v.Children {
children = append(children, dictionaryDTO(x))
}
}
var details []*dto.DictionaryDetailResponse
var details []*DictionaryDetailResponse
if v.Details != nil {
details = make([]*dto.DictionaryDetailResponse, 0, len(v.Details))
details = make([]*DictionaryDetailResponse, 0, len(v.Details))
for _, x := range v.Details {
details = append(details, detailDTO(x))
}
}
return &dto.DictionaryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc, ParentID: v.ParentID, Children: children, SysDictionaryDetails: details}
return &DictionaryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc, ParentID: v.ParentID, Children: children, SysDictionaryDetails: details}
}
func (s *DictionaryService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]*dto.DictionaryResponse, int64, error) {
func (s *DictionaryService) Dictionaries(ctx context.Context, page, size int, name, typ string, details bool) ([]*DictionaryResponse, int64, error) {
items, total, err := s.uc.ListDictionaries(ctx, page, size, name, typ, details)
if err != nil {
return nil, 0, err
}
out := make([]*dto.DictionaryResponse, 0, len(items))
out := make([]*DictionaryResponse, 0, len(items))
for _, v := range items {
out = append(out, dictionaryDTO(v))
}
return out, total, nil
}
func (s *DictionaryService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (*dto.DictionaryResponse, error) {
func (s *DictionaryService) Dictionary(ctx context.Context, id uint, typ string, status *bool, details bool) (*DictionaryResponse, error) {
v, err := s.uc.FindDictionary(ctx, id, typ, status, details)
if err != nil {
return nil, err
}
return dictionaryDTO(v), nil
}
func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (*dto.DictionaryExportResponse, error) {
func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (*DictionaryExportResponse, error) {
v, err := s.uc.ExportDictionary(ctx, id)
if err != nil {
return nil, err
}
var details []*dto.DictionaryDetailExportResponse
var details []*DictionaryDetailExportResponse
for _, detail := range v.Details {
details = append(details, &dto.DictionaryDetailExportResponse{
details = append(details, &DictionaryDetailExportResponse{
Label: detail.Label, Value: detail.Value, Extend: detail.Extend,
Status: detail.Status, Sort: detail.Sort, Level: detail.Level, Path: detail.Path,
})
}
return &dto.DictionaryExportResponse{
return &DictionaryExportResponse{
Name: v.Name, Type: v.Type, Status: v.Status, Desc: v.Desc,
SysDictionaryDetails: details,
}, nil
@@ -88,38 +87,38 @@ func (s *DictionaryService) DeleteDictionary(ctx context.Context, id uint) error
return s.uc.DeleteDictionary(ctx, id)
}
func detailDomain(value *dto.DictionaryDetailRequest) *biz.DictionaryDetail {
func detailDomain(value *DictionaryDetailRequest) *biz.DictionaryDetail {
return &biz.DictionaryDetail{ID: value.ID, Label: value.Label, Value: value.Value, Extend: value.Extend, Status: value.Status, Sort: value.Sort, DictionaryID: value.DictionaryID, ParentID: value.ParentID, Level: value.Level, Path: value.Path}
}
func (s *DictionaryService) CreateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
func (s *DictionaryService) CreateDictionaryDetailRequest(ctx context.Context, req *DictionaryDetailRequest) error {
return s.CreateDictionaryDetail(ctx, detailDomain(req))
}
func (s *DictionaryService) UpdateDictionaryDetailRequest(ctx context.Context, req *dto.DictionaryDetailRequest) error {
func (s *DictionaryService) UpdateDictionaryDetailRequest(ctx context.Context, req *DictionaryDetailRequest) error {
return s.UpdateDictionaryDetail(ctx, detailDomain(req))
}
func detailDTO(v *biz.DictionaryDetail) *dto.DictionaryDetailResponse {
var children []*dto.DictionaryDetailResponse
func detailDTO(v *biz.DictionaryDetail) *DictionaryDetailResponse {
var children []*DictionaryDetailResponse
if v.Children != nil {
children = make([]*dto.DictionaryDetailResponse, 0, len(v.Children))
children = make([]*DictionaryDetailResponse, 0, len(v.Children))
for _, x := range v.Children {
children = append(children, detailDTO(x))
}
}
disabled := v.Status != nil && !*v.Status
return &dto.DictionaryDetailResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Label: v.Label, Value: v.Value, Extend: v.Extend, Status: v.Status, Sort: v.Sort, DictionaryID: v.DictionaryID, ParentID: v.ParentID, Level: v.Level, Path: v.Path, Disabled: disabled, Children: children}
return &DictionaryDetailResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Label: v.Label, Value: v.Value, Extend: v.Extend, Status: v.Status, Sort: v.Sort, DictionaryID: v.DictionaryID, ParentID: v.ParentID, Level: v.Level, Path: v.Path, Disabled: disabled, Children: children}
}
func (s *DictionaryService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]*dto.DictionaryDetailResponse, int64, error) {
func (s *DictionaryService) DictionaryDetails(ctx context.Context, page, size int, filter biz.DictionaryDetailFilter) ([]*DictionaryDetailResponse, int64, error) {
items, total, err := s.uc.ListDictionaryDetails(ctx, page, size, filter)
if err != nil {
return nil, 0, err
}
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
out := make([]*DictionaryDetailResponse, 0, len(items))
for _, v := range items {
out = append(out, detailDTO(v))
}
return out, total, nil
}
func (s *DictionaryService) DictionaryDetailsRequest(ctx context.Context, page, size int, request dto.DictionaryDetailListRequest) ([]*dto.DictionaryDetailResponse, int64, error) {
func (s *DictionaryService) DictionaryDetailsRequest(ctx context.Context, page, size int, request DictionaryDetailListRequest) ([]*DictionaryDetailResponse, int64, error) {
return s.DictionaryDetails(ctx, page, size, biz.DictionaryDetailFilter{
DictionaryID: request.DictionaryID,
Label: request.Label,
@@ -129,21 +128,21 @@ func (s *DictionaryService) DictionaryDetailsRequest(ctx context.Context, page,
Level: request.Level,
})
}
func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (*dto.DictionaryDetailResponse, error) {
func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (*DictionaryDetailResponse, error) {
v, err := s.uc.FindDictionaryDetail(ctx, id)
if err != nil {
return nil, err
}
return detailDTO(v), nil
}
func (s *DictionaryService) DictionaryPath(ctx context.Context, id uint) ([]*dto.DictionaryDetailResponse, error) {
path := make([]*dto.DictionaryDetailResponse, 0)
func (s *DictionaryService) DictionaryPath(ctx context.Context, id uint) ([]*DictionaryDetailResponse, error) {
path := make([]*DictionaryDetailResponse, 0)
for id != 0 {
value, err := s.uc.FindDictionaryDetail(ctx, id)
if err != nil {
return nil, err
}
path = append([]*dto.DictionaryDetailResponse{detailDTO(value)}, path...)
path = append([]*DictionaryDetailResponse{detailDTO(value)}, path...)
if value.ParentID == nil {
break
}
@@ -151,12 +150,12 @@ func (s *DictionaryService) DictionaryPath(ctx context.Context, id uint) ([]*dto
}
return path, nil
}
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]*dto.DictionaryDetailResponse, error) {
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]*DictionaryDetailResponse, error) {
items, err := s.uc.DictionaryDetailTree(ctx, id, typ)
if err != nil {
return nil, err
}
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
out := make([]*DictionaryDetailResponse, 0, len(items))
for _, v := range items {
out = append(out, detailDTO(v))
}
@@ -6,16 +6,15 @@ import (
"errors"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
func (s *DictionaryService) ImportDictionaryJSON(ctx context.Context, raw string) error {
var payload struct {
Name string `json:"name"`
Type string `json:"type"`
Status *bool `json:"status"`
Description string `json:"desc"`
Details []dto.DictionaryDetailRequest `json:"sysDictionaryDetails"`
Name string `json:"name"`
Type string `json:"type"`
Status *bool `json:"status"`
Description string `json:"desc"`
Details []DictionaryDetailRequest `json:"sysDictionaryDetails"`
}
if err := json.Unmarshal([]byte(raw), &payload); err != nil {
return errors.New("JSON 格式错误: " + err.Error())
@@ -26,19 +25,19 @@ func (s *DictionaryService) ImportDictionaryJSON(ctx context.Context, raw string
if payload.Type == "" {
return errors.New("字典类型不能为空")
}
dictionary := dictionaryDomain(&dto.DictionaryRequest{Name: payload.Name, Type: payload.Type, Status: payload.Status, Description: payload.Description})
dictionary := dictionaryDomain(&DictionaryRequest{Name: payload.Name, Type: payload.Type, Status: payload.Status, Description: payload.Description})
details := make([]*biz.DictionaryDetail, 0, len(payload.Details))
for i := range payload.Details {
details = append(details, detailDomain(&payload.Details[i]))
}
return s.uc.ImportDictionary(ctx, dictionary, details)
}
func (s *DictionaryService) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*dto.DictionaryDetailResponse, error) {
func (s *DictionaryService) DictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*DictionaryDetailResponse, error) {
items, err := s.uc.DictionaryDetailsByParent(ctx, dictionaryID, parentID, includeChildren)
if err != nil {
return nil, err
}
out := make([]*dto.DictionaryDetailResponse, 0, len(items))
out := make([]*DictionaryDetailResponse, 0, len(items))
for _, item := range items {
out = append(out, detailDTO(item))
}
@@ -0,0 +1,39 @@
package dto
import (
"encoding/json"
"time"
)
type AnnouncementRequest struct {
ID uint `json:"ID"`
Title string `json:"title"`
Content string `json:"content"`
UserID *int `json:"userID"`
Attachments json.RawMessage `json:"attachments"`
}
type AnnouncementSearchRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
StartCreatedAt *time.Time `form:"startCreatedAt"`
EndCreatedAt *time.Time `form:"endCreatedAt"`
}
type AnnouncementResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
// Keep the soft-delete slot in the transport shape while omitting it from
// JSON responses.
DeletedAt any `json:"-"`
Title string `json:"title"`
Content string `json:"content"`
UserID *int `json:"userID"`
Attachments any `json:"attachments"`
}
type SelectOptionResponse struct {
Label string `json:"label"`
Value uint `json:"value"`
}
+74
View File
@@ -0,0 +1,74 @@
package dto
import "time"
type APIRequest struct {
ID uint `json:"ID"`
Path string `json:"path"`
Description string `json:"description"`
APIGroup string `json:"apiGroup"`
Method string `json:"method"`
}
type APIListRequest struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Path string `json:"path"`
Description string `json:"description"`
APIGroup string `json:"apiGroup"`
Method string `json:"method"`
OrderKey string `json:"orderKey"`
Desc bool `json:"desc"`
}
type APIResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Path string `json:"path"`
Description string `json:"description"`
APIGroup string `json:"apiGroup"`
Method string `json:"method"`
}
type DeleteAPIRequest struct {
ID uint `json:"ID"`
}
type DeleteAPIsRequest struct {
IDs []uint `json:"ids"`
}
type GetAPIRequest struct {
ID uint `json:"id"`
}
type SetAPIRolesRequest struct {
Path string `json:"path"`
Method string `json:"method"`
AuthorityIDs []uint `json:"authorityIds"`
}
type IgnoreAPIRequest struct {
Path string `json:"path"`
Method string `json:"method"`
Flag bool `json:"flag"`
}
type ApplyAPISyncRequest struct {
NewAPIs []APIRequest `json:"newApis"`
DeleteAPIs []APIRequest `json:"deleteApis"`
}
type PolicyPathRequest struct {
Path string `json:"path"`
Method string `json:"method"`
}
type SetPolicyPathsRequest struct {
AuthorityID uint `json:"authorityId"`
Infos []PolicyPathRequest `json:"casbinInfos"`
}
type GetPolicyPathsRequest struct {
AuthorityID uint `json:"authorityId"`
}
type APISyncResponse struct {
NewAPIs []*APIResponse `json:"newApis"`
DeleteAPIs []*APIResponse `json:"deleteApis"`
IgnoreAPIs []*APIResponse `json:"ignoreApis"`
}
+186
View File
@@ -0,0 +1,186 @@
package dto
import "time"
type OperationRecordRequest struct {
IP string
Method string
Path string
Status int
LatencyMS int64
Agent string
ErrorMessage string
Body string
Response string
UserID uint
RequestID string
TraceID string
DeviceID string
}
type DataAccessRecordRequest struct {
EventType string
Operation string
UserID uint
AuthorityID uint
RequestID string
Method string
Path string
Detail string
}
type DataAccessListRequest struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
EventType string `json:"eventType"`
TargetTable string `json:"targetTable"`
}
type OperationRecordSearchRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
Path string `form:"path"`
Method string `form:"method"`
Status int `form:"status"`
}
type LoginLogSearchRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
Username string `form:"username"`
Status bool `form:"status"`
}
type AuditIDQuery struct {
ID uint `form:"ID"`
}
type AuditIDsRequest struct {
IDs []int `json:"ids"`
}
type ErrorRecordRequest struct {
Form string `json:"form"`
Info string `json:"info"`
Level string `json:"level"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`
Solution string `json:"solution"`
Status string `json:"status"`
}
// ErrorRecordMutationRequest mirrors the public error-record model. Pointer
// fields preserve the distinction between an omitted value and an explicitly
// supplied empty string, which is required by the update contract.
type ErrorRecordMutationRequest struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
Form *string `json:"form" binding:"required"`
Info *string `json:"info"`
Level string `json:"level"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`
Solution *string `json:"solution"`
Status string `json:"status"`
}
type OperationRecordResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
IP string `json:"ip"`
Method string `json:"method"`
Path string `json:"path"`
Status int `json:"status"`
LatencyMS int64 `json:"latency_ms"`
Agent string `json:"agent"`
ErrorMessage string `json:"error_message"`
Body string `json:"body"`
Response string `json:"resp"`
UserID uint `json:"user_id"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`
DeviceID string `json:"device_id"`
User any `json:"user"`
}
type LoginLogResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Username string `json:"username"`
IP string `json:"ip"`
Status bool `json:"status"`
ErrorMessage string `json:"errorMessage"`
Agent string `json:"agent"`
UserID uint `json:"userId"`
User any `json:"user"`
}
type DataAccessLogResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
EventType string `json:"eventType"`
TargetTable string `json:"targetTable"`
Operation string `json:"operation"`
UserID uint `json:"userId"`
AuthorityID uint `json:"authorityId"`
Scope int `json:"scope"`
RequestID string `json:"requestId"`
Method string `json:"method"`
Path string `json:"path"`
Detail string `json:"detail"`
}
type ErrorRecordResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Form *string `json:"form"`
Info *string `json:"info"`
Level string `json:"level"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`
Solution *string `json:"solution"`
Status string `json:"status"`
}
type LogDateResponse struct {
Date string `json:"date"`
FileCount int `json:"fileCount"`
}
type LogDatesResponse struct {
Month string `json:"month"`
Dates []*LogDateResponse `json:"dates"`
}
type LogFileResponse struct {
Path string `json:"path"`
Name string `json:"name"`
Size int64 `json:"size"`
ModifiedAt time.Time `json:"modifiedAt"`
}
type LogFilesResponse struct {
Date string `json:"date"`
Files []*LogFileResponse `json:"files"`
}
type LogContentResponse struct {
Date string `json:"date"`
Path string `json:"path"`
Content string `json:"content"`
LineCount int `json:"lineCount"`
NextCursor int64 `json:"nextCursor"`
HasMore bool `json:"hasMore"`
LimitedByBytes bool `json:"limitedByBytes"`
Size int64 `json:"size"`
ModifiedAt time.Time `json:"modifiedAt"`
}
@@ -0,0 +1,38 @@
package dto
import (
"net/http/httptest"
"strings"
"testing"
"github.com/gin-gonic/gin"
)
func bindErrorMutation(t *testing.T, body string) (ErrorRecordMutationRequest, error) {
t.Helper()
context, _ := gin.CreateTestContext(httptest.NewRecorder())
context.Request = httptest.NewRequest("PUT", "/sysError/updateSysError", strings.NewReader(body))
context.Request.Header.Set("Content-Type", "application/json")
var request ErrorRecordMutationRequest
return request, context.ShouldBindJSON(&request)
}
func TestErrorRecordMutationAcceptsExplicitEmptyPointerFields(t *testing.T) {
request, err := bindErrorMutation(t, `{"ID":1,"form":"","info":"","solution":""}`)
if err != nil {
t.Fatal(err)
}
if request.Form == nil || *request.Form != "" || request.Info == nil || *request.Info != "" || request.Solution == nil || *request.Solution != "" {
t.Fatalf("explicit empty values lost: form=%#v info=%#v solution=%#v", request.Form, request.Info, request.Solution)
}
}
func TestErrorRecordMutationRequiresFormButKeepsOtherFieldsOmittable(t *testing.T) {
request, err := bindErrorMutation(t, `{"ID":1}`)
if err == nil {
t.Fatal("missing form unexpectedly accepted")
}
if request.Info != nil || request.Solution != nil {
t.Fatalf("omitted fields = (%#v, %#v), want nil", request.Info, request.Solution)
}
}
@@ -0,0 +1,8 @@
package dto
type LoginResponse struct {
User *UserResponse `json:"user"`
Token string `json:"token"`
ExpiresAt int64 `json:"expiresAt"`
NeedChangePassword bool `json:"needChangePassword"`
}
@@ -0,0 +1,42 @@
package dto
import "time"
type AuthorityRequest struct {
AuthorityID uint `json:"authorityId"`
AuthorityName string `json:"authorityName"`
ParentID *uint `json:"parentId"`
DataScope int `json:"dataScope"`
DefaultRouter string `json:"defaultRouter"`
}
type CopyAuthorityRequest struct {
Authority AuthorityRequest `json:"authority"`
OldAuthorityID uint `json:"oldAuthorityId"`
}
type DeleteAuthorityRequest struct {
AuthorityID uint `json:"authorityId"`
}
type SetRoleUsersRequest struct {
AuthorityID uint `json:"authorityId" form:"authorityId"`
UserIDs []uint `json:"userIds" form:"userIds"`
}
type SetDataScopeRequest struct {
AuthorityID uint `json:"authorityId" form:"authorityId"`
DataScope int `json:"dataScope" form:"dataScope"`
DepartmentIDs []uint `json:"deptIds" form:"deptIds"`
}
type AuthorityResponse struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt *time.Time `json:"DeletedAt"`
AuthorityID uint `json:"authorityId"`
AuthorityName string `json:"authorityName"`
ParentID *uint `json:"parentId"`
Children []*AuthorityResponse `json:"children"`
Menus []*MenuResponse `json:"menus"`
DataScope int `json:"dataScope"`
DefaultRouter string `json:"defaultRouter"`
}
+7
View File
@@ -0,0 +1,7 @@
package dto
type SendEmailRequest struct {
To string `json:"to"`
Subject string `json:"subject"`
Body string `json:"body"`
}
+75
View File
@@ -0,0 +1,75 @@
package dto
import "time"
type ExportConditionRequest struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
TemplateID string `json:"templateID"`
From string `json:"from"`
Column string `json:"column"`
Operator string `json:"operator"`
}
type ExportJoinRequest struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
TemplateID string `json:"templateID"`
Join string `json:"joins"`
Table string `json:"table"`
On string `json:"on"`
}
type ExportTemplateRequest struct {
ID uint `json:"ID"`
DBName string `json:"dbName"`
Name string `json:"name"`
TableName string `json:"tableName"`
TemplateID string `json:"templateID"`
TemplateInfo string `json:"templateInfo"`
SQL string `json:"sql"`
ImportSQL string `json:"importSql"`
Limit *int `json:"limit"`
Order string `json:"order"`
Conditions []ExportConditionRequest `json:"conditions"`
Joins []ExportJoinRequest `json:"joinTemplate"`
}
type ExportConditionResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
TemplateID string `json:"templateID"`
From string `json:"from"`
Column string `json:"column"`
Operator string `json:"operator"`
}
type ExportJoinResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
TemplateID string `json:"templateID"`
Join string `json:"joins"`
Table string `json:"table"`
On string `json:"on"`
}
type ExportTemplateResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
// The compatible embedded gorm.DeletedAt field is json:"-".
DeletedAt any `json:"-"`
DBName string `json:"dbName"`
Name string `json:"name"`
TableName string `json:"tableName"`
TemplateID string `json:"templateID"`
TemplateInfo string `json:"templateInfo"`
SQL string `json:"sql"`
ImportSQL string `json:"importSql"`
Limit *int `json:"limit"`
Order string `json:"order"`
Conditions []ExportConditionResponse `json:"conditions"`
Joins []ExportJoinResponse `json:"joinTemplate"`
}
+102
View File
@@ -0,0 +1,102 @@
package dto
import "time"
type MediaResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
// The compatible model embeds gorm.DeletedAt with json:"-", so this field is omitted.
DeletedAt any `json:"-"`
Name string `json:"name"`
ClassID int `json:"classId"`
URL string `json:"url"`
Tag string `json:"tag"`
Key string `json:"key"`
Size int64 `json:"size"`
Mime string `json:"mime"`
MD5 string `json:"md5"`
UserID uint `json:"userId"`
}
type MediaCategoryResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Name string `json:"name"`
PID uint `json:"pid"`
Children []*MediaCategoryResponse `json:"children"`
}
type StorageObjectResponse struct {
Key string `json:"Key"`
Size int64 `json:"Size"`
LastModified time.Time `json:"LastModified"`
ContentType string `json:"ContentType"`
}
type InitUploadResponse struct {
Instant bool `json:"instant"`
UploadID uint `json:"uploadId"`
UploadedChunks []int `json:"uploadedChunks"`
Media *MediaResponse `json:"media,omitempty"`
}
type MediaListRequest struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Keyword string `json:"keyword"`
ClassID int `json:"classId"`
Tag string `json:"tag"`
UserID uint `json:"userId"`
StartCreatedAt time.Time `json:"startCreatedAt"`
EndCreatedAt time.Time `json:"endCreatedAt"`
OrderKey string `json:"orderKey"`
Desc bool `json:"desc"`
}
type IDRequest struct {
ID uint `json:"ID" form:"id"`
}
type IDsRequest struct {
IDs []uint `json:"ids"`
}
type MediaBatchDeleteRequest struct {
IDs []uint `json:"ids" binding:"required"`
}
type RenameMediaRequest struct {
ID uint `json:"ID"`
Name string `json:"name"`
}
type ImportMediaRequest struct {
Name string `json:"name"`
ClassID int `json:"classId"`
URL string `json:"url"`
Tag string `json:"tag"`
Key string `json:"key"`
Size int64 `json:"size"`
Mime string `json:"mime"`
MD5 string `json:"md5"`
UserID uint `json:"userId"`
}
type StorageListRequest struct {
Prefix string `json:"prefix"`
Cursor string `json:"cursor"`
Limit int `json:"limit"`
}
type CategoryRequest struct {
ID uint `json:"ID"`
Name string `json:"name"`
PID uint `json:"pid"`
}
type InitUploadRequest struct {
FileName string `json:"fileName" binding:"required"`
FileHash string `json:"fileHash" binding:"required"`
FileSize int64 `json:"fileSize" binding:"required"`
ChunkSize int64 `json:"chunkSize" binding:"required"`
ChunkTotal int `json:"chunkTotal" binding:"required"`
Mime string `json:"mime"`
}
type CompleteUploadRequest struct {
UploadID uint `json:"uploadId" binding:"required"`
}
+143
View File
@@ -0,0 +1,143 @@
package dto
import "time"
type MenuMetaRequest struct {
ActiveName string `json:"activeName"`
KeepAlive bool `json:"keepAlive"`
DefaultMenu bool `json:"defaultMenu"`
Title string `json:"title"`
Icon string `json:"icon"`
CloseTab bool `json:"closeTab"`
TransitionType string `json:"transitionType"`
}
type MenuButtonRequest struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
ID uint `json:"ID"`
Name string `json:"name"`
Description string `json:"desc"`
SysBaseMenuID uint `json:"sysBaseMenuID"`
}
type MenuParameterRequest struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
ID uint `json:"ID"`
SysBaseMenuID uint `json:"SysBaseMenuID"`
Type string `json:"type"`
Key string `json:"key"`
Value string `json:"value"`
}
type MenuRequest struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
ID uint `json:"ID"`
ParentID uint `json:"parentId"`
Path string `json:"path"`
Name string `json:"name"`
Hidden bool `json:"hidden"`
Component string `json:"component"`
Sort int `json:"sort"`
Meta MenuMetaRequest `json:"meta"`
MenuButtons []MenuButtonRequest `json:"menuBtn"`
Parameters []MenuParameterRequest `json:"parameters"`
}
type DeleteMenuRequest struct {
ID int `json:"id"`
}
type GetMenuRequest struct {
ID int `json:"id"`
}
type SetAuthorityMenusRequest struct {
AuthorityID uint `json:"authorityId"`
Menus []MenuRequest `json:"menus"`
}
type GetAuthorityMenusRequest struct {
AuthorityID uint `json:"authorityId"`
}
type SetMenuRolesRequest struct {
MenuID uint `json:"menuId" form:"menuId"`
AuthorityIDs []uint `json:"authorityIds"`
}
type MenuMetaResponse struct {
ActiveName string `json:"activeName"`
KeepAlive bool `json:"keepAlive"`
DefaultMenu bool `json:"defaultMenu"`
Title string `json:"title"`
Icon string `json:"icon"`
CloseTab bool `json:"closeTab"`
TransitionType string `json:"transitionType"`
}
type MenuButtonResponse struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
ID uint `json:"ID"`
Name string `json:"name"`
Description string `json:"desc"`
SysBaseMenuID uint `json:"sysBaseMenuID"`
}
type MenuParameterResponse struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
ID uint `json:"ID"`
SysBaseMenuID uint `json:"SysBaseMenuID"`
Type string `json:"type"`
Key string `json:"key"`
Value string `json:"value"`
}
type MenuResponse struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
ID uint `json:"ID"`
MenuID uint `json:"menuId,omitempty"`
ParentID uint `json:"parentId"`
Path string `json:"path"`
Name string `json:"name"`
Hidden bool `json:"hidden"`
Component string `json:"component"`
Sort int `json:"sort"`
Meta MenuMetaResponse `json:"meta"`
Children []*MenuResponse `json:"children"`
Parameters []MenuParameterResponse `json:"parameters"`
MenuButtons []MenuButtonResponse `json:"menuBtn"`
Authorities []*AuthorityResponse `json:"authoritys"`
}
type DynamicMenuResponse struct {
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
ID uint `json:"ID"`
MenuID uint `json:"menuId"`
ParentID uint `json:"parentId"`
Path string `json:"path"`
Name string `json:"name"`
Hidden bool `json:"hidden"`
Component string `json:"component"`
Sort int `json:"sort"`
Meta MenuMetaResponse `json:"meta"`
Children []*DynamicMenuResponse `json:"children"`
Parameters []MenuParameterResponse `json:"parameters"`
MenuButtons []MenuButtonResponse `json:"menuBtn"`
Buttons map[string]uint `json:"btns"`
Authorities []*AuthorityResponse `json:"authoritys"`
}
type AuthorityMenuResponse struct {
// The administration response embeds the base-menu fields, so menu fields are
// flat in the response (there is no sysBaseMenu envelope). Keep the
// authority ID internal, matching the compatible json:"-" field.
*DynamicMenuResponse
AuthorityID uint `json:"-"`
}
@@ -0,0 +1,84 @@
package dto
import "time"
type DepartmentRequest struct {
ID uint `json:"ID"`
Name string `json:"name"`
ParentID uint `json:"parentId"`
Sort int `json:"sort"`
LeaderID uint `json:"leaderId"`
Status *bool `json:"status"`
}
type DepartmentListRequest struct {
Name string `json:"name"`
}
type DeleteDepartmentRequest struct {
ID uint `json:"ID" form:"id"`
}
type SetDepartmentUsersRequest struct {
DepartmentID uint `json:"deptId" form:"deptId"`
UserIDs []uint `json:"userIds"`
}
type SetUserDepartmentsRequest struct {
ID uint `json:"ID"`
DepartmentIDs []uint `json:"deptIds"`
Primary uint `json:"primaryDeptId"`
}
type DepartmentResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Name string `json:"name"`
ParentID uint `json:"parentId"`
Ancestors string `json:"ancestors"`
Sort int `json:"sort"`
LeaderID uint `json:"leaderId"`
Leader any `json:"leader"`
Status *bool `json:"status"`
Children []*DepartmentResponse `json:"children"`
NamePath string `json:"namePath"`
}
type PositionRequest struct {
ID uint `json:"ID"`
Name string `json:"name"`
Code string `json:"code"`
Sort int `json:"sort"`
Status *bool `json:"status"`
Remark string `json:"remark"`
}
type PositionListRequest struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Name string `json:"name"`
Code string `json:"code"`
Status *bool `json:"status"`
}
type DeletePositionRequest struct {
ID uint `json:"ID" form:"id"`
}
type SetPositionUsersRequest struct {
PositionID uint `json:"positionId" form:"positionId"`
UserIDs []uint `json:"userIds"`
}
type SetUserPositionsRequest struct {
ID uint `json:"ID"`
PositionIDs []uint `json:"positionIds"`
}
type PositionResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Name string `json:"name"`
Code string `json:"code"`
Sort int `json:"sort"`
Status *bool `json:"status"`
Remark string `json:"remark"`
}
+137
View File
@@ -0,0 +1,137 @@
package dto
import (
"encoding/json"
"time"
)
type PaymentConfigRequest struct {
Provider string `json:"provider"`
Enabled bool `json:"enabled"`
Config json.RawMessage `json:"config"`
}
// PaymentConfigResponse is the transport representation returned by the
// payment configuration endpoint. Values are already masked by the usecase's
// repository boundary.
type PaymentConfigResponse struct {
Provider string `json:"provider"`
Enabled bool `json:"enabled"`
Config json.RawMessage `json:"config"`
}
type PaymentOrderListRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
Provider string `form:"provider"`
TradeNo string `form:"tradeNo"`
BusinessType string `form:"businessType"`
BusinessID string `form:"businessId"`
PaymentStatus string `form:"paymentStatus"`
RefundStatus string `form:"refundStatus"`
}
type PaymentRequest struct {
Provider string `json:"provider"`
TradeNo string `json:"tradeNo"`
Subject string `json:"subject"`
Amount int64 `json:"amount"`
OriginalAmount int64 `json:"originalAmount"`
Currency string `json:"currency"`
NotifyURL string `json:"notifyUrl"`
ReturnURL string `json:"returnUrl"`
Extra map[string]any `json:"extra"`
ClientIP string `json:"-"`
BusinessType string `json:"businessType"`
BusinessID string `json:"businessId"`
PaymentMode string `json:"paymentMode"`
}
type PaymentQueryRequest struct {
Provider string `json:"provider"`
TradeNo string `json:"tradeNo"`
}
type PaymentRefundRequest struct {
Provider string `json:"provider"`
TradeNo string `json:"tradeNo"`
Amount int64 `json:"amount"`
}
type PaymentFulfillRequest struct {
Provider string `json:"provider"`
TradeNo string `json:"tradeNo"`
}
// PaymentCallbackRequest is populated by the HTTP transport and converted to
// the biz callback object inside service.
type PaymentCallbackRequest struct {
Provider string
Headers map[string]string
Body []byte
Query map[string]string
}
type PaymentCallbackAck struct {
StatusCode int
ContentType string
Body []byte
}
type PaymentResultResponse struct {
Provider string `json:"provider"`
Status string `json:"status"`
TradeNo string `json:"tradeNo"`
ProviderTradeNo string `json:"providerTradeNo"`
Amount int64 `json:"amount"`
PayerPaidAmount int64 `json:"payerPaidAmount,omitempty"`
CashPaidAmount int64 `json:"cashPaidAmount,omitempty"`
PointPaidAmount int64 `json:"pointPaidAmount,omitempty"`
DiscountAmount int64 `json:"discountAmount,omitempty"`
ProviderDiscountAmount int64 `json:"providerDiscountAmount,omitempty"`
MerchantDiscountAmount int64 `json:"merchantDiscountAmount,omitempty"`
SettlementAmount int64 `json:"settlementAmount,omitempty"`
Currency string `json:"currency"`
PayerCurrency string `json:"payerCurrency,omitempty"`
AmountBreakdownKnown bool `json:"amountBreakdownKnown"`
Duplicate bool `json:"duplicate"`
Payload json.RawMessage `json:"payload"`
OrderStatus string `json:"orderStatus,omitempty"`
FulfillmentStatus string `json:"fulfillmentStatus,omitempty"`
RefundStatus string `json:"refundStatus,omitempty"`
}
type PaymentOrderResponse struct {
ID uint64 `json:"ID"`
Provider string `json:"provider"`
TradeNo string `json:"tradeNo"`
ProviderTradeNo string `json:"providerTradeNo"`
BusinessType string `json:"businessType"`
BusinessID string `json:"businessId"`
Subject string `json:"subject"`
PaymentMode string `json:"paymentMode"`
OriginalAmount int64 `json:"originalAmount"`
Amount int64 `json:"amount"`
PaidAmount int64 `json:"paidAmount"`
PayerPaidAmount int64 `json:"payerPaidAmount"`
CashPaidAmount int64 `json:"cashPaidAmount"`
PointPaidAmount int64 `json:"pointPaidAmount"`
DiscountAmount int64 `json:"discountAmount"`
ProviderDiscountAmount int64 `json:"providerDiscountAmount"`
MerchantDiscountAmount int64 `json:"merchantDiscountAmount"`
SettlementAmount int64 `json:"settlementAmount"`
Currency string `json:"currency"`
PayerCurrency string `json:"payerCurrency,omitempty"`
AmountBreakdownKnown bool `json:"amountBreakdownKnown"`
PaymentStatus string `json:"paymentStatus"`
ProviderStatus string `json:"providerStatus"`
FulfillmentStatus string `json:"fulfillmentStatus"`
RefundStatus string `json:"refundStatus"`
RefundedAmount int64 `json:"refundedAmount"`
RefundRequestedAmount int64 `json:"refundRequestedAmount"`
RefundNo string `json:"refundNo,omitempty"`
LastError string `json:"lastError,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
PaidAt *time.Time `json:"paidAt,omitempty"`
FulfilledAt *time.Time `json:"fulfilledAt,omitempty"`
RefundedAt *time.Time `json:"refundedAt,omitempty"`
}
@@ -0,0 +1,13 @@
package dto
type GetAuthorityButtonsRequest struct {
MenuID uint `json:"menuID"`
AuthorityID uint `json:"authorityId"`
Selected []uint `json:"selected"`
}
type SetAuthorityButtonsRequest struct {
MenuID uint `json:"menuID"`
AuthorityID uint `json:"authorityId"`
Selected []uint `json:"selected"`
}
+172
View File
@@ -0,0 +1,172 @@
package dto
import "time"
type DictionaryRequest struct {
ID uint `json:"ID" form:"ID"`
Name string `json:"name" form:"name"`
Type string `json:"type" form:"type"`
Status *bool `json:"status" form:"status"`
Description string `json:"desc" form:"desc"`
ParentID *uint `json:"parentID" form:"parentID"`
}
type DictionaryDetailRequest struct {
ID uint `json:"ID" form:"ID"`
Label string `json:"label" form:"label"`
Value string `json:"value" form:"value"`
Extend string `json:"extend" form:"extend"`
Status *bool `json:"status" form:"status"`
Sort int `json:"sort" form:"sort"`
DictionaryID uint `json:"sysDictionaryID" form:"sysDictionaryID"`
ParentID *uint `json:"parentID" form:"parentID"`
Level int `json:"level"`
Path string `json:"path"`
}
type ImportDictionaryRequest struct {
JSON string `json:"json"`
}
type DictionaryDetailsByParentRequest struct {
DictionaryID uint `json:"sysDictionaryID" form:"sysDictionaryID" binding:"required"`
ParentID *uint `json:"parentID" form:"parentID"`
IncludeChildren bool `json:"includeChildren" form:"includeChildren"`
}
type DictionaryDetailListRequest struct {
DictionaryID uint
Label string
Value string
Status *bool
ParentID *uint
Level *int
}
type SystemParameterRequest struct {
ID uint `json:"ID" form:"ID"`
CreatedAt time.Time `json:"CreatedAt" form:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt" form:"UpdatedAt"`
Name string `json:"name" form:"name" binding:"required"`
Key string `json:"key" form:"key" binding:"required"`
Value string `json:"value" form:"value" binding:"required"`
Description string `json:"desc" form:"desc"`
}
type SystemParameterSearchRequest struct {
Page int `json:"page" form:"page"`
PageSize int `json:"pageSize" form:"pageSize"`
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
Name string `json:"name" form:"name"`
Key string `json:"key" form:"key"`
}
type CreateAPITokenRequest struct {
UserID uint `json:"userId"`
AuthorityID uint `json:"authorityId"`
Days int `json:"days"`
Remark string `json:"remark"`
}
type APITokenListRequest struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
UserID uint `json:"userId"`
Status *bool `json:"status"`
}
type APITokenResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
UserID uint `json:"userId"`
AuthorityID uint `json:"authorityId"`
Token string `json:"token"`
Status bool `json:"status"`
ExpiresAt time.Time `json:"expiresAt"`
Remark string `json:"remark"`
User *UserResponse `json:"user"`
}
type SecurityConfigResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
CaptchaOpen int `json:"captchaOpen"`
CaptchaTimeout int `json:"captchaTimeout"`
KeyLong int `json:"keyLong"`
ImgWidth int `json:"imgWidth"`
ImgHeight int `json:"imgHeight"`
PwdMinLength int `json:"pwdMinLength"`
PwdRequireUpper bool `json:"pwdRequireUpper"`
PwdRequireLower bool `json:"pwdRequireLower"`
PwdRequireDigit bool `json:"pwdRequireDigit"`
PwdRequireSpecial bool `json:"pwdRequireSpecial"`
LimitEnable bool `json:"limitEnable"`
LimitWindow int `json:"limitWindow"`
LimitCount int `json:"limitCount"`
LockEnable bool `json:"lockEnable"`
LockThreshold int `json:"lockThreshold"`
LockDuration int `json:"lockDuration"`
PwdExpireEnable bool `json:"pwdExpireEnable"`
PwdExpireDays int `json:"pwdExpireDays"`
ForceNewUserChangePassword bool `json:"forceNewUserChangePassword"`
}
type SystemParameterResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Name string `json:"name"`
Key string `json:"key"`
Value string `json:"value"`
Desc string `json:"desc"`
}
type DictionaryResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Name string `json:"name"`
Type string `json:"type"`
Status *bool `json:"status"`
Desc string `json:"desc"`
ParentID *uint `json:"parentID"`
Children []*DictionaryResponse `json:"children"`
SysDictionaryDetails []*DictionaryDetailResponse `json:"sysDictionaryDetails"`
}
type DictionaryDetailResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Label string `json:"label"`
Value string `json:"value"`
Extend string `json:"extend"`
Status *bool `json:"status"`
Sort int `json:"sort"`
DictionaryID uint `json:"sysDictionaryID"`
ParentID *uint `json:"parentID"`
Level int `json:"level"`
Path string `json:"path"`
Disabled bool `json:"disabled"`
Children []*DictionaryDetailResponse `json:"children"`
}
type DictionaryExportResponse struct {
Name string `json:"name"`
Type string `json:"type"`
Status *bool `json:"status"`
Desc string `json:"desc"`
SysDictionaryDetails []*DictionaryDetailExportResponse `json:"sysDictionaryDetails"`
}
type DictionaryDetailExportResponse struct {
Label string `json:"label"`
Value string `json:"value"`
Extend string `json:"extend"`
Status *bool `json:"status"`
Sort int `json:"sort"`
Level int `json:"level"`
Path string `json:"path"`
}
+133
View File
@@ -0,0 +1,133 @@
package dto
import "time"
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Captcha string `json:"captcha"`
CaptchaID string `json:"captchaId"`
}
type Route struct {
Path string
Method string
}
type UserListRequest struct {
Page int `json:"page"`
PageSize int `json:"pageSize"`
Username string `json:"username"`
NickName string `json:"nickName"`
Phone string `json:"phone"`
Email string `json:"email"`
OrderKey string `json:"orderKey"`
Desc bool `json:"desc"`
}
type UserRequest struct {
ID uint `json:"ID" form:"id"`
Username string `json:"userName"`
Password string `json:"passWord"`
NickName string `json:"nickName"`
HeaderImg string `json:"headerImg"`
AuthorityID uint `json:"authorityId"`
AuthorityIDs []uint `json:"authorityIds"`
Enable int `json:"enable"`
Phone string `json:"phone"`
Email string `json:"email"`
}
type SelfUserRequest struct {
NickName string `json:"nickName"`
HeaderImg string `json:"headerImg"`
Phone string `json:"phone"`
Email string `json:"email"`
Enable int `json:"enable"`
}
type ResetPasswordRequest struct {
ID uint `json:"ID"`
Password string `json:"password"`
}
type ChangePasswordRequest struct {
Password string `json:"password"`
NewPassword string `json:"newPassword"`
}
type UserAuthoritiesRequest struct {
ID uint `json:"ID"`
AuthorityIDs []uint `json:"authorityIds"`
}
type SwitchAuthorityRequest struct {
AuthorityID uint `json:"authorityId"`
}
type LoginLogRequest struct {
Username string
IP string
Status bool
ErrorMessage string
Agent string
UserID uint
}
type UserResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
UUID string `json:"uuid"`
Username string `json:"userName"`
NickName string `json:"nickName"`
HeaderImg string `json:"headerImg"`
AuthorityID uint `json:"authorityId"`
Authority *AuthorityResponse `json:"authority"`
Authorities []*AuthorityResponse `json:"authorities"`
DeptID uint `json:"deptId"`
Department any `json:"dept"`
Departments []*DepartmentResponse `json:"departments"`
Positions []*PositionResponse `json:"positions"`
Phone string `json:"phone"`
Email string `json:"email"`
Enable int `json:"enable"`
OriginSetting map[string]any `json:"originSetting"`
PasswordUpdatedAt *time.Time `json:"passwordUpdatedAt"`
}
type ServerInfoResponse struct {
OS ServerOSResponse `json:"os"`
CPU ServerCPUResponse `json:"cpu"`
RAM ServerRAMResponse `json:"ram"`
Disk []ServerDiskResponse `json:"disk"`
}
type ServerOSResponse struct {
GOOS string `json:"goos"`
NumCPU int `json:"numCpu"`
Compiler string `json:"compiler"`
GoVersion string `json:"goVersion"`
NumGoroutine int `json:"numGoroutine"`
}
type ServerCPUResponse struct {
CPUs []float64 `json:"cpus"`
Cores int `json:"cores"`
}
type ServerRAMResponse struct {
UsedMB uint64 `json:"usedMb"`
TotalMB uint64 `json:"totalMb"`
UsedPercent int `json:"usedPercent"`
}
type ServerDiskResponse struct {
MountPoint string `json:"mountPoint"`
UsedMB uint64 `json:"usedMb"`
UsedGB uint64 `json:"usedGb"`
TotalMB uint64 `json:"totalMb"`
TotalGB uint64 `json:"totalGb"`
UsedPercent int `json:"usedPercent"`
}
@@ -0,0 +1,30 @@
package dto
import "encoding/json"
type SecurityConfigRequest struct {
ID uint `json:"ID"`
CaptchaOpen int `json:"captchaOpen"`
CaptchaTimeout int `json:"captchaTimeout"`
KeyLong int `json:"keyLong"`
ImgWidth int `json:"imgWidth"`
ImgHeight int `json:"imgHeight"`
PwdMinLength int `json:"pwdMinLength"`
PwdRequireUpper bool `json:"pwdRequireUpper"`
PwdRequireLower bool `json:"pwdRequireLower"`
PwdRequireDigit bool `json:"pwdRequireDigit"`
PwdRequireSpecial bool `json:"pwdRequireSpecial"`
LimitEnable bool `json:"limitEnable"`
LimitWindow int `json:"limitWindow"`
LimitCount int `json:"limitCount"`
LockEnable bool `json:"lockEnable"`
LockThreshold int `json:"lockThreshold"`
LockDuration int `json:"lockDuration"`
PwdExpireEnable bool `json:"pwdExpireEnable"`
PwdExpireDays int `json:"pwdExpireDays"`
ForceNewUserChangePassword bool `json:"forceNewUserChangePassword"`
}
type SetSystemConfigRequest struct {
Config json.RawMessage `json:"config"`
}
@@ -0,0 +1,13 @@
package dto
type DatabaseInitRequest struct {
DBType string `json:"dbType"`
Host string `json:"host"`
Port string `json:"port"`
UserName string `json:"userName"`
Password string `json:"password"`
DBName string `json:"dbName" binding:"required"`
DBPath string `json:"dbPath"`
Template string `json:"template"`
AdminPassword string `json:"adminPassword" binding:"required"`
}
+88
View File
@@ -0,0 +1,88 @@
package dto
import (
"encoding/json"
"time"
)
type TaskRequest struct {
ID uint `json:"ID"`
Name string `json:"name"`
Description string `json:"description"`
Spec string `json:"spec"`
WithSeconds bool `json:"withSeconds"`
ExecutorType string `json:"executorType"`
MethodName string `json:"methodName"`
Params json.RawMessage `json:"params"`
HTTPURL string `json:"httpUrl"`
HTTPMethod string `json:"httpMethod"`
HTTPHeader json.RawMessage `json:"httpHeader"`
HTTPBody string `json:"httpBody"`
HTTPAllowPrivate bool `json:"httpAllowPrivate"`
Enabled bool `json:"enabled"`
}
type DeleteTaskRequest struct {
ID uint `json:"ID" binding:"required"`
}
type ToggleTaskRequest struct {
ID uint `json:"ID" binding:"required"`
Enabled bool `json:"enabled"`
}
type TaskListRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
Name string `form:"name"`
ExecutorType string `form:"executorType"`
Enabled *bool `form:"enabled"`
}
type TaskLogListRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
TaskID uint `form:"taskId"`
Status string `form:"status"`
}
type TaskResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
Name string `json:"name"`
Description string `json:"description"`
Spec string `json:"spec"`
WithSeconds bool `json:"withSeconds"`
ExecutorType string `json:"executorType"`
MethodName string `json:"methodName"`
Params json.RawMessage `json:"params"`
HTTPURL string `json:"httpUrl"`
HTTPMethod string `json:"httpMethod"`
HTTPHeader json.RawMessage `json:"httpHeader"`
HTTPBody string `json:"httpBody"`
HTTPAllowPrivate bool `json:"httpAllowPrivate"`
Enabled bool `json:"enabled"`
NextRunAt *time.Time `json:"nextRunAt"`
}
type TaskLogResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
TaskID uint `json:"taskId"`
TaskName string `json:"taskName"`
TriggerType string `json:"triggerType"`
StartedAt time.Time `json:"startedAt"`
FinishedAt time.Time `json:"finishedAt"`
DurationMS int64 `json:"durationMs"`
Status string `json:"status"`
ErrorMsg string `json:"errorMsg"`
Output string `json:"output"`
}
type TaskMethodResponse struct {
Name string `json:"name"`
Description string `json:"description"`
}
@@ -0,0 +1,94 @@
package dto
import "time"
type VersionResponse struct {
ID uint `json:"ID"`
CreatedAt time.Time `json:"CreatedAt"`
UpdatedAt time.Time `json:"UpdatedAt"`
DeletedAt any `json:"-"`
VersionName *string `json:"versionName"`
VersionCode *string `json:"versionCode"`
Description *string `json:"description"`
VersionData *string `json:"versionData"`
}
type VersionSearchRequest struct {
CreatedAtRange []time.Time `json:"createdAtRange" form:"createdAtRange[]"`
VersionName *string `json:"versionName" form:"versionName"`
VersionCode *string `json:"versionCode" form:"versionCode"`
Page int `json:"page" form:"page"`
PageSize int `json:"pageSize" form:"pageSize"`
}
type VersionMenuMetaRequest struct {
ActiveName string `json:"activeName"`
KeepAlive bool `json:"keepAlive"`
DefaultMenu bool `json:"defaultMenu"`
Title string `json:"title"`
Icon string `json:"icon"`
CloseTab bool `json:"closeTab"`
TransitionType string `json:"transitionType"`
}
type VersionMenuButtonRequest struct {
Name string `json:"name"`
Description string `json:"desc"`
}
type VersionMenuParameterRequest struct {
Type string `json:"type"`
Key string `json:"key"`
Value string `json:"value"`
}
type VersionMenuRequest struct {
Path string `json:"path"`
Name string `json:"name"`
Hidden bool `json:"hidden"`
Component string `json:"component"`
Sort int `json:"sort"`
Meta VersionMenuMetaRequest `json:"meta"`
MenuButtons []VersionMenuButtonRequest `json:"menuBtn"`
Parameters []VersionMenuParameterRequest `json:"parameters"`
Children []VersionMenuRequest `json:"children"`
}
type VersionAPIRequest struct {
Path string `json:"path"`
Description string `json:"description"`
APIGroup string `json:"apiGroup"`
Method string `json:"method"`
}
type VersionDictionaryDetailRequest struct {
Label string `json:"label"`
Value string `json:"value"`
Extend string `json:"extend"`
Status *bool `json:"status"`
Sort int `json:"sort"`
ParentID *uint `json:"parentID"`
Level int `json:"level"`
Path string `json:"path"`
}
type VersionDictionaryRequest struct {
Name string `json:"name"`
Type string `json:"type"`
Status *bool `json:"status"`
Description string `json:"desc"`
Details []VersionDictionaryDetailRequest `json:"sysDictionaryDetails"`
}
type ImportVersionRequest struct {
Version struct {
Name string `json:"name" binding:"required"`
Code string `json:"code" binding:"required"`
Description string `json:"description"`
ExportTime string `json:"exportTime"`
} `json:"version" binding:"required"`
Menus []VersionMenuRequest `json:"menus"`
APIs []VersionAPIRequest `json:"apis"`
Dictionaries []VersionDictionaryRequest `json:"dictionaries"`
}
type ExportVersionRequest struct {
VersionName string `json:"versionName" binding:"required"`
VersionCode string `json:"versionCode" binding:"required"`
Description string `json:"description"`
MenuIDs []uint `json:"menuIds"`
APIIDs []uint `json:"apiIds"`
DictIDs []uint `json:"dictIds"`
}
+162
View File
@@ -0,0 +1,162 @@
package service
// DTO aliases keep the service API stable while request/response contracts live in service/dto.
import "kra/app/system/internal/service/dto"
type AnnouncementRequest = dto.AnnouncementRequest
type AnnouncementResponse = dto.AnnouncementResponse
type AnnouncementSearchRequest = dto.AnnouncementSearchRequest
type APIListRequest = dto.APIListRequest
type APIRequest = dto.APIRequest
type APIResponse = dto.APIResponse
type APISyncResponse = dto.APISyncResponse
type APITokenListRequest = dto.APITokenListRequest
type APITokenResponse = dto.APITokenResponse
type ApplyAPISyncRequest = dto.ApplyAPISyncRequest
type AuditIDQuery = dto.AuditIDQuery
type AuditIDsRequest = dto.AuditIDsRequest
type AuthorityMenuResponse = dto.AuthorityMenuResponse
type AuthorityRequest = dto.AuthorityRequest
type AuthorityResponse = dto.AuthorityResponse
type CategoryRequest = dto.CategoryRequest
type ChangePasswordRequest = dto.ChangePasswordRequest
type CompleteUploadRequest = dto.CompleteUploadRequest
type CopyAuthorityRequest = dto.CopyAuthorityRequest
type CreateAPITokenRequest = dto.CreateAPITokenRequest
type DataAccessListRequest = dto.DataAccessListRequest
type DataAccessLogResponse = dto.DataAccessLogResponse
type DataAccessRecordRequest = dto.DataAccessRecordRequest
type DatabaseInitRequest = dto.DatabaseInitRequest
type DeleteAPIRequest = dto.DeleteAPIRequest
type DeleteAPIsRequest = dto.DeleteAPIsRequest
type DeleteAuthorityRequest = dto.DeleteAuthorityRequest
type DeleteDepartmentRequest = dto.DeleteDepartmentRequest
type DeleteMenuRequest = dto.DeleteMenuRequest
type DeletePositionRequest = dto.DeletePositionRequest
type DeleteTaskRequest = dto.DeleteTaskRequest
type DepartmentListRequest = dto.DepartmentListRequest
type DepartmentRequest = dto.DepartmentRequest
type DepartmentResponse = dto.DepartmentResponse
type DictionaryDetailExportResponse = dto.DictionaryDetailExportResponse
type DictionaryDetailListRequest = dto.DictionaryDetailListRequest
type DictionaryDetailRequest = dto.DictionaryDetailRequest
type DictionaryDetailResponse = dto.DictionaryDetailResponse
type DictionaryDetailsByParentRequest = dto.DictionaryDetailsByParentRequest
type DictionaryExportResponse = dto.DictionaryExportResponse
type DictionaryRequest = dto.DictionaryRequest
type DictionaryResponse = dto.DictionaryResponse
type DynamicMenuResponse = dto.DynamicMenuResponse
type ErrorRecordMutationRequest = dto.ErrorRecordMutationRequest
type ErrorRecordRequest = dto.ErrorRecordRequest
type ErrorRecordResponse = dto.ErrorRecordResponse
type ExportConditionRequest = dto.ExportConditionRequest
type ExportConditionResponse = dto.ExportConditionResponse
type ExportJoinRequest = dto.ExportJoinRequest
type ExportJoinResponse = dto.ExportJoinResponse
type ExportTemplateRequest = dto.ExportTemplateRequest
type ExportTemplateResponse = dto.ExportTemplateResponse
type ExportVersionRequest = dto.ExportVersionRequest
type GetAPIRequest = dto.GetAPIRequest
type GetAuthorityButtonsRequest = dto.GetAuthorityButtonsRequest
type GetAuthorityMenusRequest = dto.GetAuthorityMenusRequest
type GetMenuRequest = dto.GetMenuRequest
type GetPolicyPathsRequest = dto.GetPolicyPathsRequest
type IDRequest = dto.IDRequest
type IDsRequest = dto.IDsRequest
type IgnoreAPIRequest = dto.IgnoreAPIRequest
type ImportDictionaryRequest = dto.ImportDictionaryRequest
type ImportMediaRequest = dto.ImportMediaRequest
type ImportVersionRequest = dto.ImportVersionRequest
type InitUploadRequest = dto.InitUploadRequest
type InitUploadResponse = dto.InitUploadResponse
type LogContentResponse = dto.LogContentResponse
type LogDateResponse = dto.LogDateResponse
type LogDatesResponse = dto.LogDatesResponse
type LogFileResponse = dto.LogFileResponse
type LogFilesResponse = dto.LogFilesResponse
type LoginLogRequest = dto.LoginLogRequest
type LoginLogResponse = dto.LoginLogResponse
type LoginLogSearchRequest = dto.LoginLogSearchRequest
type LoginRequest = dto.LoginRequest
type LoginResponse = dto.LoginResponse
type MediaBatchDeleteRequest = dto.MediaBatchDeleteRequest
type MediaCategoryResponse = dto.MediaCategoryResponse
type MediaListRequest = dto.MediaListRequest
type MediaResponse = dto.MediaResponse
type MenuButtonRequest = dto.MenuButtonRequest
type MenuButtonResponse = dto.MenuButtonResponse
type MenuMetaRequest = dto.MenuMetaRequest
type MenuMetaResponse = dto.MenuMetaResponse
type MenuParameterRequest = dto.MenuParameterRequest
type MenuParameterResponse = dto.MenuParameterResponse
type MenuRequest = dto.MenuRequest
type MenuResponse = dto.MenuResponse
type OperationRecordRequest = dto.OperationRecordRequest
type OperationRecordResponse = dto.OperationRecordResponse
type OperationRecordSearchRequest = dto.OperationRecordSearchRequest
type PaymentCallbackAck = dto.PaymentCallbackAck
type PaymentCallbackRequest = dto.PaymentCallbackRequest
type PaymentConfigRequest = dto.PaymentConfigRequest
type PaymentConfigResponse = dto.PaymentConfigResponse
type PaymentFulfillRequest = dto.PaymentFulfillRequest
type PaymentOrderListRequest = dto.PaymentOrderListRequest
type PaymentOrderResponse = dto.PaymentOrderResponse
type PaymentQueryRequest = dto.PaymentQueryRequest
type PaymentRefundRequest = dto.PaymentRefundRequest
type PaymentRequest = dto.PaymentRequest
type PaymentResultResponse = dto.PaymentResultResponse
type PolicyPathRequest = dto.PolicyPathRequest
type PositionListRequest = dto.PositionListRequest
type PositionRequest = dto.PositionRequest
type PositionResponse = dto.PositionResponse
type RenameMediaRequest = dto.RenameMediaRequest
type ResetPasswordRequest = dto.ResetPasswordRequest
type Route = dto.Route
type SecurityConfigRequest = dto.SecurityConfigRequest
type SecurityConfigResponse = dto.SecurityConfigResponse
type SelectOptionResponse = dto.SelectOptionResponse
type SelfUserRequest = dto.SelfUserRequest
type SendEmailRequest = dto.SendEmailRequest
type ServerCPUResponse = dto.ServerCPUResponse
type ServerDiskResponse = dto.ServerDiskResponse
type ServerInfoResponse = dto.ServerInfoResponse
type ServerOSResponse = dto.ServerOSResponse
type ServerRAMResponse = dto.ServerRAMResponse
type SetAPIRolesRequest = dto.SetAPIRolesRequest
type SetAuthorityButtonsRequest = dto.SetAuthorityButtonsRequest
type SetAuthorityMenusRequest = dto.SetAuthorityMenusRequest
type SetDataScopeRequest = dto.SetDataScopeRequest
type SetDepartmentUsersRequest = dto.SetDepartmentUsersRequest
type SetMenuRolesRequest = dto.SetMenuRolesRequest
type SetPolicyPathsRequest = dto.SetPolicyPathsRequest
type SetPositionUsersRequest = dto.SetPositionUsersRequest
type SetRoleUsersRequest = dto.SetRoleUsersRequest
type SetSystemConfigRequest = dto.SetSystemConfigRequest
type SetUserDepartmentsRequest = dto.SetUserDepartmentsRequest
type SetUserPositionsRequest = dto.SetUserPositionsRequest
type StorageListRequest = dto.StorageListRequest
type StorageObjectResponse = dto.StorageObjectResponse
type SwitchAuthorityRequest = dto.SwitchAuthorityRequest
type SystemParameterRequest = dto.SystemParameterRequest
type SystemParameterResponse = dto.SystemParameterResponse
type SystemParameterSearchRequest = dto.SystemParameterSearchRequest
type TaskListRequest = dto.TaskListRequest
type TaskLogListRequest = dto.TaskLogListRequest
type TaskLogResponse = dto.TaskLogResponse
type TaskMethodResponse = dto.TaskMethodResponse
type TaskRequest = dto.TaskRequest
type TaskResponse = dto.TaskResponse
type ToggleTaskRequest = dto.ToggleTaskRequest
type UserAuthoritiesRequest = dto.UserAuthoritiesRequest
type UserListRequest = dto.UserListRequest
type UserRequest = dto.UserRequest
type UserResponse = dto.UserResponse
type VersionAPIRequest = dto.VersionAPIRequest
type VersionDictionaryDetailRequest = dto.VersionDictionaryDetailRequest
type VersionDictionaryRequest = dto.VersionDictionaryRequest
type VersionMenuButtonRequest = dto.VersionMenuButtonRequest
type VersionMenuMetaRequest = dto.VersionMenuMetaRequest
type VersionMenuParameterRequest = dto.VersionMenuParameterRequest
type VersionMenuRequest = dto.VersionMenuRequest
type VersionResponse = dto.VersionResponse
type VersionSearchRequest = dto.VersionSearchRequest
+15 -16
View File
@@ -8,7 +8,6 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
"github.com/google/uuid"
)
@@ -67,7 +66,7 @@ func (s *ExportService) ConsumeToken(ctx context.Context, token string, expectBl
_ = s.cache.Delete(ctx, "export:"+token)
return &ExportToken{TemplateID: value.TemplateID, Params: value.Params, Blank: value.Blank}, nil
}
func exportTemplateDomain(value *dto.ExportTemplateRequest) *biz.ExportTemplate {
func exportTemplateDomain(value *ExportTemplateRequest) *biz.ExportTemplate {
out := &biz.ExportTemplate{ID: value.ID, DBName: value.DBName, Name: value.Name, TableName: value.TableName, TemplateID: value.TemplateID, TemplateInfo: value.TemplateInfo, SQL: value.SQL, ImportSQL: value.ImportSQL, Limit: value.Limit, Order: value.Order}
for _, item := range value.Conditions {
out.Conditions = append(out.Conditions, biz.ExportCondition{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, TemplateID: item.TemplateID, From: item.From, Column: item.Column, Operator: item.Operator})
@@ -77,31 +76,31 @@ func exportTemplateDomain(value *dto.ExportTemplateRequest) *biz.ExportTemplate
}
return out
}
func (s *ExportService) CreateRequest(ctx context.Context, req *dto.ExportTemplateRequest) error {
func (s *ExportService) CreateRequest(ctx context.Context, req *ExportTemplateRequest) error {
return s.Create(ctx, exportTemplateDomain(req))
}
func (s *ExportService) UpdateRequest(ctx context.Context, req *dto.ExportTemplateRequest) error {
func (s *ExportService) UpdateRequest(ctx context.Context, req *ExportTemplateRequest) error {
return s.Update(ctx, exportTemplateDomain(req))
}
func (s *ExportService) TemplatesFilter(ctx context.Context, page, size int, name, tableName, templateID string, start, end *time.Time) ([]*dto.ExportTemplateResponse, int64, error) {
func (s *ExportService) TemplatesFilter(ctx context.Context, page, size int, name, tableName, templateID string, start, end *time.Time) ([]*ExportTemplateResponse, int64, error) {
return s.Templates(ctx, page, size, &biz.ExportTemplate{Name: name, TableName: tableName, TemplateID: templateID, StartCreatedAt: start, EndCreatedAt: end})
}
func exportDTO(v *biz.ExportTemplate) *dto.ExportTemplateResponse {
var conditions []dto.ExportConditionResponse
func exportDTO(v *biz.ExportTemplate) *ExportTemplateResponse {
var conditions []ExportConditionResponse
if v.Conditions != nil {
conditions = make([]dto.ExportConditionResponse, 0, len(v.Conditions))
conditions = make([]ExportConditionResponse, 0, len(v.Conditions))
for _, x := range v.Conditions {
conditions = append(conditions, dto.ExportConditionResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, From: x.From, Column: x.Column, Operator: x.Operator})
conditions = append(conditions, ExportConditionResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, From: x.From, Column: x.Column, Operator: x.Operator})
}
}
var joins []dto.ExportJoinResponse
var joins []ExportJoinResponse
if v.Joins != nil {
joins = make([]dto.ExportJoinResponse, 0, len(v.Joins))
joins = make([]ExportJoinResponse, 0, len(v.Joins))
for _, x := range v.Joins {
joins = append(joins, dto.ExportJoinResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, Join: x.Join, Table: x.Table, On: x.On})
joins = append(joins, ExportJoinResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, Join: x.Join, Table: x.Table, On: x.On})
}
}
return &dto.ExportTemplateResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, DBName: v.DBName, Name: v.Name, TableName: v.TableName, TemplateID: v.TemplateID, TemplateInfo: v.TemplateInfo, SQL: v.SQL, ImportSQL: v.ImportSQL, Limit: v.Limit, Order: v.Order, Conditions: conditions, Joins: joins}
return &ExportTemplateResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, DBName: v.DBName, Name: v.Name, TableName: v.TableName, TemplateID: v.TemplateID, TemplateInfo: v.TemplateInfo, SQL: v.SQL, ImportSQL: v.ImportSQL, Limit: v.Limit, Order: v.Order, Conditions: conditions, Joins: joins}
}
func (s *ExportService) Create(ctx context.Context, v *biz.ExportTemplate) error {
return s.uc.CreateExportTemplate(ctx, v)
@@ -112,19 +111,19 @@ func (s *ExportService) Update(ctx context.Context, v *biz.ExportTemplate) error
func (s *ExportService) Delete(ctx context.Context, ids []uint) error {
return s.uc.DeleteExportTemplates(ctx, ids)
}
func (s *ExportService) Template(ctx context.Context, id uint, tid string) (*dto.ExportTemplateResponse, error) {
func (s *ExportService) Template(ctx context.Context, id uint, tid string) (*ExportTemplateResponse, error) {
v, err := s.uc.FindExportTemplate(ctx, id, tid)
if err != nil {
return nil, err
}
return exportDTO(v), nil
}
func (s *ExportService) Templates(ctx context.Context, page, size int, q *biz.ExportTemplate) ([]*dto.ExportTemplateResponse, int64, error) {
func (s *ExportService) Templates(ctx context.Context, page, size int, q *biz.ExportTemplate) ([]*ExportTemplateResponse, int64, error) {
items, total, err := s.uc.ListExportTemplates(ctx, page, size, q)
if err != nil {
return nil, 0, err
}
out := make([]*dto.ExportTemplateResponse, 0, len(items))
out := make([]*ExportTemplateResponse, 0, len(items))
for _, v := range items {
out = append(out, exportDTO(v))
}
+18 -19
View File
@@ -5,7 +5,6 @@ import (
"io"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type MediaService struct {
@@ -19,45 +18,45 @@ func NewMediaService(uc *biz.MediaUsecase, settings biz.RuntimeSettings) *MediaS
func (s *MediaService) MediaConfig() biz.MediaSettings {
return s.settings.MediaSettings()
}
func mediaDTO(v *biz.MediaFile) *dto.MediaResponse {
return &dto.MediaResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, ClassID: v.CategoryID, URL: v.URL, Tag: v.Tag, Key: v.Key, Size: v.Size, Mime: v.Mime, MD5: v.MD5, UserID: v.UserID}
func mediaDTO(v *biz.MediaFile) *MediaResponse {
return &MediaResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, ClassID: v.CategoryID, URL: v.URL, Tag: v.Tag, Key: v.Key, Size: v.Size, Mime: v.Mime, MD5: v.MD5, UserID: v.UserID}
}
func categoryDTO(v *biz.AttachmentCategory) *dto.MediaCategoryResponse {
var children []*dto.MediaCategoryResponse
func categoryDTO(v *biz.AttachmentCategory) *MediaCategoryResponse {
var children []*MediaCategoryResponse
if v.Children != nil {
children = make([]*dto.MediaCategoryResponse, 0, len(v.Children))
children = make([]*MediaCategoryResponse, 0, len(v.Children))
for _, x := range v.Children {
children = append(children, categoryDTO(x))
}
}
return &dto.MediaCategoryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, PID: v.ParentID, Children: children}
return &MediaCategoryResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, PID: v.ParentID, Children: children}
}
func (s *MediaService) Upload(ctx context.Context, userID uint, name, mime string, categoryID int, reader io.Reader, save bool) (*dto.MediaResponse, error) {
func (s *MediaService) Upload(ctx context.Context, userID uint, name, mime string, categoryID int, reader io.Reader, save bool) (*MediaResponse, error) {
v, err := s.uc.Upload(ctx, userID, name, mime, categoryID, reader, save)
if err != nil {
return nil, err
}
return mediaDTO(v), nil
}
func (s *MediaService) Media(ctx context.Context, id uint) (*dto.MediaResponse, error) {
func (s *MediaService) Media(ctx context.Context, id uint) (*MediaResponse, error) {
v, err := s.uc.FindMedia(ctx, id)
if err != nil {
return nil, err
}
return mediaDTO(v), nil
}
func (s *MediaService) MediaList(ctx context.Context, filter biz.MediaFilter) ([]*dto.MediaResponse, int64, error) {
func (s *MediaService) MediaList(ctx context.Context, filter biz.MediaFilter) ([]*MediaResponse, int64, error) {
items, total, err := s.uc.ListMedia(ctx, filter)
if err != nil {
return nil, 0, err
}
out := make([]*dto.MediaResponse, 0, len(items))
out := make([]*MediaResponse, 0, len(items))
for _, v := range items {
out = append(out, mediaDTO(v))
}
return out, total, nil
}
func (s *MediaService) MediaListRequest(ctx context.Context, request *dto.MediaListRequest) ([]*dto.MediaResponse, int64, error) {
func (s *MediaService) MediaListRequest(ctx context.Context, request *MediaListRequest) ([]*MediaResponse, int64, error) {
return s.MediaList(ctx, biz.MediaFilter{
Page: request.Page, PageSize: request.PageSize, Keyword: request.Keyword,
CategoryID: request.ClassID, Tag: request.Tag, UserID: request.UserID,
@@ -72,30 +71,30 @@ func (s *MediaService) Rename(ctx context.Context, id uint, name string) error {
func (s *MediaService) ImportURLs(ctx context.Context, items []*biz.MediaFile) error {
return s.uc.CreateMediaBatch(ctx, items)
}
func (s *MediaService) ImportURLRequests(ctx context.Context, values []dto.ImportMediaRequest) error {
func (s *MediaService) ImportURLRequests(ctx context.Context, values []ImportMediaRequest) error {
items := make([]*biz.MediaFile, 0, len(values))
for _, value := range values {
items = append(items, &biz.MediaFile{Name: value.Name, CategoryID: value.ClassID, URL: value.URL, Tag: value.Tag, Key: value.Key, Size: value.Size, Mime: value.Mime, MD5: value.MD5, UserID: value.UserID})
}
return s.ImportURLs(ctx, items)
}
func (s *MediaService) Storage(ctx context.Context, prefix, cursor string, limit int) ([]*dto.StorageObjectResponse, string, bool, error) {
func (s *MediaService) Storage(ctx context.Context, prefix, cursor string, limit int) ([]*StorageObjectResponse, string, bool, error) {
items, next, more, err := s.uc.ListStorage(ctx, prefix, cursor, limit)
if err != nil {
return nil, "", false, err
}
out := make([]*dto.StorageObjectResponse, 0, len(items))
out := make([]*StorageObjectResponse, 0, len(items))
for _, v := range items {
out = append(out, &dto.StorageObjectResponse{Key: v.Path, Size: v.Size, LastModified: v.LastModified, ContentType: v.ContentType})
out = append(out, &StorageObjectResponse{Key: v.Path, Size: v.Size, LastModified: v.LastModified, ContentType: v.ContentType})
}
return out, next, more, nil
}
func (s *MediaService) Categories(ctx context.Context) ([]*dto.MediaCategoryResponse, error) {
func (s *MediaService) Categories(ctx context.Context) ([]*MediaCategoryResponse, error) {
items, err := s.uc.ListCategories(ctx)
if err != nil {
return nil, err
}
out := make([]*dto.MediaCategoryResponse, 0, len(items))
out := make([]*MediaCategoryResponse, 0, len(items))
for _, v := range items {
out = append(out, categoryDTO(v))
}
@@ -104,7 +103,7 @@ func (s *MediaService) Categories(ctx context.Context) ([]*dto.MediaCategoryResp
func (s *MediaService) SaveCategory(ctx context.Context, v *biz.AttachmentCategory) error {
return s.uc.SaveCategory(ctx, v)
}
func (s *MediaService) SaveCategoryRequest(ctx context.Context, value *dto.CategoryRequest) error {
func (s *MediaService) SaveCategoryRequest(ctx context.Context, value *CategoryRequest) error {
return s.SaveCategory(ctx, &biz.AttachmentCategory{ID: value.ID, Name: value.Name, ParentID: value.PID})
}
func (s *MediaService) DeleteCategory(ctx context.Context, id uint) error {
+4 -6
View File
@@ -3,11 +3,9 @@ package service
import (
"context"
"io"
"kra/app/system/internal/dto"
)
func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash string, size, chunkSize int64, total int) (*dto.InitUploadResponse, error) {
func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash string, size, chunkSize int64, total int) (*InitUploadResponse, error) {
session, media, chunks, err := s.uc.InitUpload(ctx, userID, name, hash, size, chunkSize, total)
if err != nil {
return nil, err
@@ -15,14 +13,14 @@ func (s *MediaService) InitUpload(ctx context.Context, userID uint, name, hash s
if media != nil {
// The compatible response leaves UploadedChunks nil on an instant-upload hit, producing
// JSON null while still returning uploadId: 0.
return &dto.InitUploadResponse{Instant: true, Media: mediaDTO(media)}, nil
return &InitUploadResponse{Instant: true, Media: mediaDTO(media)}, nil
}
return &dto.InitUploadResponse{Instant: false, UploadID: session.ID, UploadedChunks: chunks, Media: nil}, nil
return &InitUploadResponse{Instant: false, UploadID: session.ID, UploadedChunks: chunks, Media: nil}, nil
}
func (s *MediaService) SaveChunk(ctx context.Context, userID, uploadID uint, index int, hash string, reader io.Reader) error {
return s.uc.SaveChunk(ctx, userID, uploadID, index, hash, reader)
}
func (s *MediaService) CompleteUpload(ctx context.Context, userID, uploadID uint) (*dto.MediaResponse, error) {
func (s *MediaService) CompleteUpload(ctx context.Context, userID, uploadID uint) (*MediaResponse, error) {
v, err := s.uc.CompleteUpload(ctx, userID, uploadID, "")
if err != nil {
return nil, err
+32 -33
View File
@@ -4,14 +4,13 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type MenuService struct{ uc *biz.MenuUsecase }
func NewMenuService(uc *biz.MenuUsecase) *MenuService { return &MenuService{uc: uc} }
func (s *MenuService) List(ctx context.Context) ([]*dto.MenuResponse, error) {
func (s *MenuService) List(ctx context.Context) ([]*MenuResponse, error) {
items, err := s.uc.List(ctx)
if err != nil {
return nil, err
@@ -19,7 +18,7 @@ func (s *MenuService) List(ctx context.Context) ([]*dto.MenuResponse, error) {
return menuResponses(items), nil
}
func (s *MenuService) Tree(ctx context.Context) ([]*dto.MenuResponse, error) {
func (s *MenuService) Tree(ctx context.Context) ([]*MenuResponse, error) {
items, err := s.uc.Tree(ctx)
if err != nil {
return nil, err
@@ -27,15 +26,15 @@ func (s *MenuService) Tree(ctx context.Context) ([]*dto.MenuResponse, error) {
return menuResponses(items), nil
}
func (s *MenuService) Create(ctx context.Context, req *dto.MenuRequest) error {
func (s *MenuService) Create(ctx context.Context, req *MenuRequest) error {
return s.uc.Create(ctx, menuDomain(req))
}
func (s *MenuService) Update(ctx context.Context, req *dto.MenuRequest) error {
func (s *MenuService) Update(ctx context.Context, req *MenuRequest) error {
return s.uc.Update(ctx, menuDomain(req))
}
func (s *MenuService) Delete(ctx context.Context, id uint) error { return s.uc.Delete(ctx, id) }
func (s *MenuService) Find(ctx context.Context, id uint) (*dto.MenuResponse, error) {
func (s *MenuService) Find(ctx context.Context, id uint) (*MenuResponse, error) {
item, err := s.uc.Find(ctx, id)
if err != nil {
return nil, err
@@ -43,7 +42,7 @@ func (s *MenuService) Find(ctx context.Context, id uint) (*dto.MenuResponse, err
return menuResponse(item), nil
}
func (s *MenuService) SetAuthorityMenus(ctx context.Context, req *dto.SetAuthorityMenusRequest) error {
func (s *MenuService) SetAuthorityMenus(ctx context.Context, req *SetAuthorityMenusRequest) error {
ids := make([]uint, 0, len(req.Menus))
for _, menu := range req.Menus {
ids = append(ids, menu.ID)
@@ -51,15 +50,15 @@ func (s *MenuService) SetAuthorityMenus(ctx context.Context, req *dto.SetAuthori
return s.uc.SetAuthorityMenus(ctx, req.AuthorityID, ids)
}
func (s *MenuService) AuthorityMenus(ctx context.Context, authorityID uint) ([]*dto.AuthorityMenuResponse, error) {
func (s *MenuService) AuthorityMenus(ctx context.Context, authorityID uint) ([]*AuthorityMenuResponse, error) {
items, err := s.uc.AuthorityMenus(ctx, authorityID)
if err != nil {
return nil, err
}
var out []*dto.AuthorityMenuResponse
var out []*AuthorityMenuResponse
for _, item := range items {
item.MenuID = item.ID
out = append(out, &dto.AuthorityMenuResponse{DynamicMenuResponse: dynamicMenuResponse(item), AuthorityID: authorityID})
out = append(out, &AuthorityMenuResponse{DynamicMenuResponse: dynamicMenuResponse(item), AuthorityID: authorityID})
}
return out, nil
}
@@ -70,11 +69,11 @@ func (s *MenuService) RoleIDs(ctx context.Context, menuID uint) ([]uint, error)
func (s *MenuService) DefaultRouterRoleIDs(ctx context.Context, menuID uint) ([]uint, error) {
return s.uc.DefaultRouterRoleIDs(ctx, menuID)
}
func (s *MenuService) SetRoles(ctx context.Context, req *dto.SetMenuRolesRequest) error {
func (s *MenuService) SetRoles(ctx context.Context, req *SetMenuRolesRequest) error {
return s.uc.SetRoles(ctx, req.MenuID, req.AuthorityIDs)
}
func menuDomain(v *dto.MenuRequest) *biz.Menu {
func menuDomain(v *MenuRequest) *biz.Menu {
menu := &biz.Menu{CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, ID: v.ID, ParentID: v.ParentID, Path: v.Path, Name: v.Name, Hidden: v.Hidden, Component: v.Component, Sort: v.Sort, ActiveName: v.Meta.ActiveName, KeepAlive: v.Meta.KeepAlive, DefaultMenu: v.Meta.DefaultMenu, Title: v.Meta.Title, Icon: v.Meta.Icon, CloseTab: v.Meta.CloseTab, TransitionType: v.Meta.TransitionType}
menu.Buttons = make([]*biz.MenuButton, 0, len(v.MenuButtons))
for _, button := range v.MenuButtons {
@@ -87,44 +86,44 @@ func menuDomain(v *dto.MenuRequest) *biz.Menu {
return menu
}
func menuResponse(menu *biz.Menu) *dto.MenuResponse {
var children []*dto.MenuResponse
func menuResponse(menu *biz.Menu) *MenuResponse {
var children []*MenuResponse
if menu.Children != nil {
children = make([]*dto.MenuResponse, 0, len(menu.Children))
children = make([]*MenuResponse, 0, len(menu.Children))
for _, child := range menu.Children {
children = append(children, menuResponse(child))
}
}
var buttons []dto.MenuButtonResponse
var buttons []MenuButtonResponse
if menu.Buttons != nil {
buttons = make([]dto.MenuButtonResponse, 0, len(menu.Buttons))
buttons = make([]MenuButtonResponse, 0, len(menu.Buttons))
for _, button := range menu.Buttons {
buttons = append(buttons, dto.MenuButtonResponse{CreatedAt: button.CreatedAt, UpdatedAt: button.UpdatedAt, ID: button.ID, Name: button.Name, Description: button.Description, SysBaseMenuID: button.MenuID})
buttons = append(buttons, MenuButtonResponse{CreatedAt: button.CreatedAt, UpdatedAt: button.UpdatedAt, ID: button.ID, Name: button.Name, Description: button.Description, SysBaseMenuID: button.MenuID})
}
}
var parameters []dto.MenuParameterResponse
var parameters []MenuParameterResponse
if menu.Parameters != nil {
parameters = make([]dto.MenuParameterResponse, 0, len(menu.Parameters))
parameters = make([]MenuParameterResponse, 0, len(menu.Parameters))
for _, parameter := range menu.Parameters {
parameters = append(parameters, dto.MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
parameters = append(parameters, MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
}
}
return &dto.MenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: dto.MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: buttons}
return &MenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: buttons}
}
func dynamicMenuResponse(menu *biz.Menu) *dto.DynamicMenuResponse {
var children []*dto.DynamicMenuResponse
func dynamicMenuResponse(menu *biz.Menu) *DynamicMenuResponse {
var children []*DynamicMenuResponse
if menu.Children != nil {
children = make([]*dto.DynamicMenuResponse, 0, len(menu.Children))
children = make([]*DynamicMenuResponse, 0, len(menu.Children))
for _, child := range menu.Children {
children = append(children, dynamicMenuResponse(child))
}
}
var parameters []dto.MenuParameterResponse
var parameters []MenuParameterResponse
if menu.Parameters != nil {
parameters = make([]dto.MenuParameterResponse, 0, len(menu.Parameters))
parameters = make([]MenuParameterResponse, 0, len(menu.Parameters))
for _, parameter := range menu.Parameters {
parameters = append(parameters, dto.MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
parameters = append(parameters, MenuParameterResponse{CreatedAt: parameter.CreatedAt, UpdatedAt: parameter.UpdatedAt, ID: parameter.ID, SysBaseMenuID: parameter.MenuID, Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
}
}
var buttonAuthorities map[string]uint
@@ -137,22 +136,22 @@ func dynamicMenuResponse(menu *biz.Menu) *dto.DynamicMenuResponse {
}
buttonAuthorities[button.Name] = button.AuthorityID
}
return &dto.DynamicMenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: dto.MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: nil, Buttons: buttonAuthorities}
return &DynamicMenuResponse{CreatedAt: menu.CreatedAt, UpdatedAt: menu.UpdatedAt, ID: menu.ID, MenuID: menu.MenuID, ParentID: menu.ParentID, Path: menu.Path, Name: menu.Name, Hidden: menu.Hidden, Component: menu.Component, Sort: menu.Sort, Meta: MenuMetaResponse{ActiveName: menu.ActiveName, KeepAlive: menu.KeepAlive, DefaultMenu: menu.DefaultMenu, Title: menu.Title, Icon: menu.Icon, CloseTab: menu.CloseTab, TransitionType: menu.TransitionType}, Children: children, Parameters: parameters, MenuButtons: nil, Buttons: buttonAuthorities}
}
func menuResponses(items []*biz.Menu) []*dto.MenuResponse {
func menuResponses(items []*biz.Menu) []*MenuResponse {
if items == nil {
return nil
}
out := make([]*dto.MenuResponse, 0, len(items))
out := make([]*MenuResponse, 0, len(items))
for _, item := range items {
out = append(out, menuResponse(item))
}
return out
}
func dynamicMenuResponses(items []*biz.Menu) []*dto.DynamicMenuResponse {
out := make([]*dto.DynamicMenuResponse, 0, len(items))
func dynamicMenuResponses(items []*biz.Menu) []*DynamicMenuResponse {
out := make([]*DynamicMenuResponse, 0, len(items))
for _, item := range items {
out = append(out, dynamicMenuResponse(item))
}
+3 -4
View File
@@ -6,20 +6,19 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
func TestMenuDomainPreservesRelationIdentity(t *testing.T) {
createdAt := time.Date(2025, time.March, 4, 5, 6, 7, 0, time.UTC)
updatedAt := time.Date(2025, time.April, 5, 6, 7, 8, 0, time.UTC)
menu := menuDomain(&dto.MenuRequest{
menu := menuDomain(&MenuRequest{
CreatedAt: createdAt,
UpdatedAt: updatedAt,
ID: 10,
MenuButtons: []dto.MenuButtonRequest{{
MenuButtons: []MenuButtonRequest{{
CreatedAt: createdAt, UpdatedAt: updatedAt, ID: 31, Name: "edit", Description: "编辑",
}},
Parameters: []dto.MenuParameterRequest{{
Parameters: []MenuParameterRequest{{
CreatedAt: createdAt, UpdatedAt: updatedAt, ID: 21, Type: "query", Key: "id", Value: "1",
}},
})
+10 -11
View File
@@ -5,7 +5,6 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type ParameterService struct{ uc *biz.ParameterUsecase }
@@ -14,40 +13,40 @@ func NewParameterService(uc *biz.ParameterUsecase) *ParameterService {
return &ParameterService{uc: uc}
}
func parameterDomain(value *dto.SystemParameterRequest) *biz.SystemParameter {
func parameterDomain(value *SystemParameterRequest) *biz.SystemParameter {
return &biz.SystemParameter{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, Name: value.Name, Key: value.Key, Value: value.Value, Desc: value.Description}
}
func (s *ParameterService) CreateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
func (s *ParameterService) CreateParameterRequest(ctx context.Context, req *SystemParameterRequest) error {
return s.CreateParameter(ctx, parameterDomain(req))
}
func (s *ParameterService) UpdateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
func (s *ParameterService) UpdateParameterRequest(ctx context.Context, req *SystemParameterRequest) error {
return s.UpdateParameter(ctx, parameterDomain(req))
}
func (s *ParameterService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]*dto.SystemParameterResponse, int64, error) {
func (s *ParameterService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]*SystemParameterResponse, int64, error) {
return s.Parameters(ctx, page, size, &biz.SystemParameter{Name: name, Key: key, StartCreatedAt: start, EndCreatedAt: end})
}
func parameterDTO(v *biz.SystemParameter) *dto.SystemParameterResponse {
return &dto.SystemParameterResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Key: v.Key, Value: v.Value, Desc: v.Desc}
func parameterDTO(v *biz.SystemParameter) *SystemParameterResponse {
return &SystemParameterResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Key: v.Key, Value: v.Value, Desc: v.Desc}
}
func (s *ParameterService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]*dto.SystemParameterResponse, int64, error) {
func (s *ParameterService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]*SystemParameterResponse, int64, error) {
items, total, err := s.uc.ListParameters(ctx, page, size, q)
if err != nil {
return nil, 0, err
}
out := make([]*dto.SystemParameterResponse, 0, len(items))
out := make([]*SystemParameterResponse, 0, len(items))
for _, v := range items {
out = append(out, parameterDTO(v))
}
return out, total, nil
}
func (s *ParameterService) ParameterByID(ctx context.Context, id string) (*dto.SystemParameterResponse, error) {
func (s *ParameterService) ParameterByID(ctx context.Context, id string) (*SystemParameterResponse, error) {
v, err := s.uc.FindParameterByID(ctx, id)
if err != nil {
return nil, err
}
return parameterDTO(v), nil
}
func (s *ParameterService) ParameterByKey(ctx context.Context, key string) (*dto.SystemParameterResponse, error) {
func (s *ParameterService) ParameterByKey(ctx context.Context, key string) (*SystemParameterResponse, error) {
v, err := s.uc.FindParameterByKey(ctx, key)
if err != nil {
return nil, err
+27 -20
View File
@@ -5,38 +5,37 @@ import (
"errors"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type PaymentService struct{ uc *biz.PaymentUsecase }
func NewPaymentService(uc *biz.PaymentUsecase) *PaymentService { return &PaymentService{uc: uc} }
func (s *PaymentService) Configs(ctx context.Context) ([]*dto.PaymentConfigResponse, error) {
func (s *PaymentService) Configs(ctx context.Context) ([]*PaymentConfigResponse, error) {
configs, err := s.uc.Configs(ctx)
if err != nil {
return nil, err
}
result := make([]*dto.PaymentConfigResponse, 0, len(configs))
result := make([]*PaymentConfigResponse, 0, len(configs))
for _, config := range configs {
if config == nil {
continue
}
result = append(result, &dto.PaymentConfigResponse{Provider: config.Provider, Enabled: config.Enabled, Config: config.Values})
result = append(result, &PaymentConfigResponse{Provider: config.Provider, Enabled: config.Enabled, Config: config.Values})
}
return result, nil
}
func (s *PaymentService) SaveConfig(ctx context.Context, req *dto.PaymentConfigRequest) error {
func (s *PaymentService) SaveConfig(ctx context.Context, req *PaymentConfigRequest) error {
if req == nil {
return errors.New("支付配置请求为空")
}
return s.uc.SaveConfig(ctx, &biz.PaymentConfig{Provider: req.Provider, Enabled: req.Enabled, Values: req.Config})
}
func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*dto.PaymentOrderResponse, error) {
func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*PaymentOrderResponse, error) {
order, err := s.uc.Order(ctx, provider, tradeNo)
if err != nil {
return nil, err
}
return &dto.PaymentOrderResponse{
return &PaymentOrderResponse{
ID: order.ID,
Provider: order.Provider, TradeNo: order.TradeNo, ProviderTradeNo: order.ProviderTradeNo,
BusinessType: order.BusinessType, BusinessID: order.BusinessID, Subject: order.Subject,
@@ -53,7 +52,7 @@ func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*
}, nil
}
func (s *PaymentService) Orders(ctx context.Context, req *dto.PaymentOrderListRequest) ([]*dto.PaymentOrderResponse, int64, int, int, error) {
func (s *PaymentService) Orders(ctx context.Context, req *PaymentOrderListRequest) ([]*PaymentOrderResponse, int64, int, int, error) {
if req == nil {
return nil, 0, 1, 10, errors.New("支付订单列表请求为空")
}
@@ -71,7 +70,7 @@ func (s *PaymentService) Orders(ctx context.Context, req *dto.PaymentOrderListRe
if err != nil {
return nil, 0, page, pageSize, err
}
result := make([]*dto.PaymentOrderResponse, 0, len(items))
result := make([]*PaymentOrderResponse, 0, len(items))
for _, item := range items {
converted, convertErr := paymentOrderResponse(item)
if convertErr != nil {
@@ -82,11 +81,11 @@ func (s *PaymentService) Orders(ctx context.Context, req *dto.PaymentOrderListRe
return result, total, page, pageSize, nil
}
func paymentOrderResponse(order *biz.PaymentOrder) (*dto.PaymentOrderResponse, error) {
func paymentOrderResponse(order *biz.PaymentOrder) (*PaymentOrderResponse, error) {
if order == nil {
return nil, errors.New("支付订单为空")
}
return &dto.PaymentOrderResponse{
return &PaymentOrderResponse{
ID: order.ID, Provider: order.Provider, TradeNo: order.TradeNo, ProviderTradeNo: order.ProviderTradeNo,
BusinessType: order.BusinessType, BusinessID: order.BusinessID, Subject: order.Subject,
PaymentMode: order.PaymentMode, OriginalAmount: order.OriginalAmount, Amount: order.Amount, PaidAmount: order.PaidAmount,
@@ -100,7 +99,7 @@ func paymentOrderResponse(order *biz.PaymentOrder) (*dto.PaymentOrderResponse, e
PaidAt: order.PaidAt, FulfilledAt: order.FulfilledAt, RefundedAt: order.RefundedAt,
}, nil
}
func (s *PaymentService) Create(ctx context.Context, req *dto.PaymentRequest) (*dto.PaymentResultResponse, error) {
func (s *PaymentService) Create(ctx context.Context, req *PaymentRequest) (*PaymentResultResponse, error) {
if req == nil {
return nil, errors.New("支付请求为空")
}
@@ -113,21 +112,29 @@ func (s *PaymentService) Create(ctx context.Context, req *dto.PaymentRequest) (*
})
return paymentResultResponse(result), err
}
func (s *PaymentService) Query(ctx context.Context, req *dto.PaymentQueryRequest) (*dto.PaymentResultResponse, error) {
func (s *PaymentService) Query(ctx context.Context, req *PaymentQueryRequest) (*PaymentResultResponse, error) {
if req == nil {
return nil, errors.New("支付查询请求为空")
}
result, err := s.uc.Query(ctx, req.Provider, req.TradeNo)
return paymentResultResponse(result), err
}
func (s *PaymentService) Refund(ctx context.Context, req *dto.PaymentRefundRequest) (*dto.PaymentResultResponse, error) {
func (s *PaymentService) Refund(ctx context.Context, req *PaymentRefundRequest) (*PaymentResultResponse, error) {
if req == nil {
return nil, errors.New("支付退款请求为空")
}
result, err := s.uc.Refund(ctx, req.Provider, req.TradeNo, req.Amount)
return paymentResultResponse(result), err
}
func (s *PaymentService) Callback(ctx context.Context, req *dto.PaymentCallbackRequest) (dto.PaymentCallbackAck, error) {
func (s *PaymentService) Fulfill(ctx context.Context, req *PaymentFulfillRequest) (*PaymentResultResponse, error) {
if req == nil {
return nil, errors.New("支付发货请求为空")
}
result, err := s.uc.Fulfill(ctx, req.Provider, req.TradeNo)
return paymentResultResponse(result), err
}
func (s *PaymentService) Callback(ctx context.Context, req *PaymentCallbackRequest) (PaymentCallbackAck, error) {
if req == nil {
return paymentCallbackAckResponse(biz.DefaultPaymentCallbackAck("", false)), errors.New("支付回调请求为空")
}
@@ -142,15 +149,15 @@ func (s *PaymentService) Callback(ctx context.Context, req *dto.PaymentCallbackR
return paymentCallbackAckResponse(ack), nil
}
func DefaultPaymentCallbackAck(provider string, success bool) dto.PaymentCallbackAck {
func DefaultPaymentCallbackAck(provider string, success bool) PaymentCallbackAck {
return paymentCallbackAckResponse(biz.DefaultPaymentCallbackAck(provider, success))
}
func paymentResultResponse(result *biz.PaymentResult) *dto.PaymentResultResponse {
func paymentResultResponse(result *biz.PaymentResult) *PaymentResultResponse {
if result == nil {
return nil
}
return &dto.PaymentResultResponse{
return &PaymentResultResponse{
Provider: result.Provider, Status: result.Status, TradeNo: result.TradeNo,
ProviderTradeNo: result.ProviderTradeNo, Amount: result.Amount,
PayerPaidAmount: result.PayerPaidAmount, CashPaidAmount: result.CashPaidAmount,
@@ -164,6 +171,6 @@ func paymentResultResponse(result *biz.PaymentResult) *dto.PaymentResultResponse
}
}
func paymentCallbackAckResponse(ack biz.PaymentCallbackAck) dto.PaymentCallbackAck {
return dto.PaymentCallbackAck{StatusCode: ack.StatusCode, ContentType: ack.ContentType, Body: ack.Body}
func paymentCallbackAckResponse(ack biz.PaymentCallbackAck) PaymentCallbackAck {
return PaymentCallbackAck{StatusCode: ack.StatusCode, ContentType: ack.ContentType, Body: ack.Body}
}
+10 -11
View File
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type PositionService struct{ uc *biz.PositionUsecase }
@@ -13,31 +12,31 @@ func NewPositionService(uc *biz.PositionUsecase) *PositionService {
return &PositionService{uc: uc}
}
func positionDomain(value *dto.PositionRequest) *biz.Position {
func positionDomain(value *PositionRequest) *biz.Position {
return &biz.Position{ID: value.ID, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
}
func positionResponse(value *biz.Position) *dto.PositionResponse {
return &dto.PositionResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
func positionResponse(value *biz.Position) *PositionResponse {
return &PositionResponse{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, DeletedAt: nil, Name: value.Name, Code: value.Code, Sort: value.Sort, Status: value.Status, Remark: value.Remark}
}
func (s *PositionService) Positions(ctx context.Context, req *dto.PositionListRequest) ([]*dto.PositionResponse, int64, error) {
func (s *PositionService) Positions(ctx context.Context, req *PositionListRequest) ([]*PositionResponse, int64, error) {
items, total, err := s.uc.Positions(ctx, req.Page, req.PageSize, &biz.PositionListFilter{Name: req.Name, Code: req.Code, Status: req.Status})
if err != nil {
return nil, 0, err
}
out := make([]*dto.PositionResponse, 0, len(items))
out := make([]*PositionResponse, 0, len(items))
for _, item := range items {
out = append(out, positionResponse(item))
}
return out, total, nil
}
func (s *PositionService) Create(ctx context.Context, req *dto.PositionRequest) error {
func (s *PositionService) Create(ctx context.Context, req *PositionRequest) error {
return s.uc.CreatePosition(ctx, positionDomain(req))
}
func (s *PositionService) Update(ctx context.Context, req *dto.PositionRequest) error {
func (s *PositionService) Update(ctx context.Context, req *PositionRequest) error {
return s.uc.UpdatePosition(ctx, positionDomain(req))
}
@@ -45,7 +44,7 @@ func (s *PositionService) Delete(ctx context.Context, id uint) error {
return s.uc.DeletePosition(ctx, id)
}
func (s *PositionService) Position(ctx context.Context, id uint) (*dto.PositionResponse, error) {
func (s *PositionService) Position(ctx context.Context, id uint) (*PositionResponse, error) {
value, err := s.uc.Position(ctx, id)
if err != nil {
return nil, err
@@ -57,10 +56,10 @@ func (s *PositionService) UserIDs(ctx context.Context, id uint) ([]uint, error)
return s.uc.PositionUserIDs(ctx, id)
}
func (s *PositionService) SetUsers(ctx context.Context, req *dto.SetPositionUsersRequest) error {
func (s *PositionService) SetUsers(ctx context.Context, req *SetPositionUsersRequest) error {
return s.uc.SetPositionUsers(ctx, req.PositionID, req.UserIDs)
}
func (s *PositionService) SetUserPositions(ctx context.Context, req *dto.SetUserPositionsRequest) error {
func (s *PositionService) SetUserPositions(ctx context.Context, req *SetUserPositionsRequest) error {
return s.uc.SetUserPositions(ctx, req.ID, req.PositionIDs)
}
@@ -0,0 +1,192 @@
package service
import "strings"
type apiMetadataValue struct{ group, description string }
var apiMetadata = map[string]apiMetadataValue{
"DELETE /api/deleteApisByIds": {group: "api", description: "批量删除api"},
"DELETE /dataAccessLog/deleteDataAccessLogByIds": {group: "数据权限审计", description: "批量删除数据权限审计日志"},
"DELETE /department/deleteDepartment": {group: "部门", description: "删除部门"},
"DELETE /info/deleteInfo": {group: "公告", description: "删除公告"},
"DELETE /info/deleteInfoByIds": {group: "公告", description: "批量删除公告"},
"DELETE /mediaUpload/:uploadId": {group: "媒体上传", description: "取消大文件上传"},
"DELETE /position/deletePosition": {group: "岗位", description: "删除岗位"},
"DELETE /sysDictionary/deleteSysDictionary": {group: "系统字典", description: "删除字典"},
"DELETE /sysDictionaryDetail/deleteSysDictionaryDetail": {group: "系统字典详情", description: "删除字典内容"},
"DELETE /sysError/deleteSysError": {group: "错误日志", description: "删除错误日志"},
"DELETE /sysError/deleteSysErrorByIds": {group: "错误日志", description: "批量删除错误日志"},
"DELETE /sysExportTemplate/deleteSysExportTemplate": {group: "导出模板", description: "删除导出模板"},
"DELETE /sysExportTemplate/deleteSysExportTemplateByIds": {group: "导出模板", description: "批量删除导出模板"},
"DELETE /sysLoginLog/deleteLoginLog": {group: "登录日志", description: "删除登录日志"},
"DELETE /sysLoginLog/deleteLoginLogByIds": {group: "登录日志", description: "批量删除登录日志"},
"DELETE /sysOperationRecord/deleteSysOperationRecord": {group: "操作记录", description: "删除操作记录"},
"DELETE /sysOperationRecord/deleteSysOperationRecordByIds": {group: "操作记录", description: "批量删除操作历史"},
"DELETE /sysParams/deleteSysParams": {group: "参数管理", description: "删除参数"},
"DELETE /sysParams/deleteSysParamsByIds": {group: "参数管理", description: "批量删除参数"},
"DELETE /sysVersion/deleteSysVersion": {group: "版本控制", description: "删除版本"},
"DELETE /sysVersion/deleteSysVersionByIds": {group: "版本控制", description: "批量删除版本"},
"DELETE /timedTask/deleteTimedTask": {group: "定时任务", description: "删除定时任务"},
"DELETE /user/deleteUser": {group: "系统用户", description: "删除用户"},
"GET /api/getApiGroups": {group: "api", description: "获取路由组"},
"GET /api/getApiRoles": {group: "api", description: "获取指定API关联角色列表"},
"GET /api/syncApi": {group: "api", description: "获取待同步API"},
"GET /attachmentCategory/getCategoryList": {group: "媒体库分类", description: "分类列表"},
"GET /authority/getDataScopeDepts": {group: "角色", description: "获取角色自定义部门集"},
"GET /authority/getUsersByAuthority": {group: "角色", description: "获取角色关联用户ID列表"},
"GET /department/findDepartment": {group: "部门", description: "根据ID获取部门"},
"GET /department/getDepartmentUsers": {group: "部门", description: "获取部门成员ID列表"},
"GET /info/findInfo": {group: "公告", description: "根据ID获取公告"},
"GET /info/getInfoList": {group: "公告", description: "获取公告列表"},
"GET /logViewer/content": {group: "文件日志", description: "分块读取日志文件内容"},
"GET /logViewer/dates": {group: "文件日志", description: "获取存在日志的日期"},
"GET /logViewer/files": {group: "文件日志", description: "获取日期下的日志文件"},
"GET /menu/getMenuRoles": {group: "菜单", description: "获取菜单关联角色列表"},
"GET /position/findPosition": {group: "岗位", description: "根据ID获取岗位"},
"GET /position/getPositionUsers": {group: "岗位", description: "获取岗位成员ID列表"},
"GET /payment/configs": {group: "支付", description: "获取支付渠道配置"},
"GET /payment/orders": {group: "支付", description: "分页查询支付订单"},
"GET /securityConfig/getSecurityConfig": {group: "安全配置", description: "获取安全配置"},
"GET /sysDictionary/exportSysDictionary": {group: "系统字典", description: "导出字典JSON"},
"GET /sysDictionary/findSysDictionary": {group: "系统字典", description: "根据ID获取字典(建议选择)"},
"GET /sysDictionary/getSysDictionaryList": {group: "系统字典", description: "获取字典列表"},
"GET /sysDictionary/getSysDictionaryListWithDetails": {group: "系统字典", description: "获取字典列表(含明细)"},
"GET /sysDictionaryDetail/findSysDictionaryDetail": {group: "系统字典详情", description: "根据ID获取字典内容"},
"GET /sysDictionaryDetail/getDictionaryDetailsByParent": {group: "系统字典详情", description: "根据父级ID获取字典详情"},
"GET /sysDictionaryDetail/getDictionaryPath": {group: "系统字典详情", description: "获取字典详情的完整路径"},
"GET /sysDictionaryDetail/getDictionaryTreeList": {group: "系统字典详情", description: "获取字典数列表"},
"GET /sysDictionaryDetail/getDictionaryTreeListByType": {group: "系统字典详情", description: "根据分类获取字典数列表"},
"GET /sysDictionaryDetail/getSysDictionaryDetailList": {group: "系统字典详情", description: "获取字典内容列表"},
"GET /sysError/findSysError": {group: "错误日志", description: "根据ID获取错误日志"},
"GET /sysError/getSysErrorList": {group: "错误日志", description: "获取错误日志列表"},
"GET /sysExportTemplate/exportExcel": {group: "导出模板", description: "导出Excel"},
"GET /sysExportTemplate/exportTemplate": {group: "导出模板", description: "下载模板"},
"GET /sysExportTemplate/findSysExportTemplate": {group: "导出模板", description: "根据ID获取导出模板"},
"GET /sysExportTemplate/getSysExportTemplateList": {group: "导出模板", description: "获取导出模板列表"},
"GET /sysExportTemplate/previewSQL": {group: "导出模板", description: "预览SQL"},
"GET /sysLoginLog/findLoginLog": {group: "登录日志", description: "根据ID获取登录日志"},
"GET /sysLoginLog/getLoginLogList": {group: "登录日志", description: "获取登录日志列表"},
"GET /sysOperationRecord/findSysOperationRecord": {group: "操作记录", description: "根据ID获取操作记录"},
"GET /sysOperationRecord/getSysOperationRecordList": {group: "操作记录", description: "获取操作记录列表"},
"GET /sysParams/findSysParams": {group: "参数管理", description: "根据ID获取参数"},
"GET /sysParams/getSysParam": {group: "参数管理", description: "获取参数列表"},
"GET /sysParams/getSysParamsList": {group: "参数管理", description: "获取参数列表"},
"GET /sysVersion/downloadVersionJson": {group: "版本控制", description: "下载版本json"},
"GET /sysVersion/findSysVersion": {group: "版本控制", description: "获取单一版本"},
"GET /sysVersion/getSysVersionList": {group: "版本控制", description: "获取版本列表"},
"GET /timedTask/alertStream": {group: "定时任务", description: "订阅定时任务失败告警(SSE)"},
"GET /timedTask/getRegisteredMethods": {group: "定时任务", description: "获取已注册方法列表"},
"GET /timedTask/getTimedTaskList": {group: "定时任务", description: "获取定时任务列表"},
"GET /timedTask/getTimedTaskLogList": {group: "定时任务", description: "获取定时任务执行日志"},
"GET /user/getUserInfo": {group: "系统用户", description: "获取自身信息(必选)"},
"POST /api/createApi": {group: "api", description: "创建api"},
"POST /api/deleteApi": {group: "api", description: "删除Api"},
"POST /api/enterSyncApi": {group: "api", description: "确认同步API"},
"POST /api/getAllApis": {group: "api", description: "获取所有api"},
"POST /api/getApiById": {group: "api", description: "获取api详细信息"},
"POST /api/getApiList": {group: "api", description: "获取api列表"},
"POST /api/ignoreApi": {group: "api", description: "忽略API"},
"POST /api/setApiRoles": {group: "api", description: "全量覆盖API关联角色列表"},
"POST /api/updateApi": {group: "api", description: "更新Api"},
"POST /attachmentCategory/addCategory": {group: "媒体库分类", description: "添加/编辑分类"},
"POST /attachmentCategory/deleteCategory": {group: "媒体库分类", description: "删除分类"},
"POST /authority/copyAuthority": {group: "角色", description: "拷贝角色"},
"POST /authority/createAuthority": {group: "角色", description: "创建角色"},
"POST /authority/deleteAuthority": {group: "角色", description: "删除角色"},
"POST /authority/getAuthorityList": {group: "角色", description: "获取角色列表"},
"POST /authority/setDataScope": {group: "角色", description: "设置角色数据权限"},
"POST /authority/setRoleUsers": {group: "角色", description: "全量覆盖角色关联用户"},
"POST /authorityBtn/canRemoveAuthorityBtn": {group: "按钮权限", description: "删除按钮"},
"POST /authorityBtn/getAuthorityBtn": {group: "按钮权限", description: "获取已有按钮权限"},
"POST /authorityBtn/setAuthorityBtn": {group: "按钮权限", description: "设置按钮权限"},
"POST /casbin/getPolicyPathByAuthorityId": {group: "casbin", description: "获取权限列表"},
"POST /casbin/updateCasbin": {group: "casbin", description: "更改角色api权限"},
"POST /dataAccessLog/getDataAccessLogList": {group: "数据权限审计", description: "获取数据权限审计日志"},
"POST /department/createDepartment": {group: "部门", description: "创建部门"},
"POST /department/getDepartmentList": {group: "部门", description: "获取部门树"},
"POST /department/setDepartmentUsers": {group: "部门", description: "设置部门成员(反向分配)"},
"POST /email/emailTest": {group: "email", description: "发送测试邮件"},
"POST /email/sendEmail": {group: "email", description: "发送邮件"},
"POST /fileUploadAndDownload/deleteFile": {group: "文件上传与下载", description: "删除文件"},
"POST /fileUploadAndDownload/editFileName": {group: "文件上传与下载", description: "文件名或者备注编辑"},
"POST /fileUploadAndDownload/getFileList": {group: "文件上传与下载", description: "获取上传文件列表"},
"POST /fileUploadAndDownload/importURL": {group: "文件上传与下载", description: "导入URL"},
"POST /fileUploadAndDownload/upload": {group: "文件上传与下载", description: "文件上传(建议选择)"},
"POST /info/createInfo": {group: "公告", description: "新建公告"},
"POST /jwt/jsonInBlacklist": {group: "jwt", description: "jwt加入黑名单(退出,必选)"},
"POST /mediaUpload/chunk": {group: "媒体上传", description: "上传分片"},
"POST /mediaUpload/complete": {group: "媒体上传", description: "完成大文件上传"},
"POST /mediaUpload/init": {group: "媒体上传", description: "初始化大文件上传"},
"POST /menu/addBaseMenu": {group: "菜单", description: "新增菜单"},
"POST /menu/addMenuAuthority": {group: "菜单", description: "增加menu和角色关联关系"},
"POST /menu/deleteBaseMenu": {group: "菜单", description: "删除菜单"},
"POST /menu/getBaseMenuById": {group: "菜单", description: "根据id获取菜单"},
"POST /menu/getBaseMenuTree": {group: "菜单", description: "获取用户动态路由"},
"POST /menu/getMenu": {group: "菜单", description: "获取菜单树(必选)"},
"POST /menu/getMenuAuthority": {group: "菜单", description: "获取指定角色menu"},
"POST /menu/getMenuList": {group: "菜单", description: "分页获取基础menu列表"},
"POST /menu/setMenuRoles": {group: "菜单", description: "全量覆盖菜单关联角色列表"},
"POST /menu/updateBaseMenu": {group: "菜单", description: "更新菜单"},
"POST /payment/config": {group: "支付", description: "保存支付渠道配置"},
"POST /payment/order": {group: "支付", description: "查询支付订单"},
"POST /position/createPosition": {group: "岗位", description: "创建岗位"},
"POST /position/getPositionList": {group: "岗位", description: "获取岗位列表"},
"POST /position/setPositionUsers": {group: "岗位", description: "设置岗位成员(反向分配)"},
"POST /securityConfig/setSecurityConfig": {group: "安全配置", description: "设置安全配置"},
"POST /sysApiToken/createApiToken": {group: "API Token", description: "签发API Token"},
"POST /sysApiToken/deleteApiToken": {group: "API Token", description: "作废API Token"},
"POST /sysApiToken/getApiTokenList": {group: "API Token", description: "获取API Token列表"},
"POST /sysDictionary/createSysDictionary": {group: "系统字典", description: "新增字典"},
"POST /sysDictionary/importSysDictionary": {group: "系统字典", description: "导入字典JSON"},
"POST /sysDictionaryDetail/createSysDictionaryDetail": {group: "系统字典详情", description: "新增字典内容"},
"POST /sysError/createSysError": {group: "错误日志", description: "新建错误日志"},
"POST /sysExportTemplate/createSysExportTemplate": {group: "导出模板", description: "新增导出模板"},
"POST /sysExportTemplate/importExcel": {group: "导出模板", description: "导入Excel"},
"POST /sysOperationRecord/createSysOperationRecord": {group: "操作记录", description: "新增操作记录"},
"POST /sysParams/createSysParams": {group: "参数管理", description: "新建参数"},
"POST /system/getServerInfo": {group: "系统服务", description: "获取服务器信息"},
"POST /system/getSystemConfig": {group: "系统服务", description: "获取配置文件内容"},
"POST /system/setSystemConfig": {group: "系统服务", description: "设置配置文件内容"},
"POST /sysVersion/exportVersion": {group: "版本控制", description: "创建版本"},
"POST /sysVersion/importVersion": {group: "版本控制", description: "同步版本"},
"POST /timedTask/createTimedTask": {group: "定时任务", description: "创建定时任务"},
"POST /timedTask/toggleTimedTask": {group: "定时任务", description: "启用/停用定时任务"},
"POST /timedTask/triggerTimedTask": {group: "定时任务", description: "手动触发定时任务"},
"POST /user/admin_register": {group: "系统用户", description: "用户注册"},
"POST /user/changePassword": {group: "系统用户", description: "修改密码(建议选择)"},
"POST /user/getUserList": {group: "系统用户", description: "获取用户列表"},
"POST /user/resetPassword": {group: "系统用户", description: "重置用户密码"},
"POST /user/setUserAuthorities": {group: "系统用户", description: "设置权限组"},
"POST /user/setUserAuthority": {group: "系统用户", description: "修改用户角色(必选)"},
"POST /user/setUserDepartments": {group: "系统用户", description: "设置用户归属部门"},
"POST /user/setUserPositions": {group: "系统用户", description: "设置用户岗位"},
"PUT /authority/updateAuthority": {group: "角色", description: "更新角色信息"},
"PUT /department/updateDepartment": {group: "部门", description: "更新部门"},
"PUT /info/updateInfo": {group: "公告", description: "更新公告"},
"PUT /position/updatePosition": {group: "岗位", description: "更新岗位"},
"PUT /sysDictionary/updateSysDictionary": {group: "系统字典", description: "更新字典"},
"PUT /sysDictionaryDetail/updateSysDictionaryDetail": {group: "系统字典详情", description: "更新字典内容"},
"PUT /sysError/updateSysError": {group: "错误日志", description: "更新错误日志"},
"PUT /sysExportTemplate/updateSysExportTemplate": {group: "导出模板", description: "更新导出模板"},
"PUT /sysParams/updateSysParams": {group: "参数管理", description: "更新参数"},
"PUT /timedTask/updateTimedTask": {group: "定时任务", description: "更新定时任务"},
"PUT /user/setSelfInfo": {group: "系统用户", description: "设置自身信息(必选)"},
"PUT /user/setSelfSetting": {group: "系统用户", description: "用户界面配置"},
"PUT /user/setUserInfo": {group: "系统用户", description: "设置用户信息"},
}
// Metadata returns the administration group and description for a route.
func RouteMetadata(method, path string) (string, string) {
if value, ok := apiMetadata[strings.ToUpper(method)+" "+path]; ok {
return value.group, value.description
}
return routeGroup(path), ""
}
func routeGroup(path string) string {
parts := strings.Split(strings.Trim(path, "/"), "/")
if len(parts) > 0 && parts[0] != "" {
return parts[0]
}
return "base"
}
+5 -6
View File
@@ -5,7 +5,6 @@ import (
"errors"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type PasswordPolicyError struct{ Err error }
@@ -18,26 +17,26 @@ func IsPasswordPolicyError(err error) bool {
return errors.As(err, &policyErr)
}
func securityDTO(v *biz.SecurityConfig) *dto.SecurityConfigResponse {
return &dto.SecurityConfigResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, CaptchaOpen: v.CaptchaOpen, CaptchaTimeout: v.CaptchaTimeout, KeyLong: v.KeyLong, ImgWidth: v.ImgWidth, ImgHeight: v.ImgHeight, PwdMinLength: v.PwdMinLength, PwdRequireUpper: v.PwdRequireUpper, PwdRequireLower: v.PwdRequireLower, PwdRequireDigit: v.PwdRequireDigit, PwdRequireSpecial: v.PwdRequireSpecial, LimitEnable: v.LimitEnable, LimitWindow: v.LimitWindow, LimitCount: v.LimitCount, LockEnable: v.LockEnable, LockThreshold: v.LockThreshold, LockDuration: v.LockDuration, PwdExpireEnable: v.PwdExpireEnable, PwdExpireDays: v.PwdExpireDays, ForceNewUserChangePassword: v.ForceNewUserChangePassword}
func securityDTO(v *biz.SecurityConfig) *SecurityConfigResponse {
return &SecurityConfigResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, CaptchaOpen: v.CaptchaOpen, CaptchaTimeout: v.CaptchaTimeout, KeyLong: v.KeyLong, ImgWidth: v.ImgWidth, ImgHeight: v.ImgHeight, PwdMinLength: v.PwdMinLength, PwdRequireUpper: v.PwdRequireUpper, PwdRequireLower: v.PwdRequireLower, PwdRequireDigit: v.PwdRequireDigit, PwdRequireSpecial: v.PwdRequireSpecial, LimitEnable: v.LimitEnable, LimitWindow: v.LimitWindow, LimitCount: v.LimitCount, LockEnable: v.LockEnable, LockThreshold: v.LockThreshold, LockDuration: v.LockDuration, PwdExpireEnable: v.PwdExpireEnable, PwdExpireDays: v.PwdExpireDays, ForceNewUserChangePassword: v.ForceNewUserChangePassword}
}
func (s *SecurityService) CurrentSecurity(ctx context.Context) (*biz.SecurityConfig, error) {
return s.uc.Current(ctx)
}
func (s *SecurityService) Security(ctx context.Context) (*dto.SecurityConfigResponse, error) {
func (s *SecurityService) Security(ctx context.Context) (*SecurityConfigResponse, error) {
value, err := s.uc.Security(ctx)
if err != nil {
return nil, err
}
return securityDTO(value), nil
}
func (s *SecurityService) SaveSecurity(ctx context.Context, value *biz.SecurityConfig) (*dto.SecurityConfigResponse, error) {
func (s *SecurityService) SaveSecurity(ctx context.Context, value *biz.SecurityConfig) (*SecurityConfigResponse, error) {
if err := s.uc.UpdateSecurity(ctx, value); err != nil {
return nil, err
}
return securityDTO(value), nil
}
func (s *SecurityService) SaveSecurityRequest(ctx context.Context, value *dto.SecurityConfigRequest) (*dto.SecurityConfigResponse, error) {
func (s *SecurityService) SaveSecurityRequest(ctx context.Context, value *SecurityConfigRequest) (*SecurityConfigResponse, error) {
return s.SaveSecurity(ctx, &biz.SecurityConfig{
ID: value.ID, CaptchaOpen: value.CaptchaOpen, CaptchaTimeout: value.CaptchaTimeout,
KeyLong: value.KeyLong, ImgWidth: value.ImgWidth, ImgHeight: value.ImgHeight,
+1 -3
View File
@@ -3,8 +3,6 @@ package service
import (
"context"
"encoding/json"
"kra/app/system/internal/dto"
)
func (s *SystemConfigService) PersistConfig(ctx context.Context) error {
@@ -21,6 +19,6 @@ func (s *SystemConfigService) SystemConfig() (json.RawMessage, error) {
return s.uc.ConfigurationJSON()
}
func (s *SystemConfigService) SaveSystemConfig(ctx context.Context, req *dto.SetSystemConfigRequest) error {
func (s *SystemConfigService) SaveSystemConfig(ctx context.Context, req *SetSystemConfigRequest) error {
return s.uc.SaveConfigurationJSON(ctx, req.Config)
}
+7 -9
View File
@@ -4,14 +4,12 @@ import (
"runtime"
"time"
"kra/app/system/internal/dto"
"github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/disk"
"github.com/shirou/gopsutil/v4/mem"
)
func (s *SystemConfigService) ServerInfo() (*dto.ServerInfoResponse, error) {
func (s *SystemConfigService) ServerInfo() (*ServerInfoResponse, error) {
physicalCores, err := cpu.Counts(false)
if err != nil {
return nil, err
@@ -24,19 +22,19 @@ func (s *SystemConfigService) ServerInfo() (*dto.ServerInfoResponse, error) {
if err != nil {
return nil, err
}
diskInfo := make([]dto.ServerDiskResponse, 0)
diskInfo := make([]ServerDiskResponse, 0)
for _, mountPoint := range s.DiskMountPoints() {
usage, usageErr := disk.Usage(mountPoint)
if usageErr != nil {
return nil, usageErr
}
diskInfo = append(diskInfo, dto.ServerDiskResponse{MountPoint: mountPoint, UsedMB: usage.Used / 1024 / 1024, UsedGB: usage.Used / 1024 / 1024 / 1024, TotalMB: usage.Total / 1024 / 1024, TotalGB: usage.Total / 1024 / 1024 / 1024, UsedPercent: int(usage.UsedPercent)})
diskInfo = append(diskInfo, ServerDiskResponse{MountPoint: mountPoint, UsedMB: usage.Used / 1024 / 1024, UsedGB: usage.Used / 1024 / 1024 / 1024, TotalMB: usage.Total / 1024 / 1024, TotalGB: usage.Total / 1024 / 1024 / 1024, UsedPercent: int(usage.UsedPercent)})
}
usedMB, totalMB := memory.Used/1024/1024, memory.Total/1024/1024
return &dto.ServerInfoResponse{
OS: dto.ServerOSResponse{GOOS: runtime.GOOS, NumCPU: runtime.NumCPU(), Compiler: runtime.Compiler, GoVersion: runtime.Version(), NumGoroutine: runtime.NumGoroutine()},
CPU: dto.ServerCPUResponse{CPUs: cpuPercent, Cores: physicalCores},
RAM: dto.ServerRAMResponse{UsedMB: usedMB, TotalMB: totalMB, UsedPercent: int(memory.UsedPercent)},
return &ServerInfoResponse{
OS: ServerOSResponse{GOOS: runtime.GOOS, NumCPU: runtime.NumCPU(), Compiler: runtime.Compiler, GoVersion: runtime.Version(), NumGoroutine: runtime.NumGoroutine()},
CPU: ServerCPUResponse{CPUs: cpuPercent, Cores: physicalCores},
RAM: ServerRAMResponse{UsedMB: usedMB, TotalMB: totalMB, UsedPercent: int(memory.UsedPercent)},
Disk: diskInfo,
}, nil
}
+3 -5
View File
@@ -4,11 +4,9 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
"kra/app/system/internal/routeinfo"
)
func (s *SystemConfigService) Initialize(ctx context.Context, input *dto.DatabaseInitRequest, apis []*biz.API) error {
func (s *SystemConfigService) Initialize(ctx context.Context, input *DatabaseInitRequest, apis []*biz.API) error {
driver, config := input.DBType, ""
switch driver {
case "mysql":
@@ -25,11 +23,11 @@ func (s *SystemConfigService) Initialize(ctx context.Context, input *dto.Databas
return s.uc.Initialize(ctx, &biz.DatabaseConfig{Driver: driver, Host: input.Host, Port: input.Port, User: input.UserName, Password: input.Password, Name: input.DBName, Path: input.DBPath, Config: config, Template: input.Template, AdminPassword: input.AdminPassword, APIs: apis})
}
func (s *SystemConfigService) InitializeRoutes(ctx context.Context, input *dto.DatabaseInitRequest, routes []dto.Route) error {
func (s *SystemConfigService) InitializeRoutes(ctx context.Context, input *DatabaseInitRequest, routes []Route) error {
apis := make([]*biz.API, 0, len(routes))
for _, route := range routes {
path := NormalizeRoutePath(route.Path, s.settings.RouterPrefix())
group, description := routeinfo.Metadata(route.Method, path)
group, description := RouteMetadata(route.Method, path)
apis = append(apis, &biz.API{Path: path, Method: route.Method, APIGroup: group, Description: description})
}
return s.Initialize(ctx, input, apis)
+14 -15
View File
@@ -6,7 +6,6 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type TaskService struct {
@@ -16,20 +15,20 @@ type TaskService struct {
func NewTaskService(uc *biz.TaskApplicationUsecase) *TaskService {
return &TaskService{uc: uc}
}
func taskDomain(v *dto.TaskRequest) *biz.TimedTask {
func taskDomain(v *TaskRequest) *biz.TimedTask {
return &biz.TimedTask{ID: v.ID, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: v.Params, HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: v.HTTPHeader, HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled}
}
func (s *TaskService) CreateRequest(ctx context.Context, req *dto.TaskRequest) (uint, error) {
func (s *TaskService) CreateRequest(ctx context.Context, req *TaskRequest) (uint, error) {
value := taskDomain(req)
if err := s.Create(ctx, value); err != nil {
return 0, err
}
return value.ID, nil
}
func (s *TaskService) UpdateRequest(ctx context.Context, req *dto.TaskRequest) error {
func (s *TaskService) UpdateRequest(ctx context.Context, req *TaskRequest) error {
return s.Update(ctx, taskDomain(req))
}
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool) ([]*dto.TaskResponse, int64, error) {
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool) ([]*TaskResponse, int64, error) {
return s.Tasks(ctx, page, size, &biz.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled})
}
func (s *TaskService) Create(ctx context.Context, v *biz.TimedTask) error {
@@ -44,15 +43,15 @@ func (s *TaskService) Delete(ctx context.Context, id uint) error {
func (s *TaskService) Toggle(ctx context.Context, id uint, enabled bool) error {
return s.uc.Toggle(ctx, id, enabled)
}
func taskDTO(v *biz.TimedTask, next *time.Time) *dto.TaskResponse {
return &dto.TaskResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: json.RawMessage(v.Params), HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: json.RawMessage(v.HTTPHeader), HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled, NextRunAt: next}
func taskDTO(v *biz.TimedTask, next *time.Time) *TaskResponse {
return &TaskResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: json.RawMessage(v.Params), HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: json.RawMessage(v.HTTPHeader), HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled, NextRunAt: next}
}
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]*dto.TaskResponse, int64, error) {
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]*TaskResponse, int64, error) {
items, total, next, err := s.uc.List(ctx, page, size, q)
if err != nil {
return nil, 0, err
}
out := make([]*dto.TaskResponse, 0, len(items))
out := make([]*TaskResponse, 0, len(items))
for _, v := range items {
var ptr *time.Time
if value, ok := next[v.ID]; ok {
@@ -64,14 +63,14 @@ func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTas
return out, total, nil
}
func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, status string) ([]*dto.TaskLogResponse, int64, error) {
func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, status string) ([]*TaskLogResponse, int64, error) {
items, total, err := s.uc.Logs(ctx, page, size, taskID, status)
if err != nil {
return nil, 0, err
}
out := make([]*dto.TaskLogResponse, 0, len(items))
out := make([]*TaskLogResponse, 0, len(items))
for _, v := range items {
out = append(out, &dto.TaskLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, TaskID: v.TaskID, TaskName: v.TaskName, TriggerType: v.TriggerType, StartedAt: v.StartedAt, FinishedAt: v.FinishedAt, DurationMS: v.DurationMS, Status: v.Status, ErrorMsg: v.ErrorMsg, Output: v.Output})
out = append(out, &TaskLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, TaskID: v.TaskID, TaskName: v.TaskName, TriggerType: v.TriggerType, StartedAt: v.StartedAt, FinishedAt: v.FinishedAt, DurationMS: v.DurationMS, Status: v.Status, ErrorMsg: v.ErrorMsg, Output: v.Output})
}
return out, total, nil
}
@@ -81,11 +80,11 @@ func (s *TaskService) Reload(ctx context.Context) error { return s.uc
func (s *TaskService) Subscribe(userID uint) chan []byte { return s.uc.Subscribe(userID) }
func (s *TaskService) Unsubscribe(userID uint, events chan []byte) { s.uc.Unsubscribe(userID, events) }
func (s *TaskService) RegisteredMethods() []*dto.TaskMethodResponse {
func (s *TaskService) RegisteredMethods() []*TaskMethodResponse {
methods := s.uc.RegisteredMethods()
out := make([]*dto.TaskMethodResponse, 0, len(methods))
out := make([]*TaskMethodResponse, 0, len(methods))
for _, method := range methods {
out = append(out, &dto.TaskMethodResponse{Name: method.Name, Description: method.Description})
out = append(out, &TaskMethodResponse{Name: method.Name, Description: method.Description})
}
return out
}
+13 -14
View File
@@ -4,7 +4,6 @@ import (
"context"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type userInput struct {
@@ -24,23 +23,23 @@ func NewUserService(uc *biz.UserUsecase, settings *SecurityService) *UserService
return &UserService{uc: uc, settings: settings}
}
func userRequestInput(value *dto.UserRequest) userInput {
func userRequestInput(value *UserRequest) userInput {
return userInput{ID: value.ID, Username: value.Username, Password: value.Password, NickName: value.NickName, HeaderImg: value.HeaderImg, AuthorityID: value.AuthorityID, AuthorityIDs: value.AuthorityIDs, Enable: value.Enable, Phone: value.Phone, Email: value.Email}
}
func (s *UserService) ListUsersRequest(ctx context.Context, value *dto.UserListRequest) ([]*dto.UserResponse, int64, error) {
func (s *UserService) ListUsersRequest(ctx context.Context, value *UserListRequest) ([]*UserResponse, int64, error) {
return s.ListUsers(ctx, value.Page, value.PageSize, &biz.UserListFilter{Username: value.Username, NickName: value.NickName, Phone: value.Phone, Email: value.Email, OrderKey: value.OrderKey, Desc: value.Desc})
}
func (s *UserService) CreateUserRequest(ctx context.Context, value *dto.UserRequest) (*dto.UserResponse, error) {
func (s *UserService) CreateUserRequest(ctx context.Context, value *UserRequest) (*UserResponse, error) {
return s.createUser(ctx, userRequestInput(value))
}
func (s *UserService) UpdateUserRequest(ctx context.Context, value *dto.UserRequest) error {
func (s *UserService) UpdateUserRequest(ctx context.Context, value *UserRequest) error {
return s.updateUser(ctx, userRequestInput(value))
}
func (s *UserService) UpdateSelfUserRequest(ctx context.Context, id uint, value *dto.SelfUserRequest) error {
func (s *UserService) UpdateSelfUserRequest(ctx context.Context, id uint, value *SelfUserRequest) error {
return s.updateSelfUser(ctx, userInput{ID: id, NickName: value.NickName, HeaderImg: value.HeaderImg, Phone: value.Phone, Email: value.Email, Enable: value.Enable})
}
func (s *UserService) User(ctx context.Context, id uint) (*dto.UserResponse, error) {
func (s *UserService) User(ctx context.Context, id uint) (*UserResponse, error) {
value, err := s.uc.User(ctx, id)
if err != nil {
return nil, err
@@ -48,7 +47,7 @@ func (s *UserService) User(ctx context.Context, id uint) (*dto.UserResponse, err
return convertUser(value), nil
}
func (s *UserService) UserByUUID(ctx context.Context, uuid string) (*dto.UserResponse, error) {
func (s *UserService) UserByUUID(ctx context.Context, uuid string) (*UserResponse, error) {
value, err := s.uc.UserByUUID(ctx, uuid)
if err != nil {
return nil, err
@@ -56,7 +55,7 @@ func (s *UserService) UserByUUID(ctx context.Context, uuid string) (*dto.UserRes
return convertUser(value), nil
}
func (s *UserService) Menus(ctx context.Context, authorityID uint) ([]*dto.DynamicMenuResponse, error) {
func (s *UserService) Menus(ctx context.Context, authorityID uint) ([]*DynamicMenuResponse, error) {
menus, err := s.uc.Menus(ctx, authorityID)
if err != nil {
return nil, err
@@ -64,31 +63,31 @@ func (s *UserService) Menus(ctx context.Context, authorityID uint) ([]*dto.Dynam
return dynamicMenuResponses(menus), nil
}
func (s *UserService) ListUsers(ctx context.Context, page, pageSize int, filter *biz.UserListFilter) ([]*dto.UserResponse, int64, error) {
func (s *UserService) ListUsers(ctx context.Context, page, pageSize int, filter *biz.UserListFilter) ([]*UserResponse, int64, error) {
users, total, err := s.uc.ListUsers(ctx, page, pageSize, filter)
if err != nil {
return nil, 0, err
}
result := make([]*dto.UserResponse, 0, len(users))
result := make([]*UserResponse, 0, len(users))
for _, user := range users {
result = append(result, convertUser(user))
}
return result, total, nil
}
func (s *UserService) Authorities(ctx context.Context) ([]*dto.AuthorityResponse, error) {
func (s *UserService) Authorities(ctx context.Context) ([]*AuthorityResponse, error) {
values, err := s.uc.Authorities(ctx)
if err != nil {
return nil, err
}
result := make([]*dto.AuthorityResponse, 0, len(values))
result := make([]*AuthorityResponse, 0, len(values))
for _, value := range values {
result = append(result, convertAuthority(*value))
}
return result, nil
}
func (s *UserService) createUser(ctx context.Context, input userInput) (*dto.UserResponse, error) {
func (s *UserService) createUser(ctx context.Context, input userInput) (*UserResponse, error) {
if err := s.settings.ValidatePassword(ctx, input.Password); err != nil {
return nil, err
}
+12 -13
View File
@@ -2,43 +2,42 @@ package service
import (
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
func convertAuthority(value biz.Authority) *dto.AuthorityResponse {
var menus []*dto.MenuResponse
func convertAuthority(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 convertUser(user *biz.User) *dto.UserResponse {
var authorities []*dto.AuthorityResponse
func convertUser(user *biz.User) *UserResponse {
var authorities []*AuthorityResponse
if user.Authorities != nil {
authorities = make([]*dto.AuthorityResponse, 0, len(user.Authorities))
authorities = make([]*AuthorityResponse, 0, len(user.Authorities))
for _, value := range user.Authorities {
authorities = append(authorities, convertAuthority(value))
}
}
var departments []*dto.DepartmentResponse
var departments []*DepartmentResponse
if user.Departments != nil {
departments = make([]*dto.DepartmentResponse, 0, len(user.Departments))
departments = make([]*DepartmentResponse, 0, len(user.Departments))
for i := range user.Departments {
departments = append(departments, departmentResponse(&user.Departments[i]))
}
}
var positions []*dto.PositionResponse
var positions []*PositionResponse
if user.Positions != nil {
positions = make([]*dto.PositionResponse, 0, len(user.Positions))
positions = make([]*PositionResponse, 0, len(user.Positions))
for i := range user.Positions {
positions = append(positions, positionResponse(&user.Positions[i]))
}
}
// The primary department is represented by a zero-value object when it is
// absent, preserving the response shape expected by the administration UI.
var department any = dto.DepartmentResponse{}
var department any = DepartmentResponse{}
if user.Department != nil {
department = departmentResponse(user.Department)
}
return &dto.UserResponse{ID: user.ID, CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt, DeletedAt: nil, UUID: user.UUID, Username: user.Username, NickName: user.NickName, HeaderImg: user.HeaderImg, AuthorityID: user.AuthorityID, Authority: convertAuthority(user.Authority), Authorities: authorities, DeptID: user.DeptID, Department: department, Departments: departments, Positions: positions, Phone: user.Phone, Email: user.Email, Enable: user.Enable, OriginSetting: user.OriginSetting, PasswordUpdatedAt: user.PasswordUpdatedAt}
return &UserResponse{ID: user.ID, CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt, DeletedAt: nil, UUID: user.UUID, Username: user.Username, NickName: user.NickName, HeaderImg: user.HeaderImg, AuthorityID: user.AuthorityID, Authority: convertAuthority(user.Authority), Authorities: authorities, DeptID: user.DeptID, Department: department, Departments: departments, Positions: positions, Phone: user.Phone, Email: user.Email, Enable: user.Enable, OriginSetting: user.OriginSetting, PasswordUpdatedAt: user.PasswordUpdatedAt}
}
+9 -10
View File
@@ -6,7 +6,6 @@ import (
"time"
"kra/app/system/internal/biz"
"kra/app/system/internal/dto"
)
type VersionService struct{ uc *biz.VersionUsecase }
@@ -49,7 +48,7 @@ type versionExportMenu struct {
Hidden bool `json:"hidden"`
Component string `json:"component"`
Sort int `json:"sort"`
Meta dto.VersionMenuMetaRequest `json:"meta"`
Meta VersionMenuMetaRequest `json:"meta"`
Authorities []any `json:"authoritys"`
Children []*versionExportMenu `json:"children"`
Parameters []versionExportMenuParameter `json:"parameters"`
@@ -106,7 +105,7 @@ type versionExportDocument struct {
func exportMenu(value *biz.Menu) *versionExportMenu {
menu := &versionExportMenu{
Path: value.Path, Name: value.Name, Hidden: value.Hidden, Component: value.Component, Sort: value.Sort,
Meta: dto.VersionMenuMetaRequest{ActiveName: value.ActiveName, KeepAlive: value.KeepAlive, DefaultMenu: value.DefaultMenu, Title: value.Title, Icon: value.Icon, CloseTab: value.CloseTab, TransitionType: value.TransitionType},
Meta: VersionMenuMetaRequest{ActiveName: value.ActiveName, KeepAlive: value.KeepAlive, DefaultMenu: value.DefaultMenu, Title: value.Title, Icon: value.Icon, CloseTab: value.CloseTab, TransitionType: value.TransitionType},
}
if len(value.Parameters) > 0 {
menu.Parameters = make([]versionExportMenuParameter, 0, len(value.Parameters))
@@ -129,8 +128,8 @@ func exportMenu(value *biz.Menu) *versionExportMenu {
return menu
}
func versionDTO(v *biz.Version) *dto.VersionResponse {
return &dto.VersionResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, VersionName: v.Name, VersionCode: v.Code, Description: v.Description, VersionData: v.Data}
func versionDTO(v *biz.Version) *VersionResponse {
return &VersionResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, VersionName: v.Name, VersionCode: v.Code, Description: v.Description, VersionData: v.Data}
}
func versionValue(value *string) string {
@@ -141,18 +140,18 @@ func versionValue(value *string) string {
}
func versionPointer(value string) *string { return &value }
func (s *VersionService) Versions(ctx context.Context, page, size int, name, code string, createdAtRange []*time.Time) ([]*dto.VersionResponse, int64, error) {
func (s *VersionService) Versions(ctx context.Context, page, size int, name, code string, createdAtRange []*time.Time) ([]*VersionResponse, int64, error) {
items, total, err := s.uc.ListVersions(ctx, page, size, name, code, createdAtRange)
if err != nil {
return nil, 0, err
}
out := make([]*dto.VersionResponse, 0, len(items))
out := make([]*VersionResponse, 0, len(items))
for _, v := range items {
out = append(out, versionDTO(v))
}
return out, total, nil
}
func (s *VersionService) Version(ctx context.Context, id uint) (*dto.VersionResponse, error) {
func (s *VersionService) Version(ctx context.Context, id uint) (*VersionResponse, error) {
v, err := s.uc.FindVersion(ctx, id)
if err != nil {
return nil, err
@@ -223,7 +222,7 @@ func (s *VersionService) Export(ctx context.Context, name, code, description str
func (s *VersionService) Import(ctx context.Context, bundle *biz.VersionBundle) error {
return s.uc.ImportVersionBundle(ctx, bundle)
}
func versionMenuDomain(value dto.VersionMenuRequest) *biz.Menu {
func versionMenuDomain(value VersionMenuRequest) *biz.Menu {
menu := &biz.Menu{Path: value.Path, Name: value.Name, Hidden: value.Hidden, Component: value.Component, Sort: value.Sort, ActiveName: value.Meta.ActiveName, KeepAlive: value.Meta.KeepAlive, DefaultMenu: value.Meta.DefaultMenu, Title: value.Meta.Title, Icon: value.Meta.Icon, CloseTab: value.Meta.CloseTab, TransitionType: value.Meta.TransitionType}
for _, button := range value.MenuButtons {
menu.Buttons = append(menu.Buttons, &biz.MenuButton{Name: button.Name, Description: button.Description})
@@ -236,7 +235,7 @@ func versionMenuDomain(value dto.VersionMenuRequest) *biz.Menu {
}
return menu
}
func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersionRequest) error {
func (s *VersionService) ImportRequest(ctx context.Context, req *ImportVersionRequest) error {
if req.Version.Name == "" || req.Version.Code == "" {
return biz.ErrInvalidVersion
}