Skip to content

Commit

Permalink
feat: Application details have been enhanced with tags. (#7777)
Browse files Browse the repository at this point in the history
Refs #7774
  • Loading branch information
zhengkunwang223 authored Jan 27, 2025
1 parent aaaa598 commit 57bfc38
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 36 deletions.
6 changes: 3 additions & 3 deletions backend/app/dto/response/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type AppUpdateRes struct {

type AppDTO struct {
model.App
Installed bool `json:"installed"`
Versions []string `json:"versions"`
Tags []model.Tag `json:"tags"`
Installed bool `json:"installed"`
Versions []string `json:"versions"`
Tags []TagDTO `json:"tags"`
}

type AppItem struct {
Expand Down
2 changes: 1 addition & 1 deletion backend/app/model/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (i *App) GetDescription(ctx *gin.Context) string {
var translations = make(map[string]string)
_ = json.Unmarshal([]byte(i.Description), &translations)
lang := strings.ToLower(common.GetLang(ctx))
if desc, ok := translations[lang]; ok {
if desc, ok := translations[lang]; ok && desc != "" {
return desc
}
if lang == "zh" {
Expand Down
40 changes: 8 additions & 32 deletions backend/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,11 @@ func (a AppService) PageApp(ctx *gin.Context, req request.AppSearch) (interface{
}
appDTO.Description = ap.GetDescription(ctx)
appDTOs = append(appDTOs, appDTO)
appTags, err := appTagRepo.GetByAppId(ap.ID)
tags, err := getAppTags(ap.ID, lang)
if err != nil {
continue
}
var tagIds []uint
for _, at := range appTags {
tagIds = append(tagIds, at.TagId)
}
tags, err := tagRepo.GetByIds(tagIds)
if err != nil {
continue
}
for _, t := range tags {
if t.Name != "" {
tagDTO := response.TagDTO{
ID: t.ID,
Key: t.Key,
Name: t.Name,
}
appDTO.Tags = append(appDTO.Tags, tagDTO)
} else {
var translations = make(map[string]string)
_ = json.Unmarshal([]byte(t.Translations), &translations)
if name, ok := translations[lang]; ok {
tagDTO := response.TagDTO{
ID: t.ID,
Key: t.Key,
Name: name,
}
appDTO.Tags = append(appDTO.Tags, tagDTO)
}
}
return nil, err
}
appDTO.Tags = tags
installs, _ := appInstallRepo.ListBy(appInstallRepo.WithAppId(ap.ID))
appDTO.Installed = len(installs) > 0
}
Expand Down Expand Up @@ -185,7 +157,11 @@ func (a AppService) GetApp(ctx *gin.Context, key string) (*response.AppDTO, erro
versionsRaw = append(versionsRaw, detail.Version)
}
appDTO.Versions = common.GetSortedVersions(versionsRaw)

tags, err := getAppTags(app.ID, strings.ToLower(common.GetLang(ctx)))
if err != nil {
return nil, err
}
appDTO.Tags = tags
return &appDTO, nil
}

Expand Down
38 changes: 38 additions & 0 deletions backend/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1607,3 +1607,41 @@ func RequestDownloadCallBack(downloadCallBackUrl string) {
}
_, _, _ = httpUtil.HandleGet(downloadCallBackUrl, http.MethodGet, constant.TimeOut5s)
}

func getAppTags(appID uint, lang string) ([]response.TagDTO, error) {
appTags, err := appTagRepo.GetByAppId(appID)
if err != nil {
return nil, err
}
var tagIds []uint
for _, at := range appTags {
tagIds = append(tagIds, at.TagId)
}
tags, err := tagRepo.GetByIds(tagIds)
if err != nil {
return nil, err
}
var res []response.TagDTO
for _, t := range tags {
if t.Name != "" {
tagDTO := response.TagDTO{
ID: t.ID,
Key: t.Key,
Name: t.Name,
}
res = append(res, tagDTO)
} else {
var translations = make(map[string]string)
_ = json.Unmarshal([]byte(t.Translations), &translations)
if name, ok := translations[lang]; ok {
tagDTO := response.TagDTO{
ID: t.ID,
Key: t.Key,
Name: name,
}
res = append(res, tagDTO)
}
}
}
return res, nil
}

0 comments on commit 57bfc38

Please sign in to comment.