answer/internal/repo/activity_common/vote.go

41 lines
1.1 KiB
Go
Raw Normal View History

2022-09-27 17:59:05 +08:00
package activity_common
import (
"context"
"github.com/answerdev/answer/internal/base/data"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/service/activity_common"
"github.com/answerdev/answer/internal/service/unique"
2022-09-27 17:59:05 +08:00
)
// VoteRepo activity repository
type VoteRepo struct {
data *data.Data
uniqueIDRepo unique.UniqueIDRepo
activityRepo activity_common.ActivityRepo
}
// NewVoteRepo new repository
func NewVoteRepo(data *data.Data, activityRepo activity_common.ActivityRepo) activity_common.VoteRepo {
return &VoteRepo{
data: data,
activityRepo: activityRepo,
}
}
func (vr *VoteRepo) GetVoteStatus(ctx context.Context, objectId, userId string) (status string) {
for _, action := range []string{"vote_up", "vote_down"} {
at := &entity.Activity{}
activityType, _, _, err := vr.activityRepo.GetActivityTypeByObjID(ctx, objectId, action)
has, err := vr.data.DB.Where("object_id =? AND cancelled=0 AND activity_type=? AND user_id=?", objectId, activityType, userId).Get(at)
if err != nil {
return ""
}
if has {
return action
}
}
return ""
}