mirror of https://gitee.com/answerdev/answer.git
refactor: repo code should procees error
This commit is contained in:
parent
fd7a757ea9
commit
c8175744aa
2
go.mod
2
go.mod
|
@ -17,7 +17,6 @@ require (
|
||||||
github.com/jinzhu/copier v0.3.5
|
github.com/jinzhu/copier v0.3.5
|
||||||
github.com/jinzhu/now v1.1.5
|
github.com/jinzhu/now v1.1.5
|
||||||
github.com/lib/pq v1.10.2
|
github.com/lib/pq v1.10.2
|
||||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
|
||||||
github.com/mojocn/base64Captcha v1.3.5
|
github.com/mojocn/base64Captcha v1.3.5
|
||||||
github.com/segmentfault/pacman v1.0.1
|
github.com/segmentfault/pacman v1.0.1
|
||||||
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347
|
github.com/segmentfault/pacman/contrib/cache/memory v0.0.0-20220929065758-260b3093a347
|
||||||
|
@ -60,6 +59,7 @@ require (
|
||||||
github.com/magiconair/properties v1.8.6 // indirect
|
github.com/magiconair/properties v1.8.6 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||||
|
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
|
|
@ -95,6 +95,9 @@ func (ar *FollowRepo) GetFollowUserIDs(ctx context.Context, objectID string) (us
|
||||||
func (ar *FollowRepo) GetFollowIDs(ctx context.Context, userID, objectKey string) (followIDs []string, err error) {
|
func (ar *FollowRepo) GetFollowIDs(ctx context.Context, userID, objectKey string) (followIDs []string, err error) {
|
||||||
followIDs = make([]string, 0)
|
followIDs = make([]string, 0)
|
||||||
activityType, err := ar.activityRepo.GetActivityTypeByObjKey(ctx, objectKey, "follow")
|
activityType, err := ar.activityRepo.GetActivityTypeByObjKey(ctx, objectKey, "follow")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||||
|
}
|
||||||
session := ar.data.DB.Select("object_id")
|
session := ar.data.DB.Select("object_id")
|
||||||
session.Table(entity.Activity{}.TableName())
|
session.Table(entity.Activity{}.TableName())
|
||||||
session.Where("user_id = ? AND activity_type = ?", userID, activityType)
|
session.Where("user_id = ? AND activity_type = ?", userID, activityType)
|
||||||
|
@ -108,7 +111,7 @@ func (ar *FollowRepo) GetFollowIDs(ctx context.Context, userID, objectKey string
|
||||||
|
|
||||||
// IsFollowed check user if follow object or not
|
// IsFollowed check user if follow object or not
|
||||||
func (ar *FollowRepo) IsFollowed(userId, objectId string) (bool, error) {
|
func (ar *FollowRepo) IsFollowed(userId, objectId string) (bool, error) {
|
||||||
activityType, _, _, err := ar.activityRepo.GetActivityTypeByObjID(nil, objectId, "follow")
|
activityType, _, _, err := ar.activityRepo.GetActivityTypeByObjID(context.TODO(), objectId, "follow")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,11 @@ import (
|
||||||
"github.com/answerdev/answer/internal/base/data"
|
"github.com/answerdev/answer/internal/base/data"
|
||||||
"github.com/answerdev/answer/internal/entity"
|
"github.com/answerdev/answer/internal/entity"
|
||||||
"github.com/answerdev/answer/internal/service/activity_common"
|
"github.com/answerdev/answer/internal/service/activity_common"
|
||||||
"github.com/answerdev/answer/internal/service/unique"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// VoteRepo activity repository
|
// VoteRepo activity repository
|
||||||
type VoteRepo struct {
|
type VoteRepo struct {
|
||||||
data *data.Data
|
data *data.Data
|
||||||
uniqueIDRepo unique.UniqueIDRepo
|
|
||||||
activityRepo activity_common.ActivityRepo
|
activityRepo activity_common.ActivityRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +26,9 @@ func (vr *VoteRepo) GetVoteStatus(ctx context.Context, objectId, userId string)
|
||||||
for _, action := range []string{"vote_up", "vote_down"} {
|
for _, action := range []string{"vote_up", "vote_down"} {
|
||||||
at := &entity.Activity{}
|
at := &entity.Activity{}
|
||||||
activityType, _, _, err := vr.activityRepo.GetActivityTypeByObjID(ctx, objectId, action)
|
activityType, _, _, err := vr.activityRepo.GetActivityTypeByObjID(ctx, objectId, action)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
has, err := vr.data.DB.Where("object_id =? AND cancelled=0 AND activity_type=? AND user_id=?", objectId, activityType, userId).Get(at)
|
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 {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in New Issue