More work on the new people search

This commit is contained in:
William Bouzourène 2025-03-25 21:55:54 +01:00
parent 9cd17bd8e6
commit 9a41a5f8aa
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww
6 changed files with 337 additions and 121 deletions

View file

@ -297,3 +297,25 @@ func FieldMoveDown(c *fiber.Ctx) error {
return c.Redirect("/admin/fields")
}
func FieldJSON(c *fiber.Ctx) error {
id := c.Params("id")
db, err := helpers.GetDatabase()
if err != nil {
return err
}
var field models.Field
result := db.Preload("List").Preload("List.ListItems").Find(&field, "id = ?", id)
if result.Error != nil {
return result.Error
}
if result.RowsAffected < 1 {
return fiber.NewError(fiber.StatusNotFound, "Not found")
}
return c.JSON(field)
}