jobs.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package handlers
  2. import (
  3. "github.com/gofiber/fiber/v2"
  4. "notabug.org/alimiracle/my-website-api/models"
  5. "notabug.org/alimiracle/my-website-api/responses"
  6. )
  7. func (self Handler) GetAllJobs(c *fiber.Ctx) error {
  8. var jobs []models.Job
  9. self.Database.FindAll(&jobs)
  10. return c.Status(fiber.StatusOK).JSON(&jobs)
  11. }
  12. func (self Handler) AddJob(c *fiber.Ctx) error {
  13. body := models.Job{}
  14. if err := c.BodyParser(&body); err != nil {
  15. return responses.BadRequestResponse(c, err)
  16. }
  17. // insert new db entry
  18. err := self.Database.Create(&body)
  19. return responses.Created_Response(c, &body, err)
  20. }
  21. func (self Handler) UpdateJob(c *fiber.Ctx) error {
  22. id := c.Params("id")
  23. body := models.Job{}
  24. if err := c.BodyParser(&body); err != nil {
  25. return responses.BadRequestResponse(c, err)
  26. }
  27. err := self.Database.Update(&body, id)
  28. return responses.Response(c, err)
  29. }
  30. func (self Handler) DeleteJob(c *fiber.Ctx) error {
  31. id := c.Params("id")
  32. var job models.Job
  33. err := self.Database.Delete(&job, id)
  34. return responses.Response(c, err)
  35. }