diff --git a/main.go b/main.go index 4a3390d..099d650 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,9 @@ func copySwaggerFolder() { } func main() { - app := fiber.New() + app := fiber.New(fiber.Config{ + BodyLimit: 100 * 1024 * 1024, + }) app.Use(cors.New()) diff --git a/modules/equipment/equipment.go b/modules/equipment/equipment.go index 3245199..35cb1d3 100644 --- a/modules/equipment/equipment.go +++ b/modules/equipment/equipment.go @@ -5,6 +5,7 @@ import ( "jannex/admin-dashboard-backend/modules/structs" "github.com/gofiber/fiber/v2" + "github.com/rs/zerolog/log" ) const Base = "https://inv.ex.umbach.dev" @@ -16,7 +17,39 @@ func GetEquipmentDocumentation(stockItemId string, c *fiber.Ctx) error { database.DB.Where("stock_item_id = ?", stockItemId).Find(&documentations) - return c.JSON(documentations) + statusCode := 200 + + if len(documentations) == 0 { + // there are no documentations for this equipment on the our database + // so there will be checked on invex if the stock item exists + + a := fiber.AcquireAgent() + + a.Add("Authorization", "Token "+ApiToken) + + req := a.Request() + req.Header.SetMethod(fiber.MethodGet) + req.SetRequestURI(apiBase + "/stock/" + stockItemId + "/") + + if err := a.Parse(); err != nil { + log.Error().Msgf("Failed to parse request, err: %s", err) + return c.SendStatus(fiber.StatusInternalServerError) + } + + statusCode, _, _ = a.Bytes() + + if statusCode == 401 { + log.Error().Msgf("invex not authorized, statusCode: %d", statusCode) + } + + if statusCode == 404 { + log.Error().Msgf("Invex stock item not found, statusCode: %d", statusCode) + } + } + + return c.JSON(structs.ApiEquipmentDocumentationResponse{ + Status: statusCode, + Documentations: documentations}) } /* diff --git a/modules/structs/equipment.go b/modules/structs/equipment.go index b059fd5..86c3321 100644 --- a/modules/structs/equipment.go +++ b/modules/structs/equipment.go @@ -35,3 +35,8 @@ type ApiCreateEquipmentDocumentationRequest struct { Title string `json:"title"` Notes json.RawMessage `json:"notes"` } + +type ApiEquipmentDocumentationResponse struct { + Status int + Documentations []EquipmentDocumentation +} diff --git a/routers/router/api/v1/equipment/equipment.go b/routers/router/api/v1/equipment/equipment.go index 638f5ac..60a70de 100644 --- a/routers/router/api/v1/equipment/equipment.go +++ b/routers/router/api/v1/equipment/equipment.go @@ -63,8 +63,6 @@ func CreateEquipmentDocumentation(c *fiber.Ctx) error { // loop throught bodyNotes and save image to static folder under random name for _, bodyNote := range bodyNotes { - log.Info().Msgf("bodyNote %s", bodyNote) - var newFileName string if bodyNote["image"] != "" { @@ -98,8 +96,6 @@ func CreateEquipmentDocumentation(c *fiber.Ctx) error { }) } - log.Info().Msgf("bodyNotes %v", bodyNotes) - marshaledNotes, err := json.Marshal(notes) if err != nil {