fix: align admin behavior and Kratos integrations
This commit is contained in:
@@ -15,8 +15,8 @@ func NewVersionService(uc *biz.VersionUsecase) *VersionService { return &Version
|
||||
func versionDTO(v *biz.Version) map[string]any {
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "versionName": v.Name, "versionCode": v.Code, "description": v.Description, "versionData": v.Data}
|
||||
}
|
||||
func (s *VersionService) Versions(ctx context.Context, page, size int, name, code string) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.Repo().ListVersions(ctx, page, size, name, code)
|
||||
func (s *VersionService) Versions(ctx context.Context, page, size int, name, code string, createdAtRange []*time.Time) ([]map[string]any, int64, error) {
|
||||
items, total, err := s.uc.ListVersions(ctx, page, size, name, code, createdAtRange)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
@@ -27,24 +27,25 @@ func (s *VersionService) Versions(ctx context.Context, page, size int, name, cod
|
||||
return out, total, nil
|
||||
}
|
||||
func (s *VersionService) Version(ctx context.Context, id uint) (map[string]any, error) {
|
||||
v, err := s.uc.Repo().FindVersion(ctx, id)
|
||||
v, err := s.uc.FindVersion(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return versionDTO(v), nil
|
||||
}
|
||||
func (s *VersionService) VersionData(ctx context.Context, id uint) (string, string, error) {
|
||||
v, err := s.uc.Repo().FindVersion(ctx, id)
|
||||
v, err := s.uc.FindVersion(ctx, id)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
return v.Data, v.Code, nil
|
||||
}
|
||||
func (s *VersionService) DeleteVersions(ctx context.Context, ids []uint) error {
|
||||
return s.uc.Repo().DeleteVersions(ctx, ids)
|
||||
return s.uc.DeleteVersions(ctx, ids)
|
||||
}
|
||||
|
||||
func (s *VersionService) Export(ctx context.Context, name, code, description string, menuIDs, apiIDs, dictIDs []uint) error {
|
||||
bundle, err := s.uc.Repo().BuildVersionBundle(ctx, menuIDs, apiIDs, dictIDs)
|
||||
bundle, err := s.uc.BuildVersionBundle(ctx, menuIDs, apiIDs, dictIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -69,22 +70,28 @@ func (s *VersionService) Export(ctx context.Context, name, code, description str
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.uc.Repo().CreateVersion(ctx, &biz.Version{Name: name, Code: code, Description: description, Data: string(raw)})
|
||||
return s.uc.CreateVersion(ctx, &biz.Version{Name: name, Code: code, Description: description, Data: string(raw)})
|
||||
}
|
||||
func (s *VersionService) Import(ctx context.Context, bundle *biz.VersionBundle) error {
|
||||
return s.uc.Repo().ImportVersionBundle(ctx, bundle)
|
||||
return s.uc.ImportVersionBundle(ctx, bundle)
|
||||
}
|
||||
func versionMenuDomain(value dto.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})
|
||||
}
|
||||
for _, parameter := range value.Parameters {
|
||||
menu.Parameters = append(menu.Parameters, &biz.MenuParameter{Type: parameter.Type, Key: parameter.Key, Value: parameter.Value})
|
||||
}
|
||||
for _, child := range value.Children {
|
||||
menu.Children = append(menu.Children, versionMenuDomain(child))
|
||||
}
|
||||
return menu
|
||||
}
|
||||
func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersionRequest) error {
|
||||
if req.Version.Name == "" || req.Version.Code == "" {
|
||||
return biz.ErrInvalidVersion
|
||||
}
|
||||
bundle := &biz.VersionBundle{Name: req.Version.Name, Code: req.Version.Code, Description: req.Version.Description, ExportTime: req.Version.ExportTime}
|
||||
for _, menu := range req.Menus {
|
||||
bundle.Menus = append(bundle.Menus, versionMenuDomain(menu))
|
||||
@@ -103,5 +110,15 @@ func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersi
|
||||
}
|
||||
bundle.Dictionaries = append(bundle.Dictionaries, item)
|
||||
}
|
||||
return s.Import(ctx, bundle)
|
||||
if err := s.Import(ctx, bundle); err != nil {
|
||||
return err
|
||||
}
|
||||
raw, _ := json.Marshal(req)
|
||||
_ = s.uc.CreateVersion(ctx, &biz.Version{
|
||||
Name: req.Version.Name,
|
||||
Code: req.Version.Code + "_imported_" + time.Now().Format("20060102150405"),
|
||||
Description: "导入版本: " + req.Version.Description,
|
||||
Data: string(raw),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user