package machines import ( "encoding/json" "jannex/admin-dashboard-backend/modules/requestclient" "jannex/admin-dashboard-backend/modules/structs" "jannex/admin-dashboard-backend/modules/utils" "github.com/gofiber/fiber/v2" "github.com/rs/zerolog/log" ) // POST /v1/machines/ /* { location: 2, whitelist: [], blacklist: [] } */ type InvexApiStockListResponse struct { Results []struct { Notes string Status int PartDetail struct { Name string Thumbnail string } `json:"part_detail"` } } func GetMachines(c *fiber.Ctx) error { var body structs.MachinesBody if err := utils.BodyParserHelper(c, &body); err != nil { return c.SendStatus(fiber.StatusBadRequest) } log.Info().Msgf("body %v", body) statusCode, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/?search=&offset=0&limit=25&location=5&part_detail=true") log.Info().Msgf("statuscode %v", statusCode) if err != nil { log.Error().Msgf("Invex api request error: %s", err) return c.SendStatus(fiber.StatusInternalServerError) } // parse body as json var data InvexApiStockListResponse if err := json.Unmarshal(reqBody, &data); err != nil { log.Error().Msgf("Failed to unmarshal json, err: %s", err) return c.SendStatus(fiber.StatusInternalServerError) } for locationItem, i := range data.Results { log.Info().Msgf("lI %v %v", locationItem, i) } //log.Info().Msgf("body %s", data) return c.JSON(data.Results) }