Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize create post logic simple to simple #178

Merged
merged 1 commit into from
Jul 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions internal/service/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ func tagsFrom(originTags []string) []string {

// CreatePost 创建文章
// TODO: 推文+推文内容需要在一个事务中添加,后续优化
func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.PostFormated, error) {
var (
err error
mediaContents []string
)
func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (_ *model.PostFormated, err error) {
var mediaContents []string

defer func() {
if err != nil {
Expand All @@ -116,7 +113,7 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Pos
}()

if mediaContents, err = persistMediaContents(param.Contents); err != nil {
return nil, err
return
}

ip := c.ClientIP()
Expand All @@ -135,7 +132,7 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.Pos
}

for _, item := range param.Contents {
if err = item.Check(); err != nil {
if err := item.Check(); err != nil {
// 属性非法
logrus.Infof("contents check err: %v", err)
continue
Expand Down