equipment documentation
parent
a3ff89f5a1
commit
4f4c063290
4
main.go
4
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())
|
||||
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -35,3 +35,8 @@ type ApiCreateEquipmentDocumentationRequest struct {
|
|||
Title string `json:"title"`
|
||||
Notes json.RawMessage `json:"notes"`
|
||||
}
|
||||
|
||||
type ApiEquipmentDocumentationResponse struct {
|
||||
Status int
|
||||
Documentations []EquipmentDocumentation
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue