优化
This commit is contained in:
@@ -132,6 +132,15 @@ func exportMenu(value *biz.Menu) *versionExportMenu {
|
||||
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 versionValue(value *string) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
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) {
|
||||
items, total, err := s.uc.ListVersions(ctx, page, size, name, code, createdAtRange)
|
||||
if err != nil {
|
||||
@@ -155,11 +164,11 @@ func (s *VersionService) VersionData(ctx context.Context, id uint) (string, stri
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
if v.Data != "" {
|
||||
return v.Data, v.Code, nil
|
||||
if v.Data != nil && *v.Data != "" {
|
||||
return *v.Data, versionValue(v.Code), nil
|
||||
}
|
||||
payload := versionExportDocument{
|
||||
Version: versionExportInfo{Name: v.Name, Code: v.Code, Description: v.Description, ExportTime: v.CreatedAt.Format("2006-01-02 15:04:05")},
|
||||
Version: versionExportInfo{Name: versionValue(v.Name), Code: versionValue(v.Code), Description: versionValue(v.Description), ExportTime: v.CreatedAt.Format("2006-01-02 15:04:05")},
|
||||
Menus: []*versionExportMenu{},
|
||||
APIs: []versionExportAPI{},
|
||||
}
|
||||
@@ -167,7 +176,7 @@ func (s *VersionService) VersionData(ctx context.Context, id uint) (string, stri
|
||||
if marshalErr != nil {
|
||||
return "", "", marshalErr
|
||||
}
|
||||
return string(raw), v.Code, nil
|
||||
return string(raw), versionValue(v.Code), nil
|
||||
}
|
||||
func (s *VersionService) DeleteVersions(ctx context.Context, ids []uint) error {
|
||||
return s.uc.DeleteVersions(ctx, ids)
|
||||
@@ -206,7 +215,7 @@ func (s *VersionService) Export(ctx context.Context, name, code, description str
|
||||
if err != nil {
|
||||
return &biz.VersionStageError{Stage: biz.VersionStageJSON, Err: err}
|
||||
}
|
||||
if err = s.uc.CreateVersion(ctx, &biz.Version{Name: name, Code: code, Description: description, Data: string(raw)}); err != nil {
|
||||
if err = s.uc.CreateVersion(ctx, &biz.Version{Name: versionPointer(name), Code: versionPointer(code), Description: versionPointer(description), Data: versionPointer(string(raw))}); err != nil {
|
||||
return &biz.VersionStageError{Stage: biz.VersionStageSave, Err: err}
|
||||
}
|
||||
return nil
|
||||
@@ -250,10 +259,10 @@ func (s *VersionService) ImportRequest(ctx context.Context, req *dto.ImportVersi
|
||||
}
|
||||
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),
|
||||
Name: versionPointer(req.Version.Name),
|
||||
Code: versionPointer(req.Version.Code + "_imported_" + time.Now().Format("20060102150405")),
|
||||
Description: versionPointer("导入版本: " + req.Version.Description),
|
||||
Data: versionPointer(string(raw)),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user