From 7879f2c1c0d4965ae75484b14f72536f2484d015 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 27 Aug 2023 23:19:32 +0200 Subject: [PATCH] added system logs --- modules/equipment/equipment.go | 61 +++++++++++++++++++++++++++++++++- system_lang_log_messages.json | 52 +++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/modules/equipment/equipment.go b/modules/equipment/equipment.go index f5f566a..5bc7c5c 100644 --- a/modules/equipment/equipment.go +++ b/modules/equipment/equipment.go @@ -5,8 +5,11 @@ import ( "encoding/json" "jannex/admin-dashboard-backend/modules/config" "jannex/admin-dashboard-backend/modules/database" + "jannex/admin-dashboard-backend/modules/logger" "jannex/admin-dashboard-backend/modules/structs" + "jannex/admin-dashboard-backend/modules/utils" "os" + "strconv" "strings" "github.com/gofiber/fiber/v2" @@ -36,11 +39,30 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo 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 } @@ -71,12 +93,14 @@ func CreateEquipmentDocumentation(c *fiber.Ctx, body structs.CreateEquipmentDocu return c.SendStatus(fiber.StatusInternalServerError) } + userId := c.Locals("userId").(string) + newEquipmentDocumentation := structs.EquipmentDocumentation{ Id: uuid.New().String(), StockItemId: body.StockItemId, Type: body.Type, Title: body.Title, - CreatedByUserId: c.Locals("userId").(string), + CreatedByUserId: userId, } if err := os.Mkdir(config.Cfg.FolderPaths.PublicStatic+"/equipmentdocumentation/"+newEquipmentDocumentation.Id, os.ModePerm); err != nil { @@ -132,6 +156,19 @@ func CreateEquipmentDocumentation(c *fiber.Ctx, body structs.CreateEquipmentDocu database.DB.Create(&newEquipmentDocumentation) + logger.AddSystemLog(structs.LogMessage{ + Id: 27, + Type: utils.LogTypeInfo, + Messages: []structs.LogData{ + {Type: "userId", Value: userId}, + {Type: "equipmentDocumentationId", Value: newEquipmentDocumentation.Id}, + {Type: "stockItemId", Value: newEquipmentDocumentation.StockItemId}, + {Type: "type", Value: strconv.Itoa(int(body.Type))}, + {Type: "title", Value: body.Title}, + {Type: "description", Value: string(marshaledNotes)}, + }, + }) + return c.JSON(fiber.Map{"message": "ok"}) } @@ -154,6 +191,16 @@ func GetEquipmentDocumentations(stockItemId string, c *fiber.Ctx) error { } } + logger.AddSystemLog(structs.LogMessage{ + Id: 30, + Type: utils.LogTypeInfo, + Messages: []structs.LogData{ + {Type: "userId", Value: c.Locals("userId").(string)}, + {Type: "stockItemId", Value: stockItemId}, + {Type: "statusCode", Value: strconv.Itoa(statusCode)}, + }, + }) + return c.JSON(structs.EquipmentDocumentationResponse{ Status: statusCode, Documentations: documentations}) @@ -254,6 +301,18 @@ func EditEquipmentDocumentation(c *fiber.Ctx, body structs.EditEquipmentDocument Notes: string(marshaledNotes), }) + logger.AddSystemLog(structs.LogMessage{ + Id: 28, + Type: utils.LogTypeInfo, + Messages: []structs.LogData{ + {Type: "userId", Value: c.Locals("userId").(string)}, + {Type: "equipmentDocumentationId", Value: body.DocumentationId}, + {Type: "title", Value: body.Title}, + {Type: "type", Value: strconv.Itoa(int(body.Type))}, + {Type: "description", Value: string(marshaledNotes)}, + }, + }) + return c.JSON(fiber.Map{"message": "ok"}) } diff --git a/system_lang_log_messages.json b/system_lang_log_messages.json index b8a85e0..588d9ae 100644 --- a/system_lang_log_messages.json +++ b/system_lang_log_messages.json @@ -349,5 +349,57 @@ "message": "%userId% hat versucht einen seiner Api-Schlüssel zu verwenden, hat aber keine Berechtigung mehr dazu" } ] + }, + { + "id": 27, + "languages": [ + { + "lang": "en", + "message": "%userId% has created the equipment document %equipmentDocumentationId% for the stock item %stockItemId% with the title %title% type %type% description %description%" + }, + { + "lang": "de", + "message": "%userId% hat die Gerätedokumentation %equipmentDocumentationId% für das Lagerobjekt %stockItemId% mit der Beschreibung %description% erstellt" + } + ] + }, + { + "id": 28, + "languages": [ + { + "lang": "en", + "message": "%userId% has updated the equipment document %equipmentDocumentationId% to title %title% type %type% and description %description%" + }, + { + "lang": "de", + "message": "%userId% hat die Gerätedokumentation %equipmentDocumentationId% zu Titel %title% Typ %type% und Beschreibung %description% aktualisiert" + } + ] + }, + { + "id": 29, + "languages": [ + { + "lang": "en", + "message": "InvexApiRequestClient err: %error% statusCode: %statusCode%" + }, + { + "lang": "de", + "message": "InvexApiRequestClient err: %error% statusCode: %statusCode%" + } + ] + }, + { + "id": 30, + "languages": [ + { + "lang": "en", + "message": "%userId% has viewed equipment documentation of the stock item %stockItemId%. StatusCode: %statusCode%" + }, + { + "lang": "de", + "message": "%userId% hat die Gerätedokumentation des Lagerobjekts %stockItemId% angesehen. StatusCode: %statusCode%" + } + ] } ]