skills.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package handlers
  2. import (
  3. "notabug.org/alimiracle/my-website-api/models"
  4. "notabug.org/alimiracle/my-website-api/responses"
  5. "github.com/gofiber/fiber/v2"
  6. )
  7. func (self Handler) GetAllSkills(c *fiber.Ctx) error {
  8. var skills []models.Skill
  9. self.Database.FindAll(&skills)
  10. return c.Status(fiber.StatusOK).JSON(&skills)
  11. }
  12. func (self Handler) AddSkill(c *fiber.Ctx) error {
  13. body := models.Skill{}
  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) UpdateSkill(c *fiber.Ctx) error {
  22. id := c.Params("id")
  23. body := models.Skill{}
  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) DeleteSkill(c *fiber.Ctx) error {
  31. id := c.Params("id")
  32. var skill models.Skill
  33. err := self.Database.Delete(&skill, id)
  34. return responses.Response(c, err)
  35. }