Skip to content

Commit

Permalink
feat: 稿件发表详细信息提交接口
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Jul 26, 2024
1 parent 74b3640 commit fe7efc9
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
6 changes: 6 additions & 0 deletions backend/controller/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
35 changes: 35 additions & 0 deletions backend/controller/postapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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{})
}
17 changes: 12 additions & 5 deletions backend/database/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down
7 changes: 7 additions & 0 deletions backend/database/po.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
5 changes: 5 additions & 0 deletions backend/service/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit fe7efc9

Please sign in to comment.