feat: activity timeline revision add tag detail

This commit is contained in:
LinkinStar 2022-11-23 14:21:11 +08:00
parent 191ec2a130
commit d399b9756f
7 changed files with 61 additions and 28 deletions

View File

@ -189,7 +189,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
activityCommon := activity_common2.NewActivityCommon(activityRepo)
activityActivityRepo := activity.NewActivityRepo(dataData)
commentCommonService := comment_common.NewCommentCommonService(commentCommonRepo)
activityService := activity2.NewActivityService(activityActivityRepo, userCommon, activityCommon, tagCommonService, objService, commentCommonService, revisionService)
activityService := activity2.NewActivityService(activityActivityRepo, userCommon, activityCommon, tagCommonService, objService, commentCommonService, revisionService, metaService)
activityController := controller.NewActivityController(activityCommon, activityService)
answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController)
swaggerRouter := router.NewSwaggerRouter(swaggerConf)

View File

@ -4,6 +4,11 @@ package constant
type ActivityTypeKey string
const (
ActEdited = "edited"
ActClosed = "closed"
)
const (
ActQuestionAsked ActivityTypeKey = "question.asked"
ActQuestionClosed ActivityTypeKey = "question.closed"
@ -19,8 +24,6 @@ const (
ActQuestionUndeleted ActivityTypeKey = "question.undeleted"
)
// answer activity
const (
ActAnswerAnswered ActivityTypeKey = "answer.answered"
ActAnswerCommented ActivityTypeKey = "answer.commented"
@ -33,8 +36,6 @@ const (
ActAnswerUndeleted ActivityTypeKey = "answer.undeleted"
)
// tag activity
const (
ActTagCreated ActivityTypeKey = "tag.created"
ActTagEdited ActivityTypeKey = "tag.edited"

View File

@ -62,11 +62,12 @@ type QuestionWithTagsRevision struct {
// TagSimpleInfoForRevision tag simple info for revision
type TagSimpleInfoForRevision struct {
ID string `xorm:"not null pk comment('tag_id') BIGINT(20) id"`
MainTagID int64 `xorm:"not null default 0 BIGINT(20) main_tag_id"`
SlugName string `xorm:"not null default '' unique VARCHAR(35) slug_name"`
DisplayName string `xorm:"not null default '' VARCHAR(35) display_name"`
Recommend bool `xorm:"not null default false BOOL recommend"`
Reserved bool `xorm:"not null default false BOOL reserved"`
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
ID string `xorm:"not null pk comment('tag_id') BIGINT(20) id"`
MainTagID int64 `xorm:"not null default 0 BIGINT(20) main_tag_id"`
MainTagSlugName string `xorm:"not null default '' VARCHAR(35) main_tag_slug_name"`
SlugName string `xorm:"not null default '' unique VARCHAR(35) slug_name"`
DisplayName string `xorm:"not null default '' VARCHAR(35) display_name"`
Recommend bool `xorm:"not null default false BOOL recommend"`
Reserved bool `xorm:"not null default false BOOL reserved"`
RevisionID string `xorm:"not null default 0 BIGINT(20) revision_id"`
}

View File

@ -27,7 +27,8 @@ func NewActivityRepo(
func (ar *activityRepo) GetObjectAllActivity(ctx context.Context, objectID string, showVote bool) (
activityList []*entity.Activity, err error) {
activityList = make([]*entity.Activity, 0)
err = ar.data.DB.Find(&activityList, &entity.Activity{OriginalObjectID: objectID})
session := ar.data.DB.Desc("created_at") // TODO: if showVote is false do not show vote activity
err = session.Find(&activityList, &entity.Activity{OriginalObjectID: objectID})
if err != nil {
return nil, errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
}

View File

@ -63,7 +63,16 @@ type GetObjectTimelineDetailResp struct {
// ObjectTimelineDetail object timeline detail
type ObjectTimelineDetail struct {
Title string `json:"title"`
Tags []string `json:"tags"`
OriginalText string `json:"original_text"`
Title string `json:"title"`
Tags []*ObjectTimelineTag `json:"tags"`
OriginalText string `json:"original_text"`
}
// ObjectTimelineTag object timeline tags
type ObjectTimelineTag struct {
SlugName string `json:"slug_name"`
DisplayName string `json:"display_name"`
MainTagSlugName string `json:"main_tag_slug_name"`
Recommend bool `json:"recommend"`
Reserved bool `json:"reserved"`
}

View File

@ -11,6 +11,7 @@ import (
"github.com/answerdev/answer/internal/schema"
"github.com/answerdev/answer/internal/service/activity_common"
"github.com/answerdev/answer/internal/service/comment_common"
"github.com/answerdev/answer/internal/service/meta"
"github.com/answerdev/answer/internal/service/object_info"
"github.com/answerdev/answer/internal/service/revision_common"
"github.com/answerdev/answer/internal/service/tag_common"
@ -33,6 +34,7 @@ type ActivityService struct {
objectInfoService *object_info.ObjService
commentCommonService *comment_common.CommentCommonService
revisionService *revision_common.RevisionService
metaService *meta.MetaService
}
// NewActivityService new activity service
@ -44,6 +46,7 @@ func NewActivityService(
objectInfoService *object_info.ObjService,
commentCommonService *comment_common.CommentCommonService,
revisionService *revision_common.RevisionService,
metaService *meta.MetaService,
) *ActivityService {
return &ActivityService{
objectInfoService: objectInfoService,
@ -53,6 +56,7 @@ func NewActivityService(
tagCommonService: tagCommonService,
commentCommonService: commentCommonService,
revisionService: revisionService,
metaService: metaService,
}
}
@ -116,8 +120,23 @@ func (as *ActivityService) GetObjectTimeline(ctx context.Context, req *schema.Ge
} else {
item.Comment = comment.ParsedText
}
} else if item.ActivityType == constant.ActEdited {
revision, err := as.revisionService.GetRevision(ctx, item.RevisionID)
if err != nil {
log.Error(err)
}
item.Comment = revision.Log
} else if item.ActivityType == constant.ActClosed {
metaInfo, err := as.metaService.GetMetaByObjectIdAndKey(ctx, item.ObjectID, entity.QuestionCloseReasonKey)
if err != nil {
log.Error(err)
} else {
closeMsg := &schema.CloseQuestionMeta{}
if err := json.Unmarshal([]byte(metaInfo.Value), closeMsg); err != nil {
item.Comment = closeMsg.CloseMsg
}
}
}
resp.Timeline = append(resp.Timeline, item)
}
return
@ -127,25 +146,19 @@ func (as *ActivityService) GetObjectTimeline(ctx context.Context, req *schema.Ge
func (as *ActivityService) GetObjectTimelineDetail(ctx context.Context, req *schema.GetObjectTimelineDetailReq) (
resp *schema.GetObjectTimelineDetailResp, err error) {
resp = &schema.GetObjectTimelineDetailResp{}
resp.OldRevision, err = as.getOneObjectDetail(ctx, req.OldRevisionID)
if err != nil {
return nil, err
}
resp.NewRevision, err = as.getOneObjectDetail(ctx, req.NewRevisionID)
if err != nil {
return nil, err
}
resp.OldRevision, _ = as.getOneObjectDetail(ctx, req.OldRevisionID)
resp.NewRevision, _ = as.getOneObjectDetail(ctx, req.NewRevisionID)
return resp, nil
}
// GetObjectTimelineDetail get object detail
func (as *ActivityService) getOneObjectDetail(ctx context.Context, revisionID string) (
resp *schema.ObjectTimelineDetail, err error) {
resp = &schema.ObjectTimelineDetail{Tags: make([]string, 0)}
resp = &schema.ObjectTimelineDetail{Tags: make([]*schema.ObjectTimelineTag, 0)}
revision, err := as.revisionService.GetRevision(ctx, revisionID)
if err != nil {
return nil, err
return nil, nil
}
objInfo, err := as.objectInfoService.GetInfo(ctx, revision.ObjectID)
if err != nil {
@ -160,7 +173,13 @@ func (as *ActivityService) getOneObjectDetail(ctx context.Context, revisionID st
return resp, nil
}
for _, tag := range data.Tags {
resp.Tags = append(resp.Tags, tag.SlugName)
resp.Tags = append(resp.Tags, &schema.ObjectTimelineTag{
SlugName: tag.SlugName,
DisplayName: tag.DisplayName,
MainTagSlugName: tag.MainTagSlugName,
Recommend: tag.Recommend,
Reserved: tag.Reserved,
})
}
resp.Title = data.Title
resp.OriginalText = data.OriginalText

View File

@ -7,6 +7,7 @@ import (
"github.com/answerdev/answer/internal/service/revision"
usercommon "github.com/answerdev/answer/internal/service/user_common"
"github.com/segmentfault/pacman/errors"
"github.com/segmentfault/pacman/log"
"github.com/answerdev/answer/internal/entity"
"github.com/answerdev/answer/internal/schema"
@ -47,6 +48,7 @@ func (rs *RevisionService) GetRevision(ctx context.Context, revisionID string) (
revision *entity.Revision, err error) {
revisionInfo, exist, err := rs.revisionRepo.GetRevisionByID(ctx, revisionID)
if err != nil {
log.Error(err)
return nil, err
}
if !exist {