MCPcopy Create free account
hub / github.com/apache/answer / ListUserVotes

Method ListUserVotes

internal/service/content/vote_service.go:189–241  ·  view source on GitHub ↗

ListUserVotes list user's votes

(ctx context.Context, req schema.GetVoteWithPageReq)

Source from the content-addressed store, hash-verified

187
188// ListUserVotes list user's votes
189func (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
243func (vs *VoteService) createVoteOperationInfo(ctx context.Context,
244 userID string, voteUp bool, objectInfo *schema.SimpleObjectInfo) *schema.VoteOperationInfo {

Callers

nothing calls this directly

Calls 7

GetLangByCtxFunction · 0.92
UrlTitleFunction · 0.92
TrFunction · 0.92
NewPageModelFunction · 0.92
GetInfoMethod · 0.80
GetConfigByKeyMethod · 0.65
ListUserVotesMethod · 0.65

Tested by

no test coverage detected