dynamic machines
parent
ab82b6c733
commit
d78ef57ac2
|
@ -16,6 +16,16 @@
|
||||||
"parameterName": "kiste2",
|
"parameterName": "kiste2",
|
||||||
"type": "textarea",
|
"type": "textarea",
|
||||||
"displayName": "Nummer der zweiten Kiste yooo"
|
"displayName": "Nummer der zweiten Kiste yooo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameterName": "3d_printer_machine_selection",
|
||||||
|
"type": "select_machine",
|
||||||
|
"displayName": "3D Drucker auswählen",
|
||||||
|
"options": {
|
||||||
|
"location": 1,
|
||||||
|
"whitelist": [1, 2],
|
||||||
|
"blacklist": [0, 5]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tasks": [
|
"tasks": [
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"jannex/admin-dashboard-backend/modules/config"
|
"jannex/admin-dashboard-backend/modules/config"
|
||||||
"jannex/admin-dashboard-backend/modules/database"
|
"jannex/admin-dashboard-backend/modules/database"
|
||||||
"jannex/admin-dashboard-backend/modules/logger"
|
"jannex/admin-dashboard-backend/modules/logger"
|
||||||
|
"jannex/admin-dashboard-backend/modules/requestclient"
|
||||||
"jannex/admin-dashboard-backend/modules/structs"
|
"jannex/admin-dashboard-backend/modules/structs"
|
||||||
"jannex/admin-dashboard-backend/modules/utils"
|
"jannex/admin-dashboard-backend/modules/utils"
|
||||||
"os"
|
"os"
|
||||||
|
@ -17,57 +18,7 @@ import (
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Base = "https://inv.ex.umbach.dev"
|
|
||||||
const apiBase = Base + "/api"
|
|
||||||
const ApiToken = "1367f15d21935e4eb540f897946fb5cd98485c3f"
|
|
||||||
|
|
||||||
func InvexApiRequestClient(requestMethod string, url string) (statusCode int, body []byte, err error) {
|
|
||||||
a := fiber.AcquireAgent()
|
|
||||||
|
|
||||||
a.Add("Authorization", "Token "+ApiToken)
|
|
||||||
|
|
||||||
req := a.Request()
|
|
||||||
req.Header.SetMethod(requestMethod)
|
|
||||||
req.SetRequestURI(url)
|
|
||||||
|
|
||||||
if err := a.Parse(); err != nil {
|
|
||||||
log.Error().Msgf("Failed to parse request, err: %s", err)
|
|
||||||
return 0, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
code, body, _ := a.Bytes()
|
|
||||||
|
|
||||||
if code == 401 {
|
|
||||||
log.Error().Msgf("invex not authorized, code: %d", code)
|
|
||||||
|
|
||||||
logger.AddSystemLog(structs.LogMessage{
|
|
||||||
Id: 29,
|
|
||||||
Type: utils.LogTypeInfo,
|
|
||||||
Messages: []structs.LogData{
|
|
||||||
{Type: "error", Value: "invex not authorized"},
|
|
||||||
{Type: "statusCode", Value: strconv.Itoa(code)},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return code, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if code == 404 {
|
|
||||||
log.Error().Msgf("Invex stock item not found, code: %d", code)
|
|
||||||
|
|
||||||
logger.AddSystemLog(structs.LogMessage{
|
|
||||||
Id: 29,
|
|
||||||
Type: utils.LogTypeInfo,
|
|
||||||
Messages: []structs.LogData{
|
|
||||||
{Type: "error", Value: "invex stock item not found"},
|
|
||||||
{Type: "statusCode", Value: strconv.Itoa(code)},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return code, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return code, body, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type Notes struct {
|
type Notes struct {
|
||||||
Image string
|
Image string
|
||||||
|
@ -189,7 +140,7 @@ func GetEquipmentDocumentations(stockItemId string, query structs.PageQuery, c *
|
||||||
if len(documentations) == 0 {
|
if len(documentations) == 0 {
|
||||||
// there are no documentations for this equipment on the our database
|
// there are no documentations for this equipment on the our database
|
||||||
// so there will be checked on invex if the stock item exists
|
// so there will be checked on invex if the stock item exists
|
||||||
statusCode, _, err = InvexApiRequestClient(fiber.MethodGet, apiBase+"/stock/"+stockItemId+"/")
|
statusCode, _, err = requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/"+stockItemId+"/")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("Invex api request error: %s", err)
|
log.Error().Msgf("Invex api request error: %s", err)
|
||||||
|
@ -341,7 +292,7 @@ func isInList(fileName string, notes []Notes) bool {
|
||||||
// fetching the thumbnail from the invex server and sending it back to the client
|
// fetching the thumbnail from the invex server and sending it back to the client
|
||||||
func GetEquipmentInvexThumbnail(c *fiber.Ctx, stockItemId string) error {
|
func GetEquipmentInvexThumbnail(c *fiber.Ctx, stockItemId string) error {
|
||||||
// first request to /api/stock/:stockItemId/ to get the thumbnail url
|
// first request to /api/stock/:stockItemId/ to get the thumbnail url
|
||||||
_, body, err := InvexApiRequestClient(fiber.MethodGet, apiBase+"/stock/"+stockItemId+"/")
|
_, body, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/"+stockItemId+"/")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("Invex api request error: %s", err)
|
log.Error().Msgf("Invex api request error: %s", err)
|
||||||
|
@ -360,7 +311,7 @@ func GetEquipmentInvexThumbnail(c *fiber.Ctx, stockItemId string) error {
|
||||||
thumbnail := partDetail["thumbnail"].(string)
|
thumbnail := partDetail["thumbnail"].(string)
|
||||||
|
|
||||||
// second request to /media/part_images/:thumbnail to get the thumbnail image
|
// second request to /media/part_images/:thumbnail to get the thumbnail image
|
||||||
_, body, err = InvexApiRequestClient(fiber.MethodGet, Base+"/"+thumbnail)
|
_, body, err = requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.Base+"/"+thumbnail)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("Invex api request error: %s", err)
|
log.Error().Msgf("Invex api request error: %s", err)
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package requestclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"jannex/admin-dashboard-backend/modules/logger"
|
||||||
|
"jannex/admin-dashboard-backend/modules/structs"
|
||||||
|
"jannex/admin-dashboard-backend/modules/utils"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
const Base = "https://inv.ex.umbach.dev"
|
||||||
|
const ApiBase = Base + "/api"
|
||||||
|
const ApiToken = "1367f15d21935e4eb540f897946fb5cd98485c3f"
|
||||||
|
|
||||||
|
func InvexApiRequestClient(requestMethod string, url string) (statusCode int, body []byte, err error) {
|
||||||
|
a := fiber.AcquireAgent()
|
||||||
|
|
||||||
|
a.Add("Authorization", "Token "+ApiToken)
|
||||||
|
|
||||||
|
req := a.Request()
|
||||||
|
req.Header.SetMethod(requestMethod)
|
||||||
|
req.SetRequestURI(url)
|
||||||
|
|
||||||
|
if err := a.Parse(); err != nil {
|
||||||
|
log.Error().Msgf("Failed to parse request, err: %s", err)
|
||||||
|
return 0, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
code, body, _ := a.Bytes()
|
||||||
|
|
||||||
|
if code == 401 {
|
||||||
|
log.Error().Msgf("invex not authorized, code: %d", code)
|
||||||
|
|
||||||
|
logger.AddSystemLog(structs.LogMessage{
|
||||||
|
Id: 29,
|
||||||
|
Type: utils.LogTypeInfo,
|
||||||
|
Messages: []structs.LogData{
|
||||||
|
{Type: "error", Value: "invex not authorized"},
|
||||||
|
{Type: "statusCode", Value: strconv.Itoa(code)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return code, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if code == 404 {
|
||||||
|
log.Error().Msgf("Invex stock item not found, code: %d", code)
|
||||||
|
|
||||||
|
logger.AddSystemLog(structs.LogMessage{
|
||||||
|
Id: 29,
|
||||||
|
Type: utils.LogTypeInfo,
|
||||||
|
Messages: []structs.LogData{
|
||||||
|
{Type: "error", Value: "invex stock item not found"},
|
||||||
|
{Type: "statusCode", Value: strconv.Itoa(code)},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return code, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return code, body, nil
|
||||||
|
}
|
|
@ -57,6 +57,7 @@ type GlobalInputs struct {
|
||||||
ParameterName string `json:"parameterName"`
|
ParameterName string `json:"parameterName"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
|
Options interface{} `json:"options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
|
@ -73,6 +74,7 @@ type TaskParameter struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
Global bool `json:"global"`
|
Global bool `json:"global"`
|
||||||
|
Options interface{} `json:"options"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for ui when a user is writing into input field to lock the task step for other users
|
// used for ui when a user is writing into input field to lock the task step for other users
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package structs
|
||||||
|
|
||||||
|
type MachinesBody struct {
|
||||||
|
Location int
|
||||||
|
Whitelist []int
|
||||||
|
Blacklist []int
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
type MachinesResponse struct {
|
||||||
|
Machines []Machine
|
||||||
|
}
|
||||||
|
|
||||||
|
type Machine struct {
|
||||||
|
PartName string
|
||||||
|
PartThumbnail string
|
||||||
|
Notes MachineNotes
|
||||||
|
}
|
||||||
|
|
||||||
|
type MachineNotes struct {
|
||||||
|
DisplayName string `json:"displayName"`
|
||||||
|
Ip string `json:"ip"`
|
||||||
|
} */
|
|
@ -0,0 +1,67 @@
|
||||||
|
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)
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/equipment"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/equipment"
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/grouptasks"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/grouptasks"
|
||||||
log "jannex/admin-dashboard-backend/routers/router/api/v1/logger"
|
log "jannex/admin-dashboard-backend/routers/router/api/v1/logger"
|
||||||
|
"jannex/admin-dashboard-backend/routers/router/api/v1/machines"
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/notification"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/notification"
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/user"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/user"
|
||||||
"jannex/admin-dashboard-backend/routers/router/api/v1/users"
|
"jannex/admin-dashboard-backend/routers/router/api/v1/users"
|
||||||
|
@ -61,6 +62,9 @@ func SetupRoutes(app *fiber.App) {
|
||||||
ns.Get("/", requestAccessValidation, notification.GetNotifications)
|
ns.Get("/", requestAccessValidation, notification.GetNotifications)
|
||||||
ns.Post("/", requestAccessValidation, notification.AddNotification)
|
ns.Post("/", requestAccessValidation, notification.AddNotification)
|
||||||
|
|
||||||
|
m := v1.Group("/machines")
|
||||||
|
m.Post("/", requestAccessValidation, machines.GetMachines)
|
||||||
|
|
||||||
app.Static("/", config.Cfg.FolderPaths.PublicStatic)
|
app.Static("/", config.Cfg.FolderPaths.PublicStatic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue