diff --git a/docs/docs.go b/docs/docs.go index f458768e..d6741817 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,4 +1,5 @@ -// Code generated by swaggo/swag. DO NOT EDIT +// Package docs GENERATED BY SWAG; DO NOT EDIT +// This file was generated by swaggo/swag package docs import "github.com/swaggo/swag" @@ -6985,11 +6986,7 @@ const docTemplate = `{ }, "user_info": { "description": "user info", - "allOf": [ - { - "$ref": "#/definitions/schema.UserBasicInfo" - } - ] + "$ref": "#/definitions/schema.UserBasicInfo" }, "vote_count": { "type": "integer" @@ -7001,11 +6998,7 @@ const docTemplate = `{ "properties": { "object": { "description": "this object", - "allOf": [ - { - "$ref": "#/definitions/schema.SearchObject" - } - ] + "$ref": "#/definitions/schema.SearchObject" }, "object_type": { "description": "object_type", @@ -7518,11 +7511,7 @@ const docTemplate = `{ "properties": { "avatar": { "description": "avatar", - "allOf": [ - { - "$ref": "#/definitions/schema.AvatarInfo" - } - ] + "$ref": "#/definitions/schema.AvatarInfo" }, "bio": { "description": "bio", diff --git a/docs/swagger.json b/docs/swagger.json index b90efa55..8433f7c5 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -6974,11 +6974,7 @@ }, "user_info": { "description": "user info", - "allOf": [ - { - "$ref": "#/definitions/schema.UserBasicInfo" - } - ] + "$ref": "#/definitions/schema.UserBasicInfo" }, "vote_count": { "type": "integer" @@ -6990,11 +6986,7 @@ "properties": { "object": { "description": "this object", - "allOf": [ - { - "$ref": "#/definitions/schema.SearchObject" - } - ] + "$ref": "#/definitions/schema.SearchObject" }, "object_type": { "description": "object_type", @@ -7507,11 +7499,7 @@ "properties": { "avatar": { "description": "avatar", - "allOf": [ - { - "$ref": "#/definitions/schema.AvatarInfo" - } - ] + "$ref": "#/definitions/schema.AvatarInfo" }, "bio": { "description": "bio", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index b267b711..f3663b28 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1201,8 +1201,7 @@ definitions: title: type: string user_info: - allOf: - - $ref: '#/definitions/schema.UserBasicInfo' + $ref: '#/definitions/schema.UserBasicInfo' description: user info vote_count: type: integer @@ -1210,8 +1209,7 @@ definitions: schema.SearchResp: properties: object: - allOf: - - $ref: '#/definitions/schema.SearchObject' + $ref: '#/definitions/schema.SearchObject' description: this object object_type: description: object_type @@ -1565,8 +1563,7 @@ definitions: schema.UpdateInfoRequest: properties: avatar: - allOf: - - $ref: '#/definitions/schema.AvatarInfo' + $ref: '#/definitions/schema.AvatarInfo' description: avatar bio: description: bio diff --git a/internal/repo/notification/notification_repo.go b/internal/repo/notification/notification_repo.go index 37c9337a..994113fc 100644 --- a/internal/repo/notification/notification_repo.go +++ b/internal/repo/notification/notification_repo.go @@ -10,6 +10,7 @@ import ( "github.com/answerdev/answer/internal/entity" "github.com/answerdev/answer/internal/schema" notficationcommon "github.com/answerdev/answer/internal/service/notification_common" + "github.com/answerdev/answer/pkg/uid" "github.com/segmentfault/pacman/errors" ) @@ -27,6 +28,7 @@ func NewNotificationRepo(data *data.Data) notficationcommon.NotificationRepo { // AddNotification add notification func (nr *notificationRepo) AddNotification(ctx context.Context, notification *entity.Notification) (err error) { + notification.ObjectID = uid.DeShortID(notification.ObjectID) _, err = nr.data.DB.Insert(notification) if err != nil { return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() @@ -37,6 +39,7 @@ func (nr *notificationRepo) AddNotification(ctx context.Context, notification *e func (nr *notificationRepo) UpdateNotificationContent(ctx context.Context, notification *entity.Notification) (err error) { now := time.Now() notification.UpdatedAt = now + notification.ObjectID = uid.DeShortID(notification.ObjectID) _, err = nr.data.DB.Where("id =?", notification.ID).Cols("content", "updated_at").Update(notification) if err != nil { return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack() diff --git a/internal/service/comment/comment_service.go b/internal/service/comment/comment_service.go index 18b755ab..1e52b0cc 100644 --- a/internal/service/comment/comment_service.go +++ b/internal/service/comment/comment_service.go @@ -18,6 +18,7 @@ import ( "github.com/answerdev/answer/internal/service/permission" usercommon "github.com/answerdev/answer/internal/service/user_common" "github.com/answerdev/answer/pkg/encryption" + "github.com/answerdev/answer/pkg/uid" "github.com/jinzhu/copier" "github.com/segmentfault/pacman/errors" "github.com/segmentfault/pacman/log" @@ -97,6 +98,9 @@ func (cs *CommentService) AddComment(ctx context.Context, req *schema.AddComment if err != nil { return nil, err } + objInfo.ObjectID = uid.DeShortID(objInfo.ObjectID) + objInfo.QuestionID = uid.DeShortID(objInfo.QuestionID) + objInfo.AnswerID = uid.DeShortID(objInfo.AnswerID) if objInfo.ObjectType == constant.QuestionObjectType || objInfo.ObjectType == constant.AnswerObjectType { comment.QuestionID = objInfo.QuestionID } diff --git a/internal/service/notification/notification_service.go b/internal/service/notification/notification_service.go index b6338258..6f5e5b0e 100644 --- a/internal/service/notification/notification_service.go +++ b/internal/service/notification/notification_service.go @@ -12,6 +12,7 @@ import ( "github.com/answerdev/answer/internal/schema" notficationcommon "github.com/answerdev/answer/internal/service/notification_common" "github.com/answerdev/answer/internal/service/revision_common" + "github.com/answerdev/answer/pkg/uid" "github.com/jinzhu/copier" "github.com/segmentfault/pacman/i18n" "github.com/segmentfault/pacman/log" @@ -140,6 +141,20 @@ func (ns *NotificationService) GetNotificationPage(ctx context.Context, searchCo if notificationInfo.IsRead == schema.NotificationRead { item.IsRead = true } + answerID, ok := item.ObjectInfo.ObjectMap["answer"] + if ok { + if item.ObjectInfo.ObjectID == answerID { + item.ObjectInfo.ObjectID = uid.EnShortID(item.ObjectInfo.ObjectMap["answer"]) + } + item.ObjectInfo.ObjectMap["answer"] = uid.EnShortID(item.ObjectInfo.ObjectMap["answer"]) + } + questionID, ok := item.ObjectInfo.ObjectMap["question"] + if ok { + if item.ObjectInfo.ObjectID == questionID { + item.ObjectInfo.ObjectID = uid.EnShortID(item.ObjectInfo.ObjectMap["question"]) + } + item.ObjectInfo.ObjectMap["question"] = uid.EnShortID(item.ObjectInfo.ObjectMap["question"]) + } resp = append(resp, item) } return pager.NewPageModel(total, resp), nil diff --git a/internal/service/notification_common/notification.go b/internal/service/notification_common/notification.go index fe11a389..1a14c466 100644 --- a/internal/service/notification_common/notification.go +++ b/internal/service/notification_common/notification.go @@ -14,6 +14,7 @@ import ( "github.com/answerdev/answer/internal/service/notice_queue" "github.com/answerdev/answer/internal/service/object_info" usercommon "github.com/answerdev/answer/internal/service/user_common" + "github.com/answerdev/answer/pkg/uid" "github.com/goccy/go-json" "github.com/jinzhu/copier" "github.com/segmentfault/pacman/errors" @@ -81,12 +82,13 @@ func (ns *NotificationCommon) HandleNotification() { // ObjectInfo.ObjectID // ObjectInfo.ObjectType func (ns *NotificationCommon) AddNotification(ctx context.Context, msg *schema.NotificationMsg) error { + req := &schema.NotificationContent{ TriggerUserID: msg.TriggerUserID, ReceiverUserID: msg.ReceiverUserID, ObjectInfo: schema.ObjectInfo{ Title: msg.Title, - ObjectID: msg.ObjectID, + ObjectID: uid.DeShortID(msg.ObjectID), ObjectType: msg.ObjectType, }, NotificationAction: msg.NotificationAction, @@ -100,8 +102,8 @@ func (ns *NotificationCommon) AddNotification(ctx context.Context, msg *schema.N req.ObjectInfo.Title = objInfo.Title questionID = objInfo.QuestionID objectMap := make(map[string]string) - objectMap["question"] = objInfo.QuestionID - objectMap["answer"] = objInfo.AnswerID + objectMap["question"] = uid.DeShortID(objInfo.QuestionID) + objectMap["answer"] = uid.DeShortID(objInfo.AnswerID) objectMap["comment"] = objInfo.CommentID req.ObjectInfo.ObjectMap = objectMap }