A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
feat: activity add cancelled_at field
LinkinStar6e0c41e769a2
diff --git a/internal/entity/activity_entity.go b/internal/entity/activity_entity.goindex 3e7a7c16..b1e5fc4b 100644--- a/internal/entity/activity_entity.go+++ b/internal/entity/activity_entity.go@@ -12,6 +12,7 @@ type Activity struct {ID string `xorm:"not null pk autoincr BIGINT(20) id"`CreatedAt time.Time `xorm:"created TIMESTAMP created_at"`UpdatedAt time.Time `xorm:"updated TIMESTAMP updated_at"`+ CancelledAt time.Time `xorm:"TIMESTAMP cancelled_at"`UserID string `xorm:"not null index BIGINT(20) user_id"`TriggerUserID int64 `xorm:"not null default 0 index BIGINT(20) trigger_user_id"`ObjectID string `xorm:"not null default 0 index BIGINT(20) object_id"`diff --git a/internal/repo/activity/follow_repo.go b/internal/repo/activity/follow_repo.goindex 14238718..c8bae7b5 100644--- a/internal/repo/activity/follow_repo.go+++ b/internal/repo/activity/follow_repo.go@@ -2,6 +2,7 @@ package activityimport ("context"+ "time""github.com/answerdev/answer/internal/service/activity_common""github.com/answerdev/answer/internal/service/follow"@@ -59,7 +60,7 @@ func (ar *FollowRepo) Follow(ctx context.Context, objectID, userID string) errorreturn}- if has && existsActivity.Cancelled == 0 {+ if has && existsActivity.Cancelled == entity.ActivityAvailable {return}@@ -67,7 +68,7 @@ func (ar *FollowRepo) Follow(ctx context.Context, objectID, userID string) error_, err = session.Where(builder.Eq{"id": existsActivity.ID}).Cols(`cancelled`).Update(&entity.Activity{- Cancelled: 0,+ Cancelled: entity.ActivityAvailable,})} else {// update existing activity with new user id and u object id@@ -75,7 +76,7 @@ func (ar *FollowRepo) Follow(ctx context.Context, objectID, userID string) errorUserID: userID,ObjectID: objectID,ActivityType: activityType,- Cancelled: 0,+ Cancelled: entity.ActivityAvailable,Rank: 0,HasRank: 0,})@@ -120,13 +121,14 @@ func (ar *FollowRepo) FollowCancel(ctx context.Context, objectID, userID string)return}- if has && existsActivity.Cancelled == 1 {+ if has && existsActivity.Cancelled == entity.ActivityCancelled {return}if _, err = session.Where("id = ?", existsActivity.ID).Cols("cancelled").Update(&entity.Activity{- Cancelled: 1,+ Cancelled: entity.ActivityCancelled,+ CancelledAt: time.Now(),}); err != nil {return}diff --git a/internal/repo/activity/vote_repo.go b/internal/repo/activity/vote_repo.goindex 00ccd04b..b42ab467 100644--- a/internal/repo/activity/vote_repo.go+++ b/internal/repo/activity/vote_repo.go@@ -3,6 +3,7 @@ package activityimport ("context""strings"+ "time""github.com/answerdev/answer/pkg/converter"@@ -100,7 +101,7 @@ func (vr *VoteRepo) vote(ctx context.Context, objectID string, userID, objectUseGet(&existsActivity)// is is voted,return- if has && existsActivity.Cancelled == 0 {+ if has && existsActivity.Cancelled == entity.ActivityAvailable {return}@@ -111,7 +112,7 @@ func (vr *VoteRepo) vote(ctx context.Context, objectID string, userID, objectUseActivityType: activityType,Rank: deltaRank,HasRank: hasRank,- Cancelled: 0,+ Cancelled: entity.ActivityAvailable,}// trigger user rank and send notification@@ -131,7 +132,7 @@ func (vr *VoteRepo) vote(ctx context.Context, objectID string, userID, objectUseif has {if _, err = session.Where("id = ?", existsActivity.ID).Cols("`cancelled`").Update(&entity.Activity{- Cancelled: 0,+ Cancelled: entity.ActivityAvailable,}); err != nil {return}@@ -201,13 +202,14 @@ func (vr *VoteRepo) voteCancel(ctx context.Context, objectID string, userID, objreturn}- if existsActivity.Cancelled == 1 {+ if existsActivity.Cancelled == entity.ActivityCancelled {return}if _, err = session.Where("id = ?", existsActivity.ID).Cols("`cancelled`").Update(&entity.Activity{- Cancelled: 1,+ Cancelled: entity.ActivityCancelled,+ CancelledAt: time.Now(),}); err != nil {return}diff --git a/internal/repo/activity_common/follow.go b/internal/repo/activity_common/follow.goindex aee42454..5f7b0ec0 100644--- a/internal/repo/activity_common/follow.go+++ b/internal/repo/activity_common/follow.go@@ -124,7 +124,7 @@ func (ar *FollowRepo) IsFollowed(userID, objectID string) (bool, error) {if !has {return false, nil}- if at.Cancelled == 1 {+ if at.Cancelled == entity.ActivityCancelled {return false, nil} else {return true, nil