jokes-bapak2/api/handler/submit/submit_get.go

29 lines
511 B
Go
Raw Normal View History

2021-08-04 02:51:22 +00:00
package submit
import (
"jokes-bapak2-api/core/schema"
core "jokes-bapak2-api/core/submit"
2021-08-04 02:51:22 +00:00
"github.com/gofiber/fiber/v2"
)
func (d *Dependencies) GetSubmission(c *fiber.Ctx) error {
query := new(schema.SubmissionQuery)
2021-08-04 02:51:22 +00:00
err := c.QueryParser(query)
if err != nil {
return err
}
submissions, err := core.GetSubmittedItems(d.DB, c.Context(), *query)
2021-08-04 02:51:22 +00:00
if err != nil {
return err
}
return c.
Status(fiber.StatusOK).
JSON(fiber.Map{
"count": len(submissions),
"jokes": submissions,
})
}