From 7cf43656d816ec767a2bc5fa344790ef37187083 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 5 Feb 2024 22:54:41 +0800 Subject: [PATCH] :bug: Fix read out of scope --- pkg/server/posts_api.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/server/posts_api.go b/pkg/server/posts_api.go index f3fac9b..29fa03b 100644 --- a/pkg/server/posts_api.go +++ b/pkg/server/posts_api.go @@ -15,15 +15,19 @@ import ( func listPost(c *fiber.Ctx) error { take := c.QueryInt("take", 0) offset := c.QueryInt("offset", 0) - authorId := c.QueryInt("authorId", 0) + authorId := c.Query("authorId") tx := database.C. Where("realm_id IS NULL"). Where("published_at <= ? OR published_at IS NULL", time.Now()). Order("created_at desc") - if authorId > 0 { - tx = tx.Where(&models.Post{AuthorID: uint(authorId)}) + var author models.Account + 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