You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by ro...@apache.org on 2024/08/21 07:13:28 UTC

(incubator-answer) 27/49: feat(badge): change badge_award entity

This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch develop/robin
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 3a222877563e3efebd1bb8cffcec796d33b02d99
Author: kumfo <ku...@sifou.com>
AuthorDate: Thu Aug 8 18:16:08 2024 +0800

    feat(badge): change badge_award entity
---
 internal/entity/badge_award_entity.go              |  2 +-
 .../service/badge_award/badge_award_service.go     | 36 ++++++++++++----------
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/internal/entity/badge_award_entity.go b/internal/entity/badge_award_entity.go
index a26fd8de..26369394 100644
--- a/internal/entity/badge_award_entity.go
+++ b/internal/entity/badge_award_entity.go
@@ -28,7 +28,7 @@ type BadgeAward struct {
 	UpdatedAt      time.Time `json:"updated_at" xorm:"updated not null default CURRENT_TIMESTAMP TIMESTAMP updated_at"`
 	UserID         string    `json:"user_id" xorm:"not null index BIGINT(20) user_id"`
 	BadgeID        string    `json:"badge_id" xorm:"not null index BIGINT(20) badge_id"`
-	ObjectID       string    `json:"object_id" xorm:"not null index BIGINT(20) object_id"`
+	AwardKey       string    `json:"award_key" xorm:"not null index VARCHAR(64) award_key"`
 	BadgeGroupID   int8      `json:"badge_group_id" xorm:"not null index BIGINT(20) badge_group_id"`
 	IsBadgeDeleted int8      `json:"is_badge_deleted" xorm:"not null index TINYINT(1) s_badge_deleted"`
 }
diff --git a/internal/service/badge_award/badge_award_service.go b/internal/service/badge_award/badge_award_service.go
index b8e96545..7eb218fd 100644
--- a/internal/service/badge_award/badge_award_service.go
+++ b/internal/service/badge_award/badge_award_service.go
@@ -21,16 +21,13 @@ package badge_award
 
 import (
 	"context"
-	"github.com/apache/incubator-answer/internal/base/reason"
 	"github.com/apache/incubator-answer/internal/entity"
 	"github.com/apache/incubator-answer/internal/schema"
 	answercommon "github.com/apache/incubator-answer/internal/service/answer_common"
 	"github.com/apache/incubator-answer/internal/service/object_info"
 	questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
 	usercommon "github.com/apache/incubator-answer/internal/service/user_common"
-	"github.com/apache/incubator-answer/pkg/htmltext"
 	"github.com/jinzhu/copier"
-	"github.com/segmentfault/pacman/errors"
 	"github.com/segmentfault/pacman/log"
 	"time"
 )
@@ -103,24 +100,29 @@ func (b *BadgeAwardService) GetBadgeAwardList(
 	resp = make([]*schema.GetBadgeAwardWithPageResp, 0, len(badgeAwardList))
 
 	for i, badgeAward := range badgeAwardList {
-		objInfo, e := b.objectInfoService.GetInfo(ctx, badgeAward.ObjectID)
-		if e != nil {
-			err = e
-			return
-		}
-		if objInfo.IsDeleted() {
-			err = errors.BadRequest(reason.NewObjectAlreadyDeleted)
-			return
+		var (
+			objectID, questionID, answerID, commentID, objectType, urlTitle string
+		)
+
+		// if exist object info
+		objInfo, e := b.objectInfoService.GetInfo(ctx, badgeAward.AwardKey)
+		if e == nil && !objInfo.IsDeleted() {
+			objectID = objInfo.ObjectID
+			questionID = objInfo.QuestionID
+			answerID = objInfo.AnswerID
+			commentID = objInfo.CommentID
+			objectType = objInfo.ObjectType
+			urlTitle = objInfo.Title
 		}
 
 		row := &schema.GetBadgeAwardWithPageResp{
 			CreatedAt:      badgeAward.CreatedAt.Unix(),
-			ObjectID:       badgeAward.ObjectID,
-			QuestionID:     objInfo.QuestionID,
-			AnswerID:       objInfo.AnswerID,
-			CommentID:      objInfo.CommentID,
-			ObjectType:     objInfo.ObjectType,
-			UrlTitle:       htmltext.UrlTitle(objInfo.Title),
+			ObjectID:       objectID,
+			QuestionID:     questionID,
+			AnswerID:       answerID,
+			CommentID:      commentID,
+			ObjectType:     objectType,
+			UrlTitle:       urlTitle,
 			AuthorUserInfo: schema.UserBasicInfo{},
 		}