fix: Fix errors in the status of the post during the initial installation

pull/9/head v1.0.1
1379 2 years ago committed by 1379Monitor
parent 68e30b7c39
commit 89c69fb2b5

@ -334,10 +334,20 @@ func (b basePostServiceImpl) CreateOrUpdate(ctx context.Context, post *entity.Po
if postCount > 0 {
return xerr.BadParam.New("").WithMsg("文章别名已存在(Article alias already exists)").WithStatus(xerr.StatusBadRequest)
}
status := post.Status
err = postDAL.WithContext(ctx).Create(post)
if err != nil {
return WrapDBErr(err)
}
// 😅gorm not insert zero value: https://gorm.io/docs/create.html
if status == consts.PostStatusPublished {
_, err = postDAL.WithContext(ctx).Where(postDAL.ID.Eq(post.ID)).UpdateColumnSimple(postDAL.Status.Value(status))
if err != nil {
return WrapDBErr(err)
}
post.Status = status
}
} else {
// update post
slugCount, err := postDAL.WithContext(ctx).Where(postDAL.Slug.Eq(post.Slug), postDAL.ID.Neq(post.ID)).Count()

@ -180,11 +180,25 @@ func (i installServiceImpl) createDefaultPost(ctx context.Context, category *ent
>
`
formatContent := `<h2 id="hello-sonic" tabindex="-1">Hello Sonic</h2>
<p>使 <a href="https://go-sonic.org" target="_blank">Sonic</a> 使</p>
<h2 id="%E7%9B%B8%E5%85%B3%E9%93%BE%E6%8E%A5" tabindex="-1"></h2>
<ul>
<li><a href="https://github.com/go-sonic" target="_blank">https://github.com/go-sonic</a></li>
<li><a href="https://github.com/go-sonic/default-theme-anatole" target="_blank">https://github.com/go-sonic/default-theme-anatole</a></li>
<li><a href="https://github.com/go-sonic/sonic" target="_blank">https://github.com/go-sonic/sonic</a></li>
</ul>
<p>使</p>
<blockquote>
<p></p>
</blockquote>
`
postParam := param.Post{
Title: "Hello Sonic",
Status: consts.PostStatusPublished,
Slug: "hello-sonic",
OriginalContent: content,
Content: formatContent,
CategoryIDs: []int32{category.ID},
}
return i.PostService.Create(ctx, &postParam)

Loading…
Cancel
Save