diff --git a/modules/config/config.go b/modules/config/config.go index 5d3965c..7d0aa71 100644 --- a/modules/config/config.go +++ b/modules/config/config.go @@ -10,12 +10,13 @@ import ( var Cfg Config type Config struct { - Debug bool - ColorizedOutput bool - Host string - Port string - FolderPaths FolderPaths - MariaDB MariaDB + Debug bool + ColorizedOutput bool + Host string + Port string + FolderPaths FolderPaths + MariaDB MariaDB + InvexAPI InvexAPI } type FolderPaths struct { @@ -34,6 +35,11 @@ type MariaDB struct { DatabaseName string } +type InvexAPI struct { + Base string + Token string +} + func LoadConfig() { // used to determine server was startet in docker or not if os.Getenv("DOCKER") == "" { @@ -60,6 +66,11 @@ func LoadConfig() { Port: os.Getenv("MARIADB_PORT"), Username: os.Getenv("MARIADB_USERNAME"), Password: os.Getenv("MARIADB_PASSWORD"), - DatabaseName: os.Getenv("MARIADB_DATABASE_NAME")}, + DatabaseName: os.Getenv("MARIADB_DATABASE_NAME"), + }, + InvexAPI: InvexAPI{ + Base: os.Getenv("INVEX_API_BASE"), + Token: os.Getenv("INVEX_API_TOKEN"), + }, } } diff --git a/modules/equipment/equipment.go b/modules/equipment/equipment.go index 6519d8a..d662be6 100644 --- a/modules/equipment/equipment.go +++ b/modules/equipment/equipment.go @@ -128,7 +128,7 @@ func GetEquipmentDocumentations(stockItemId string, query structs.PageQuery, c * 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 - statusCode, _, err = requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/"+stockItemId+"/") + statusCode, _, err = requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/api/stock/"+stockItemId+"/") if err != nil { log.Error().Msgf("Invex api request error: %s", err) @@ -264,7 +264,7 @@ func isInList(fileName string, notes []Notes) bool { // fetching the thumbnail from the invex server and sending it back to the client func GetEquipmentInvexThumbnail(c *fiber.Ctx, stockItemId string) error { // first request to /api/stock/:stockItemId/ to get the thumbnail url - _, body, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/"+stockItemId+"/") + _, body, err := requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/api/stock/"+stockItemId+"/") if err != nil { log.Error().Msgf("Invex api request error: %s", err) @@ -283,7 +283,7 @@ func GetEquipmentInvexThumbnail(c *fiber.Ctx, stockItemId string) error { thumbnail := partDetail["thumbnail"].(string) // second request to /media/part_images/:thumbnail to get the thumbnail image - _, body, err = requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.Base+"/"+thumbnail) + _, body, err = requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/"+thumbnail) if err != nil { log.Error().Msgf("Invex api request error: %s", err) diff --git a/modules/requestclient/requestclient.go b/modules/requestclient/requestclient.go index e87ded7..38b683f 100644 --- a/modules/requestclient/requestclient.go +++ b/modules/requestclient/requestclient.go @@ -1,6 +1,7 @@ package requestclient import ( + "jannex/admin-dashboard-backend/modules/config" "jannex/admin-dashboard-backend/modules/logger" "strconv" @@ -8,14 +9,13 @@ import ( "github.com/rs/zerolog/log" ) -const Base = "https://inv.ex.umbach.dev" -const ApiBase = Base + "/api" -const ApiToken = "1367f15d21935e4eb540f897946fb5cd98485c3f" +//const Base = "https://inv.ex.umbach.dev" +//const ApiBase = Base + "/api" func InvexApiRequestClient(requestMethod string, url string) (statusCode int, body []byte, err error) { a := fiber.AcquireAgent() - a.Add("Authorization", "Token "+ApiToken) + a.Add("Authorization", "Token "+config.Cfg.InvexAPI.Token) req := a.Request() req.Header.SetMethod(requestMethod) diff --git a/modules/utils/globals.go b/modules/utils/globals.go index 2446c05..b8c03be 100644 --- a/modules/utils/globals.go +++ b/modules/utils/globals.go @@ -52,50 +52,50 @@ var ( // commands sent to web clients const ( - SentCmdInitUserSocketConnection = 1 - SentCmdUpdateConnectedUsers = 2 - SentCmdNewGroupTaskStarted = 3 - SentCmdNewGroupTaskStep = 4 - SentCmdUpdateGroupTaskStep = 5 - SentCmdUpdateGroupTask = 6 - SentCmdReloadingGroupTasks = 7 - SentCmdGroupTasksReloaded = 8 - SentCmdUpdateUserSessions = 9 - SentCmdUpdateAllUsersUserAvatar = 10 - SentCmdNewScanner = 11 - SentCmdDeleteScanner = 12 - SentCmdUpdateScannerUsedBy = 13 - SentCmdScanResult = 14 - SentCmdUpdateScannerLastUsed = 15 - SentCmdTaskLocked = 16 - SentCmdTaskUnlocked = 17 - SentCmdUserProfileUpdated = 18 - SentCmdAdminAreaNewRoleCreated = 19 - SentCmdAdminAreaRoleUpdated = 20 - SentCmdAdminAreaUpdateRoleSortingOrder = 21 - SentCmdAdminAreaRoleDeleted = 22 - SentCmdAllUsersUserRoleUpdated = 23 - SentCmdRolePermissionsUpdated = 24 - SentCmdErrorNoPermissions = 25 - SentCmdAllUsersNewUserCreated = 26 - SentCmdAllUsersUserDeleted = 27 - SentCmdAllUsersUserDeactivation = 28 - SentCmdGroupTasksCategoryGroupChanges = 29 - SentCmdNewUserApiKeyCreated = 30 - SentCmdDeletedUserApiKey = 31 - SentCmdNewApiKeyUsageCount = 32 - SentCmdInstallingPythonPackages = 33 - SentCmdInstallingPythonPackagesFailed = 34 - SentCmdInstallingPythonPackagesFinished = 35 - SentCmdInstallingGlobalPythonPackages = 36 - SentCmdInstallingGlobalPythonPackagesFailed = 37 - SentCmdInstallingGlobalPythonPackagesFinished = 38 - SentCmdUpdateUsers = 39 - SentCmdNewNotification = 41 - SentCmdAllNotificationsDeleted = 42 - SentCmdOneNotificationDeleted = 43 - SentCmdAdminAreaManageCheckedForAvailableCategories = 44 - SentCmdAdminAreaManageLogManagerServerConnectionAdded = 45 + SentCmdInitUserSocketConnection = 1 + SentCmdUpdateConnectedUsers = 2 + SentCmdNewGroupTaskStarted = 3 + SentCmdNewGroupTaskStep = 4 + SentCmdUpdateGroupTaskStep = 5 + SentCmdUpdateGroupTask = 6 + SentCmdReloadingGroupTasks = 7 + SentCmdGroupTasksReloaded = 8 + SentCmdUpdateUserSessions = 9 + SentCmdUpdateAllUsersUserAvatar = 10 + SentCmdNewScanner = 11 + SentCmdDeleteScanner = 12 + SentCmdUpdateScannerUsedBy = 13 + SentCmdScanResult = 14 + SentCmdUpdateScannerLastUsed = 15 + SentCmdTaskLocked = 16 + SentCmdTaskUnlocked = 17 + SentCmdUserProfileUpdated = 18 + SentCmdAdminAreaNewRoleCreated = 19 + SentCmdAdminAreaRoleUpdated = 20 + SentCmdAdminAreaUpdateRoleSortingOrder = 21 + SentCmdAdminAreaRoleDeleted = 22 + SentCmdAllUsersUserRoleUpdated = 23 + SentCmdRolePermissionsUpdated = 24 + SentCmdErrorNoPermissions = 25 + SentCmdAllUsersNewUserCreated = 26 + SentCmdAllUsersUserDeleted = 27 + SentCmdAllUsersUserDeactivation = 28 + SentCmdGroupTasksCategoryGroupChanges = 29 + SentCmdNewUserApiKeyCreated = 30 + SentCmdDeletedUserApiKey = 31 + SentCmdNewApiKeyUsageCount = 32 + SentCmdInstallingPythonPackages = 33 + SentCmdInstallingPythonPackagesFailed = 34 + SentCmdInstallingPythonPackagesFinished = 35 + SentCmdInstallingGlobalPythonPackages = 36 + SentCmdInstallingGlobalPythonPackagesFailed = 37 + SentCmdInstallingGlobalPythonPackagesFinished = 38 + SentCmdUpdateUsers = 39 + SentCmdNewNotification = 41 + SentCmdAllNotificationsDeleted = 42 + SentCmdOneNotificationDeleted = 43 + SentCmdAdminAreaManageCheckedForAvailableCategories = 44 + SentCmdAdminAreaManageLogManagerServerConnectionAdded = 45 SentCmdAdminAreaManageLogManagerServerConnectionRemoved = 46 ) diff --git a/routers/router/api/v1/machines/machines.go b/routers/router/api/v1/machines/machines.go index d0f1cc5..89b3c5e 100644 --- a/routers/router/api/v1/machines/machines.go +++ b/routers/router/api/v1/machines/machines.go @@ -2,6 +2,7 @@ package machines import ( "encoding/json" + "jannex/admin-dashboard-backend/modules/config" "jannex/admin-dashboard-backend/modules/requestclient" "jannex/admin-dashboard-backend/modules/structs" "jannex/admin-dashboard-backend/modules/utils" @@ -29,12 +30,8 @@ func GetMachines(c *fiber.Ctx) error { 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=50&location="+strconv.Itoa(body.Location)+"&part_detail=true&in_stock=0") - - log.Info().Msgf("statuscode %v", statusCode) + _, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/api/stock/?search=&offset=0&limit=50&location="+strconv.Itoa(body.Location)+"&part_detail=true&in_stock=0") if err != nil { log.Error().Msgf("Invex api request error: %s", err) @@ -74,4 +71,4 @@ func contains(slice []int, item int) bool { } } return false -} \ No newline at end of file +}