From 9d2f8e27c5abcbce4cc76a7c10750d4ab8d65e3e Mon Sep 17 00:00:00 2001 From: "garionion (aider)" Date: Fri, 28 Feb 2025 22:03:18 +0100 Subject: [PATCH] feat: Add name field to storage space and create dedicated storage page --- api/storage.go | 10 ++ database/sqlite/query.sql | 8 +- web/src/components/AppHeader.vue | 119 ++----------- web/src/components/StorageHierarchy.vue | 2 +- web/src/pages/storage.vue | 224 ++++++++++++++++++++++++ web/src/stores/storage.ts | 7 +- 6 files changed, 255 insertions(+), 115 deletions(-) create mode 100644 web/src/pages/storage.vue diff --git a/api/storage.go b/api/storage.go index 82f138c..4b28e33 100644 --- a/api/storage.go +++ b/api/storage.go @@ -43,6 +43,7 @@ func (h *StorageHandler) GetStorageSpaces(c echo.Context) error { "id": space.ID, "parent": space.Parent, "location": space.Location, + "name": space.Name, } } @@ -191,6 +192,7 @@ func (h *StorageHandler) CreateStorageSpace(c echo.Context) error { // Parse request body type StorageSpaceRequest struct { + Name string `json:"name"` Location string `json:"location"` Parent *struct { Valid bool `json:"valid"` @@ -234,10 +236,18 @@ func (h *StorageHandler) CreateStorageSpace(c echo.Context) error { location.String = req.Location } + // Convert name to sql.NullString + var name sql.NullString + if req.Name != "" { + name.Valid = true + name.String = req.Name + } + // Create storage space err := h.db.CreateStorageSpace(ctx, db.CreateStorageSpaceParams{ Parent: parent, Location: location, + Name: name, }) if err != nil { diff --git a/database/sqlite/query.sql b/database/sqlite/query.sql index dde6bff..b936f83 100644 --- a/database/sqlite/query.sql +++ b/database/sqlite/query.sql @@ -56,17 +56,17 @@ INSERT INTO pictures (user_id, storagespace_id, object_id, event_id, check_in_id VALUES (?, ?, ?, ?, ?, ?, ?, ?); -- name: GetAllStorageSpaces :many -SELECT id, parent, location FROM storagespace; +SELECT id, parent, location, name FROM storagespace; -- name: GetStorageSpaceByID :one -SELECT id, parent, location FROM storagespace WHERE id = ?; +SELECT id, parent, location, name FROM storagespace WHERE id = ?; -- name: GetChildStorageSpaces :many -SELECT id, parent, location FROM storagespace WHERE parent = ?; +SELECT id, parent, location, name FROM storagespace WHERE parent = ?; -- name: GetObjectsByStorageID :many SELECT id, storagespace_id, name, description, serialnumber, created FROM objects WHERE storagespace_id = ?; -- name: CreateStorageSpace :exec -INSERT INTO storagespace (parent, location) VALUES (?, ?); +INSERT INTO storagespace (parent, location, name) VALUES (?, ?, ?); diff --git a/web/src/components/AppHeader.vue b/web/src/components/AppHeader.vue index f3e6476..7c80e70 100644 --- a/web/src/components/AppHeader.vue +++ b/web/src/components/AppHeader.vue @@ -1,117 +1,20 @@ diff --git a/web/src/components/StorageHierarchy.vue b/web/src/components/StorageHierarchy.vue index 1c1e53c..e6d0d31 100644 --- a/web/src/components/StorageHierarchy.vue +++ b/web/src/components/StorageHierarchy.vue @@ -106,7 +106,7 @@ const StorageBox = defineComponent({
mdi-package-variant-closed - {{ storage.location || \`Storage #\${storage.id}\` }} + {{ storage.name || storage.location || \`Storage #\${storage.id}\` }} {{ objectsInCurrentStorage.length }} objects diff --git a/web/src/pages/storage.vue b/web/src/pages/storage.vue new file mode 100644 index 0000000..d14b55c --- /dev/null +++ b/web/src/pages/storage.vue @@ -0,0 +1,224 @@ + + + diff --git a/web/src/stores/storage.ts b/web/src/stores/storage.ts index 0c75f68..c91d573 100644 --- a/web/src/stores/storage.ts +++ b/web/src/stores/storage.ts @@ -8,6 +8,7 @@ interface StorageSpace { int64: number; } | null; location: string | null; + name: string | null; } interface StorageObject { @@ -43,7 +44,7 @@ export const useStorageStore = defineStore('storage', { }, actions: { - async createStorageSpace(data: { location: string; parentId: number | null }): Promise { + async createStorageSpace(data: { name: string; location: string; parentId: number | null }): Promise { this.loading = true; this.error = null; @@ -57,6 +58,7 @@ export const useStorageStore = defineStore('storage', { 'Content-Type': 'application/json', }, body: JSON.stringify({ + name: data.name, location: data.location, parent: parentData }), @@ -95,7 +97,8 @@ export const useStorageStore = defineStore('storage', { this.storageSpaces = data.map((space: any) => ({ id: space.id, parent: space.parent, - location: space.location + location: space.location, + name: space.name })); } catch (error: any) { this.error = error.message;