|
|
@ -83,12 +83,24 @@ func (p *PostContentItem) Check() error {
|
|
|
|
return nil
|
|
|
|
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) {
|
|
|
|
func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Post, error) {
|
|
|
|
ip := c.ClientIP()
|
|
|
|
ip := c.ClientIP()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags := tagsFrom(param.Tags)
|
|
|
|
post := &model.Post{
|
|
|
|
post := &model.Post{
|
|
|
|
UserID: userID,
|
|
|
|
UserID: userID,
|
|
|
|
Tags: strings.Join(param.Tags, ","),
|
|
|
|
Tags: strings.Join(tags, ","),
|
|
|
|
IP: ip,
|
|
|
|
IP: ip,
|
|
|
|
IPLoc: util.GetIPLoc(ip),
|
|
|
|
IPLoc: util.GetIPLoc(ip),
|
|
|
|
AttachmentPrice: param.AttachmentPrice,
|
|
|
|
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{
|
|
|
|
tag := &model.Tag{
|
|
|
|
UserID: userID,
|
|
|
|
UserID: userID,
|
|
|
|
Tag: t,
|
|
|
|
Tag: t,
|
|
|
|