ListUserVotes list user's votes
(ctx context.Context, req schema.GetVoteWithPageReq)
| 187 | |
| 188 | // ListUserVotes list user's votes |
| 189 | func (vs *VoteService) ListUserVotes(ctx context.Context, req schema.GetVoteWithPageReq) (resp *pager.PageModel, err error) { |
| 190 | typeKeys := []string{ |
| 191 | activity_type.QuestionVoteUp, |
| 192 | activity_type.QuestionVoteDown, |
| 193 | activity_type.AnswerVoteUp, |
| 194 | activity_type.AnswerVoteDown, |
| 195 | } |
| 196 | activityTypes := make([]int, 0) |
| 197 | activityTypeMapping := make(map[int]string, 0) |
| 198 | |
| 199 | for _, typeKey := range typeKeys { |
| 200 | cfg, err := vs.configService.GetConfigByKey(ctx, typeKey) |
| 201 | if err != nil { |
| 202 | continue |
| 203 | } |
| 204 | activityTypes = append(activityTypes, cfg.ID) |
| 205 | activityTypeMapping[cfg.ID] = typeKey |
| 206 | } |
| 207 | |
| 208 | voteList, total, err := vs.voteRepo.ListUserVotes(ctx, req.UserID, req.Page, req.PageSize, activityTypes) |
| 209 | if err != nil { |
| 210 | return nil, err |
| 211 | } |
| 212 | |
| 213 | lang := handler.GetLangByCtx(ctx) |
| 214 | |
| 215 | votes := make([]*schema.GetVoteWithPageResp, 0) |
| 216 | for _, voteInfo := range voteList { |
| 217 | objInfo, err := vs.objectService.GetInfo(ctx, voteInfo.ObjectID) |
| 218 | if err != nil { |
| 219 | log.Error(err) |
| 220 | continue |
| 221 | } |
| 222 | |
| 223 | item := &schema.GetVoteWithPageResp{ |
| 224 | CreatedAt: voteInfo.CreatedAt.Unix(), |
| 225 | ObjectID: objInfo.ObjectID, |
| 226 | QuestionID: objInfo.QuestionID, |
| 227 | AnswerID: objInfo.AnswerID, |
| 228 | ObjectType: objInfo.ObjectType, |
| 229 | Title: objInfo.Title, |
| 230 | UrlTitle: htmltext.UrlTitle(objInfo.Title), |
| 231 | Content: objInfo.Content, |
| 232 | } |
| 233 | item.VoteType = translator.Tr(lang, |
| 234 | activity_type.ActivityTypeFlagMapping[activityTypeMapping[voteInfo.ActivityType]]) |
| 235 | if objInfo.QuestionStatus == entity.QuestionStatusDeleted { |
| 236 | item.Title = translator.Tr(lang, constant.DeletedQuestionTitleTrKey) |
| 237 | } |
| 238 | votes = append(votes, item) |
| 239 | } |
| 240 | return pager.NewPageModel(total, votes), err |
| 241 | } |
| 242 | |
| 243 | func (vs *VoteService) createVoteOperationInfo(ctx context.Context, |
| 244 | userID string, voteUp bool, objectInfo *schema.SimpleObjectInfo) *schema.VoteOperationInfo { |
nothing calls this directly
no test coverage detected