1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package handlers
- import (
- "github.com/gofiber/fiber/v2"
- "notabug.org/alimiracle/my-website-api/models"
- "notabug.org/alimiracle/my-website-api/responses"
- )
- func (self Handler) GetAllProjects(c *fiber.Ctx) error {
- var projects []models.Project
- self.Database.FindAll(&projects)
- return c.Status(fiber.StatusOK).JSON(&projects)
- }
- func (self Handler) AddProject(c *fiber.Ctx) error {
- body := models.Project{}
- 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) UpdateProject(c *fiber.Ctx) error {
- id := c.Params("id")
- body := models.Project{}
- 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) DeleteProject(c *fiber.Ctx) error {
- id := c.Params("id")
- var project models.Project
- err := self.Database.Delete(&project, id)
- return responses.Response(c, err)
- }
|