mirror of https://gitee.com/answerdev/answer.git
feat: activity add cancelled_at field
This commit is contained in:
parent
20f0a1b664
commit
6e0c41e769
|
@ -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"`
|
||||
|
|
|
@ -2,6 +2,7 @@ package activity
|
|||
|
||||
import (
|
||||
"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) error
|
|||
return
|
||||
}
|
||||
|
||||
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) error
|
|||
UserID: 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
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package activity
|
|||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/answerdev/answer/pkg/converter"
|
||||
|
||||
|
@ -100,7 +101,7 @@ func (vr *VoteRepo) vote(ctx context.Context, objectID string, userID, objectUse
|
|||
Get(&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, objectUse
|
|||
ActivityType: 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, objectUse
|
|||
if 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, obj
|
|||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue