diff --git a/backend/controller/dto.go b/backend/controller/dto.go index 56c7f21..eb8d7f8 100644 --- a/backend/controller/dto.go +++ b/backend/controller/dto.go @@ -129,6 +129,12 @@ type PostLogBody struct { Comment string `json:"comment" bson:"comment"` // 备注 } +type PostVerboseBody struct { + PostID int `json:"post_id" binding:"required"` + Key string `json:"key" binding:"required"` + Values map[string]interface{} `json:"values" binding:"required"` +} + type GetBanListBody struct { // uin Uin int64 `json:"uin" binding:"required"` diff --git a/backend/controller/postapi.go b/backend/controller/postapi.go index 4ae3bb8..62b70b5 100644 --- a/backend/controller/postapi.go +++ b/backend/controller/postapi.go @@ -36,6 +36,7 @@ func NewPostRouter(rg *gin.RouterGroup, ps service.PostService, as service.Accou group.POST("/review-post", pr.ReviewPost) group.POST("/post-log", pr.PostPostLog) group.GET("/post-log/:id", pr.GetPostLog) + group.POST("/submit-verbose", pr.SubmitPostVerbose) return pr } @@ -394,3 +395,37 @@ func (pr *PostRouter) GetPostLog(c *gin.Context) { "list": logs, }) } + +// 提交稿件发布详细信息 +func (pr *PostRouter) SubmitPostVerbose(c *gin.Context) { + _, err := pr.Auth(c, ServiceOnly) + + if err != nil { + return + } + + // 取body的json里的id, op, old_stat, new_stat, comment + var body PostVerboseBody + + if err := c.ShouldBindJSON(&body); err != nil { + pr.Fail(c, 1, err.Error()) + return + } + + var postVerbose database.PostVerbose + + postVerbose.PostID = body.PostID + postVerbose.Key = body.Key + postVerbose.Values = body.Values + postVerbose.CreatedAt = util.GetCSTTime() + + // 提交稿件发布详细信息 + err = pr.PostService.SubmitPostVerbose(&postVerbose) + + if err != nil { + pr.Fail(c, 1, err.Error()) + return + } + + pr.Success(c, gin.H{}) +} diff --git a/backend/database/mongo.go b/backend/database/mongo.go index 2f3600a..c611674 100644 --- a/backend/database/mongo.go +++ b/backend/database/mongo.go @@ -12,11 +12,12 @@ import ( ) const ( - ACCOUNT_COLLECTION = "account" - POST_COLLECTION = "post" - POST_LOG_COLLECTION = "post_log" - METADATA_COLLECTION = "metadata" - BAN_LIST_COLLECTION = "ban_list" + ACCOUNT_COLLECTION = "account" + POST_COLLECTION = "post" + POST_LOG_COLLECTION = "post_log" + POST_VERBOSE_COLLECTION = "post_verbose" + METADATA_COLLECTION = "metadata" + BAN_LIST_COLLECTION = "ban_list" ) type Metadata struct { @@ -543,6 +544,12 @@ func (m *MongoDBManager) UpdatePostStatus(id int, status PostStatus) error { return err } +func (m *MongoDBManager) SavePostVerbose(pv *PostVerbose) error { + _, err := m.Client.Database(viper.GetString("database.mongo.db")).Collection(POST_VERBOSE_COLLECTION).InsertOne(context.TODO(), pv) + + return err +} + func (m *MongoDBManager) GetMetadata(key string) (string, error) { var meta struct { Value string `bson:"value"` diff --git a/backend/database/po.go b/backend/database/po.go index 2d35b88..5b5d6b5 100644 --- a/backend/database/po.go +++ b/backend/database/po.go @@ -71,6 +71,13 @@ type PostLogPO struct { CreatedAt time.Time `json:"created_at" bson:"created_at"` // CST时间 } +type PostVerbose struct { + PostID int `json:"post_id" bson:"post_id"` // 稿件ID + Key string `json:"key" bson:"key"` // 多Bot场景下识别的Key + Values map[string]interface{} `json:"values" bson:"values"` // 值 + CreatedAt time.Time `json:"created_at" bson:"created_at"` // CST时间 +} + type ReviewOption string const ( diff --git a/backend/service/post.go b/backend/service/post.go index c8511d8..e25cef2 100644 --- a/backend/service/post.go +++ b/backend/service/post.go @@ -229,3 +229,8 @@ func (ps *PostService) GetPostLogs(uin int64, postID int) ([]database.PostLogPO, return logs, nil } + +// 提交稿件详细信息 +func (ps *PostService) SubmitPostVerbose(pv *database.PostVerbose) error { + return ps.DB.SavePostVerbose(pv) +}