mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-23 06:45:43 +00:00
unfinished purchase
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/services"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/purchases/validations"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/response"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type PurchaseController struct {
|
||||
service service.PurchaseService
|
||||
}
|
||||
|
||||
func NewPurchaseController(s service.PurchaseService) *PurchaseController {
|
||||
return &PurchaseController{service: s}
|
||||
}
|
||||
|
||||
func (ctrl *PurchaseController) CreateOne(c *fiber.Ctx) error {
|
||||
req := new(validation.CreatePurchaseRequest)
|
||||
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
result, err := ctrl.service.CreateOne(c, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusCreated).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusCreated,
|
||||
Status: "success",
|
||||
Message: "Purchase requisition created successfully",
|
||||
Data: dto.ToPurchaseDetailDTO(*result),
|
||||
})
|
||||
}
|
||||
|
||||
func (ctrl *PurchaseController) ApproveStaffPurchase(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.ParseUint(param, 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid purchase requisition id")
|
||||
}
|
||||
|
||||
req := new(validation.ApproveStaffPurchaseRequest)
|
||||
if err := c.BodyParser(req); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body")
|
||||
}
|
||||
|
||||
result, err := ctrl.service.ApproveStaffPurchase(c, id, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusOK).
|
||||
JSON(response.Success{
|
||||
Code: fiber.StatusOK,
|
||||
Status: "success",
|
||||
Message: "Staff purchase approval recorded successfully",
|
||||
Data: dto.ToPurchaseDetailDTO(*result),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user