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

kumfo pushed a commit to branch feat/1.4.0/badge
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/feat/1.4.0/badge by this push:
     new 49ba98c6 feat(badge): change badge_award entity
     new 8a40e959 Merge remote-tracking branch 'origin/feat/1.4.0/badge' into 
feat/1.4.0/badge
49ba98c6 is described below

commit 49ba98c6fc1c130ade00af9fddd62bc76aa471e0
Author: kumfo <[email protected]>
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{},
                }
 

Reply via email to