1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package handlers
- import (
- "notabug.org/alimiracle/my-website-api/models"
- "notabug.org/alimiracle/my-website-api/responses"
- "github.com/gofiber/fiber/v2"
- )
- func (self Handler) GetAllSkills(c *fiber.Ctx) error {
- var skills []models.Skill
- self.Database.FindAll(&skills)
- return c.Status(fiber.StatusOK).JSON(&skills)
- }
- func (self Handler) AddSkill(c *fiber.Ctx) error {
- body := models.Skill{}
- if err := c.BodyParser(&body); err != nil {
- return responses.BadRequestResponse(c, err)
- }
- // insert new db entry
- err := self.Database.Create(&body)
- return responses.Created_Response(c, &body, err)
- }
- func (self Handler) UpdateSkill(c *fiber.Ctx) error {
- id := c.Params("id")
- body := models.Skill{}
- if err := c.BodyParser(&body); err != nil {
- return responses.BadRequestResponse(c, err)
- }
- err := self.Database.Update(&body, id)
- return responses.Response(c, err)
- }
- func (self Handler) DeleteSkill(c *fiber.Ctx) error {
- id := c.Params("id")
- var skill models.Skill
- err := self.Database.Delete(&skill, id)
- return responses.Response(c, err)
- }
|