(req request.AppInstalledSearch)
| 77 | } |
| 78 | |
| 79 | func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []response.AppInstallDTO, error) { |
| 80 | var ( |
| 81 | opts []repo.DBOption |
| 82 | total int64 |
| 83 | installs []model.AppInstall |
| 84 | err error |
| 85 | ) |
| 86 | opts = append(opts, repo.WithOrderRuleBy("favorite", "descending")) |
| 87 | opts = append(opts, repo.WithOrderRuleBy("sort_order", "ascending")) |
| 88 | |
| 89 | if req.Name != "" { |
| 90 | opts = append(opts, repo.WithByLikeName(req.Name)) |
| 91 | } |
| 92 | |
| 93 | if len(req.Tags) != 0 { |
| 94 | tags, err := tagRepo.GetByKeys(req.Tags) |
| 95 | if err != nil { |
| 96 | return 0, nil, err |
| 97 | } |
| 98 | var tagIds []uint |
| 99 | for _, t := range tags { |
| 100 | tagIds = append(tagIds, t.ID) |
| 101 | } |
| 102 | appTags, err := appTagRepo.GetByTagIds(tagIds) |
| 103 | if err != nil { |
| 104 | return 0, nil, err |
| 105 | } |
| 106 | var appIds []uint |
| 107 | for _, t := range appTags { |
| 108 | appIds = append(appIds, t.AppId) |
| 109 | } |
| 110 | |
| 111 | opts = append(opts, appInstallRepo.WithAppIdsIn(appIds)) |
| 112 | } |
| 113 | |
| 114 | if req.Update { |
| 115 | installs, err = appInstallRepo.ListBy(context.Background(), opts...) |
| 116 | if err != nil { |
| 117 | return 0, nil, err |
| 118 | } |
| 119 | } else { |
| 120 | total, installs, err = appInstallRepo.Page(req.Page, req.PageSize, opts...) |
| 121 | if err != nil { |
| 122 | return 0, nil, err |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | installDTOs, _ := handleInstalled(installs, req.Update, req.Sync, req.CheckUpdate) |
| 127 | if req.Update { |
| 128 | total = int64(len(installDTOs)) |
| 129 | } |
| 130 | return total, installDTOs, nil |
| 131 | } |
| 132 | |
| 133 | func (a *AppInstallService) CheckExist(req request.AppInstalledInfo) (*response.AppInstalledCheck, error) { |
| 134 | res := &response.AppInstalledCheck{ |
nothing calls this directly
no test coverage detected