🐛 Fix filter by author requires internal id which is ridiculous
This commit is contained in:
parent
6055ca4274
commit
f91143ce9a
@ -18,9 +18,13 @@ func listAttachment(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
tx := database.C
|
tx := database.C
|
||||||
|
|
||||||
if author := c.QueryInt("authorId", 0); author > 0 {
|
var author models.Account
|
||||||
tx = tx.Where("account_id = ?", author)
|
if err := database.C.Where("name = ?", c.Query("author")).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
} else {
|
||||||
|
tx = tx.Where("account_id = ?", author.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if usage := strings.Split(c.Query("usage"), " "); len(usage) > 0 {
|
if usage := strings.Split(c.Query("usage"), " "); len(usage) > 0 {
|
||||||
tx = tx.Where("usage IN ?", usage)
|
tx = tx.Where("usage IN ?", usage)
|
||||||
}
|
}
|
||||||
@ -31,7 +35,7 @@ func listAttachment(c *fiber.Ctx) error {
|
|||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
var attachments []models.Attachment
|
var attachments []models.Attachment
|
||||||
if err := tx.Offset(offset).Limit(take).Find(&attachments).Error; err != nil {
|
if err := tx.Order("created_at DESC").Offset(offset).Limit(take).Find(&attachments).Error; err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user