Merge pull request #109 from alimy/main

fixed create not expected empty string tag when create post
pull/111/head
Michael Li 2 years ago committed by GitHub
commit 3e08e7f90b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -83,12 +83,24 @@ func (p *PostContentItem) Check() error {
return nil
}
func tagsFrom(originTags []string) []string {
tags := make([]string, 0, len(originTags))
for _, tag := range originTags {
// TODO: 优化tag有效性检测
if tag = strings.TrimSpace(tag); len(tag) > 0 {
tags = append(tags, tag)
}
}
return tags
}
func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Post, error) {
ip := c.ClientIP()
tags := tagsFrom(param.Tags)
post := &model.Post{
UserID: userID,
Tags: strings.Join(param.Tags, ","),
Tags: strings.Join(tags, ","),
IP: ip,
IPLoc: util.GetIPLoc(ip),
AttachmentPrice: param.AttachmentPrice,
@ -99,7 +111,7 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Pos
}
// 创建标签
for _, t := range param.Tags {
for _, t := range tags {
tag := &model.Tag{
UserID: userID,
Tag: t,

Loading…
Cancel
Save