Skip to content

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 timeline revision add tag detail

LinkinStard399b9756ff5
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.go
index 21b1022e..3bab5d81 100644
--- a/cmd/answer/wire_gen.go
+++ b/cmd/answer/wire_gen.go
@@ -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)
diff --git a/internal/base/constant/acticity.go b/internal/base/constant/acticity.go
index befa016b..128659c4 100644
--- a/internal/base/constant/acticity.go
+++ b/internal/base/constant/acticity.go
@@ -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"
diff --git a/internal/entity/question_entity.go b/internal/entity/question_entity.go
index fd459e71..7d1fd167 100644
--- a/internal/entity/question_entity.go
+++ b/internal/entity/question_entity.go
@@ -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"`
}
diff --git a/internal/repo/activity/activity_repo.go b/internal/repo/activity/activity_repo.go
index e192bd16..ddd09d1b 100644
--- a/internal/repo/activity/activity_repo.go
+++ b/internal/repo/activity/activity_repo.go
@@ -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()
}
diff --git a/internal/schema/activity.go b/internal/schema/activity.go
index 196e9198..c0598c30 100644
--- a/internal/schema/activity.go
+++ b/internal/schema/activity.go
@@ -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"`
}
diff --git a/internal/service/activity/activity.go b/internal/service/activity/activity.go
index 73fce527..b5af4c9e 100644
--- a/internal/service/activity/activity.go
+++ b/internal/service/activity/activity.go
@@ -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
diff --git a/internal/service/revision_common/revision_service.go b/internal/service/revision_common/revision_service.go
index d5e08b27..4d85ca98 100644
--- a/internal/service/revision_common/revision_service.go
+++ b/internal/service/revision_common/revision_service.go
@@ -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 {