From c8175744aa0f465f9bce9dd6a7ad86ee899641f4 Mon Sep 17 00:00:00 2001 From: edocevol Date: Sun, 30 Oct 2022 21:34:18 +0800 Subject: [PATCH] refactor: repo code should procees error --- go.mod | 2 +- internal/repo/activity_common/follow.go | 5 ++++- internal/repo/activity_common/vote.go | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 7fe0bfd9..b6fa86d5 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( github.com/jinzhu/copier v0.3.5 github.com/jinzhu/now v1.1.5 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/segmentfault/pacman v1.0.1 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/mailru/easyjson v0.7.7 // 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/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/internal/repo/activity_common/follow.go b/internal/repo/activity_common/follow.go index a793fdec..a61ddcdb 100644 --- a/internal/repo/activity_common/follow.go +++ b/internal/repo/activity_common/follow.go @@ -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) { followIDs = make([]string, 0) 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.Table(entity.Activity{}.TableName()) 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 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 { return false, err } diff --git a/internal/repo/activity_common/vote.go b/internal/repo/activity_common/vote.go index c2525145..86db8f39 100644 --- a/internal/repo/activity_common/vote.go +++ b/internal/repo/activity_common/vote.go @@ -6,13 +6,11 @@ import ( "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" ) // VoteRepo activity repository type VoteRepo struct { data *data.Data - uniqueIDRepo unique.UniqueIDRepo 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"} { at := &entity.Activity{} 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) if err != nil { return ""