64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package equipment
|
|
|
|
import (
|
|
"jannex/admin-dashboard-backend/modules/equipment"
|
|
"jannex/admin-dashboard-backend/modules/structs"
|
|
"jannex/admin-dashboard-backend/modules/utils"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func GetEquipment(c *fiber.Ctx) error {
|
|
return c.JSON(equipment.GetEquipment())
|
|
}
|
|
|
|
func GetEquipmentDocumentation(c *fiber.Ctx) error {
|
|
var body structs.ApiEquipmentParamsRequest
|
|
|
|
if err := c.ParamsParser(&body); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(err)
|
|
}
|
|
|
|
if errValidation := utils.ValidateStruct(body); errValidation != nil {
|
|
log.Error().Msgf("Failed to validate body, err: %v", errValidation)
|
|
return c.Status(fiber.StatusBadRequest).JSON(errValidation)
|
|
}
|
|
|
|
return equipment.GetEquipmentDocumentation(body.StockItemId, c)
|
|
}
|
|
|
|
// fetching the thumbnail from the invex server and sending it back to the client
|
|
func GetEquipmentThumbnail(c *fiber.Ctx) error {
|
|
//resp, err := http.Get(equipment.Base + "/media/part_images/part_152_image.thumbnail.png")
|
|
|
|
a := fiber.AcquireAgent()
|
|
|
|
a.Add("Authorization", "Token "+equipment.ApiToken)
|
|
|
|
req := a.Request()
|
|
req.Header.SetMethod(fiber.MethodGet)
|
|
req.SetRequestURI(equipment.Base + "/media/part_images/" + c.Params("stockItemThumbnail"))
|
|
|
|
if err := a.Parse(); err != nil {
|
|
log.Error().Msgf("Failed to parse request, err: %s", err)
|
|
return c.SendStatus(fiber.StatusInternalServerError)
|
|
}
|
|
|
|
code, body, errs := a.Bytes()
|
|
|
|
log.Info().Msgf("code %d %s", code, errs)
|
|
/*
|
|
resp := fiber.AcquireResponse()
|
|
|
|
a.SetResponse(resp)
|
|
|
|
fiber.ReleaseResponse(resp)
|
|
*/
|
|
|
|
c.Set("Content-Type", "image/png")
|
|
|
|
return c.Send(body)
|
|
|
|
}
|