🐛 Fix read out of scope
This commit is contained in:
parent
f3ff8e8222
commit
7cf43656d8
@ -15,15 +15,19 @@ import (
|
|||||||
func listPost(c *fiber.Ctx) error {
|
func listPost(c *fiber.Ctx) error {
|
||||||
take := c.QueryInt("take", 0)
|
take := c.QueryInt("take", 0)
|
||||||
offset := c.QueryInt("offset", 0)
|
offset := c.QueryInt("offset", 0)
|
||||||
authorId := c.QueryInt("authorId", 0)
|
authorId := c.Query("authorId")
|
||||||
|
|
||||||
tx := database.C.
|
tx := database.C.
|
||||||
Where("realm_id IS NULL").
|
Where("realm_id IS NULL").
|
||||||
Where("published_at <= ? OR published_at IS NULL", time.Now()).
|
Where("published_at <= ? OR published_at IS NULL", time.Now()).
|
||||||
Order("created_at desc")
|
Order("created_at desc")
|
||||||
|
|
||||||
if authorId > 0 {
|
var author models.Account
|
||||||
tx = tx.Where(&models.Post{AuthorID: uint(authorId)})
|
if len(authorId) > 0 {
|
||||||
|
if err := database.C.Where(&models.Account{Name: authorId}).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
|
}
|
||||||
|
tx = tx.Where(&models.Post{AuthorID: author.ID})
|
||||||
}
|
}
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
|
Loading…
Reference in New Issue
Block a user