From f386d1213f51bdbada2746ae0978181561bb447c Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Fri, 4 Oct 2024 16:08:20 -0400 Subject: [PATCH 01/17] Update TextField.vue --- frontend/components/Form/TextField.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/components/Form/TextField.vue b/frontend/components/Form/TextField.vue index b3db86a3..d1aa2e46 100644 --- a/frontend/components/Form/TextField.vue +++ b/frontend/components/Form/TextField.vue @@ -12,7 +12,6 @@ {{ typeof value === "string" && (maxLength || minLength) ? `${value.length}/${maxLength}` : "" }} - {{ value }} Date: Sat, 5 Oct 2024 07:55:36 +0000 Subject: [PATCH 02/17] Translated using Weblate (Italian) Currently translated at 84.6% (149 of 176 strings) Translated using Weblate (Italian) Currently translated at 84.6% (149 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index f8627855..4c7ad98e 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -38,6 +38,9 @@ "location": { "create_modal": { "title": "Crea Posizione" + }, + "tree": { + "no_locations": "Nessuna posizione disponibile. Aggiungi nuove posizioni mediante il pulsante\n`<`span class=\"link-primary\"`>`Crea`<`/span`>` nella barra di navigazione." } } }, @@ -101,6 +104,9 @@ "tips_sub": "Suggerimenti per la Ricerca", "updated_at": "Aggiornato Il" }, + "labels": { + "no_results": "Nessuna etichetta trovata" + }, "languages": { "ca": "Catalano", "de": "Tedesco", @@ -121,6 +127,20 @@ "zh-MO": "Cinese (Macao)", "zh-TW": "Cinese (tradizionale)" }, + "locations": { + "no_results": "Nessuna posizione trovata" + }, + "maintenance": { + "filter": { + "both": "Entrambi", + "completed": "Completato", + "scheduled": "Pianificato" + }, + "list": { + "create_first": "Crea la tua prima voce", + "delete": "Eliminazione" + } + }, "profile": { "active": "Attivo", "change_password": "Cambia Password", From f3388b8449302b7d488ab054ff0b2167b31ab586 Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 07:56:27 +0000 Subject: [PATCH 03/17] Translated using Weblate (Italian) Currently translated at 86.3% (152 of 176 strings) Translated using Weblate (Italian) Currently translated at 86.3% (152 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index 4c7ad98e..ed9642f6 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -137,8 +137,11 @@ "scheduled": "Pianificato" }, "list": { + "complete": "CONFERMA", "create_first": "Crea la tua prima voce", - "delete": "Eliminazione" + "delete": "Elimina", + "edit": "Modifica", + "new": "Nuova" } }, "profile": { From d0a69c84465589bc676c7b1824cea480df36636e Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:00:29 +0000 Subject: [PATCH 04/17] Translated using Weblate (Italian) Currently translated at 86.9% (153 of 176 strings) Translated using Weblate (Italian) Currently translated at 86.9% (153 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index ed9642f6..11df1e8d 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -137,9 +137,10 @@ "scheduled": "Pianificato" }, "list": { - "complete": "CONFERMA", + "complete": "Conferma", "create_first": "Crea la tua prima voce", "delete": "Elimina", + "duplicate": "Duplica", "edit": "Modifica", "new": "Nuova" } From d8260b9988b84df5d716d00934c0c26b56492726 Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:02:07 +0000 Subject: [PATCH 05/17] Translated using Weblate (Italian) Currently translated at 87.5% (154 of 176 strings) Translated using Weblate (Italian) Currently translated at 87.5% (154 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index 11df1e8d..34a15c8d 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -140,9 +140,12 @@ "complete": "Conferma", "create_first": "Crea la tua prima voce", "delete": "Elimina", - "duplicate": "Duplica", + "duplicate": "Duplicare", "edit": "Modifica", "new": "Nuova" + }, + "modal": { + "completed_date": "Data Completata" } }, "profile": { From c298b651b6f0193f8974799e10c7948da39411e0 Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:03:00 +0000 Subject: [PATCH 06/17] Translated using Weblate (Italian) Currently translated at 88.6% (156 of 176 strings) Translated using Weblate (Italian) Currently translated at 88.6% (156 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index 34a15c8d..ec919792 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -145,7 +145,9 @@ "new": "Nuova" }, "modal": { - "completed_date": "Data Completata" + "completed_date": "Data di completamento", + "cost": "Costo", + "delete_confirmation": "Eliminare questa voce?" } }, "profile": { From 1ebc3d9c277a8d635d40bd8339f1ab7721381e75 Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:03:24 +0000 Subject: [PATCH 07/17] Translated using Weblate (Italian) Currently translated at 89.7% (158 of 176 strings) Translated using Weblate (Italian) Currently translated at 89.7% (158 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index ec919792..cd094d8d 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -147,7 +147,9 @@ "modal": { "completed_date": "Data di completamento", "cost": "Costo", - "delete_confirmation": "Eliminare questa voce?" + "delete_confirmation": "Sei sicuro di voler eliminare questa voce?", + "edit_action": "Aggiornare", + "edit_title": "Modifica iscrizione" } }, "profile": { From 333bca85f8071df499c4d9cad0c5ed1c86c03742 Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:03:52 +0000 Subject: [PATCH 08/17] Translated using Weblate (Italian) Currently translated at 90.3% (159 of 176 strings) Translated using Weblate (Italian) Currently translated at 90.3% (159 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index cd094d8d..da1e4410 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -149,7 +149,8 @@ "cost": "Costo", "delete_confirmation": "Sei sicuro di voler eliminare questa voce?", "edit_action": "Aggiornare", - "edit_title": "Modifica iscrizione" + "edit_title": "Modifica voce", + "entry_name": "Nome iscrizione" } }, "profile": { From ed3d106289ea161d8bef9255304cd3bc7745c682 Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:04:30 +0000 Subject: [PATCH 09/17] Translated using Weblate (Italian) Currently translated at 91.4% (161 of 176 strings) Translated using Weblate (Italian) Currently translated at 91.4% (161 of 176 strings) Translated using Weblate (Italian) Currently translated at 91.4% (161 of 176 strings) Co-authored-by: MyMemory Co-authored-by: Weblate Translation Memory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index da1e4410..eb35b6bb 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -150,7 +150,9 @@ "delete_confirmation": "Sei sicuro di voler eliminare questa voce?", "edit_action": "Aggiornare", "edit_title": "Modifica voce", - "entry_name": "Nome iscrizione" + "entry_name": "Inserisci il Nome", + "new_action": "Crea", + "new_title": "Nuova inserzione" } }, "profile": { From 733ccb51c337dda997d8177e48fa9106a6fa632e Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:05:32 +0000 Subject: [PATCH 10/17] Translated using Weblate (Italian) Currently translated at 93.1% (164 of 176 strings) Translated using Weblate (Italian) Currently translated at 93.1% (164 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index eb35b6bb..c0e5a984 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -152,8 +152,11 @@ "edit_title": "Modifica voce", "entry_name": "Inserisci il Nome", "new_action": "Crea", - "new_title": "Nuova inserzione" - } + "new_title": "Nuova Voce", + "notes": "Note", + "scheduled_date": "Data programmata" + }, + "monthly_average": "Media mese" }, "profile": { "active": "Attivo", From 738fe6db033b79ee9b54304c3cec9ccc7be1391a Mon Sep 17 00:00:00 2001 From: Weblate Date: Sat, 5 Oct 2024 08:06:01 +0000 Subject: [PATCH 11/17] Translated using Weblate (Italian) Currently translated at 96.0% (169 of 176 strings) Translated using Weblate (Italian) Currently translated at 96.0% (169 of 176 strings) Co-authored-by: MyMemory Co-authored-by: alexdelli Translate-URL: https://translate.sysadminsmedia.com/projects/homebox/frontend/it/ Translation: Homebox/Frontend --- frontend/locales/it.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/locales/it.json b/frontend/locales/it.json index c0e5a984..9309b3ce 100644 --- a/frontend/locales/it.json +++ b/frontend/locales/it.json @@ -156,7 +156,14 @@ "notes": "Note", "scheduled_date": "Data programmata" }, - "monthly_average": "Media mese" + "monthly_average": "Media mensile", + "toast": { + "failed_to_create": "Impossibile creare la voce", + "failed_to_delete": "Impossibile eliminare la voce", + "failed_to_update": "Impossibile aggiornare la voce" + }, + "total_cost": "Costo totale", + "total_entries": "Iscrizioni totali" }, "profile": { "active": "Attivo", From 908bfb530ebd55b2a4eef6df785ec198193d1774 Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Sat, 5 Oct 2024 12:10:27 -0400 Subject: [PATCH 12/17] fix: API should expect actual floats now --- backend/app/api/static/docs/docs.go | 23 ++++++++++++++--------- backend/app/api/static/docs/swagger.json | 23 ++++++++++++++--------- backend/app/api/static/docs/swagger.yaml | 14 +++++++++----- backend/internal/data/repo/repo_items.go | 4 ++-- frontend/lib/api/types/data-contracts.ts | 14 +++++++++----- 5 files changed, 48 insertions(+), 30 deletions(-) diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index b5fa2dcb..79d62ccc 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -2347,6 +2347,9 @@ const docTemplate = `{ }, "repo.ItemUpdate": { "type": "object", + "required": [ + "name" + ], "properties": { "archived": { "type": "boolean" @@ -2355,7 +2358,8 @@ const docTemplate = `{ "type": "string" }, "description": { - "type": "string" + "type": "string", + "maxLength": 1000 }, "fields": { "type": "array", @@ -2390,7 +2394,9 @@ const docTemplate = `{ "type": "string" }, "name": { - "type": "string" + "type": "string", + "maxLength": 255, + "minLength": 1 }, "notes": { "description": "Extras", @@ -2402,11 +2408,11 @@ const docTemplate = `{ "x-omitempty": true }, "purchaseFrom": { - "type": "string" + "type": "string", + "maxLength": 255 }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "purchaseTime": { "description": "Purchase", @@ -2423,15 +2429,15 @@ const docTemplate = `{ "type": "string" }, "soldPrice": { - "type": "string", - "example": "0" + "type": "number" }, "soldTime": { "description": "Sold", "type": "string" }, "soldTo": { - "type": "string" + "type": "string", + "maxLength": 255 }, "warrantyDetails": { "type": "string" @@ -2763,7 +2769,6 @@ const docTemplate = `{ "type": "string" }, "url": { - "description": "URL field is not exposed to the client", "type": "string" }, "userId": { diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 12e556ce..addf7280 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -2340,6 +2340,9 @@ }, "repo.ItemUpdate": { "type": "object", + "required": [ + "name" + ], "properties": { "archived": { "type": "boolean" @@ -2348,7 +2351,8 @@ "type": "string" }, "description": { - "type": "string" + "type": "string", + "maxLength": 1000 }, "fields": { "type": "array", @@ -2383,7 +2387,9 @@ "type": "string" }, "name": { - "type": "string" + "type": "string", + "maxLength": 255, + "minLength": 1 }, "notes": { "description": "Extras", @@ -2395,11 +2401,11 @@ "x-omitempty": true }, "purchaseFrom": { - "type": "string" + "type": "string", + "maxLength": 255 }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "purchaseTime": { "description": "Purchase", @@ -2416,15 +2422,15 @@ "type": "string" }, "soldPrice": { - "type": "string", - "example": "0" + "type": "number" }, "soldTime": { "description": "Sold", "type": "string" }, "soldTo": { - "type": "string" + "type": "string", + "maxLength": 255 }, "warrantyDetails": { "type": "string" @@ -2756,7 +2762,6 @@ "type": "string" }, "url": { - "description": "URL field is not exposed to the client", "type": "string" }, "userId": { diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index e663b6a6..a7211acb 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -264,6 +264,7 @@ definitions: assetId: type: string description: + maxLength: 1000 type: string fields: items: @@ -288,6 +289,8 @@ definitions: modelNumber: type: string name: + maxLength: 255 + minLength: 1 type: string notes: description: Extras @@ -297,10 +300,10 @@ definitions: x-nullable: true x-omitempty: true purchaseFrom: + maxLength: 255 type: string purchasePrice: - example: "0" - type: string + type: number purchaseTime: description: Purchase type: string @@ -312,17 +315,19 @@ definitions: soldNotes: type: string soldPrice: - example: "0" - type: string + type: number soldTime: description: Sold type: string soldTo: + maxLength: 255 type: string warrantyDetails: type: string warrantyExpires: type: string + required: + - name type: object repo.LabelCreate: properties: @@ -540,7 +545,6 @@ definitions: updatedAt: type: string url: - description: URL field is not exposed to the client type: string userId: type: string diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 73d72a89..d67a60a3 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -93,12 +93,12 @@ type ( // Purchase PurchaseTime types.Date `json:"purchaseTime"` PurchaseFrom string `json:"purchaseFrom" validate:"max=255"` - PurchasePrice float64 `json:"purchasePrice,string"` + PurchasePrice float64 `json:"purchasePrice"` // Sold SoldTime types.Date `json:"soldTime"` SoldTo string `json:"soldTo" validate:"max=255"` - SoldPrice float64 `json:"soldPrice,string"` + SoldPrice float64 `json:"soldPrice"` SoldNotes string `json:"soldNotes"` // Extras diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index f56ffae1..952e4f1e 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -159,6 +159,7 @@ export enum ItemType { export interface ItemUpdate { archived: boolean; assetId: string; + /** @maxLength 1000 */ description: string; fields: ItemField[]; id: string; @@ -170,23 +171,27 @@ export interface ItemUpdate { locationId: string; manufacturer: string; modelNumber: string; + /** + * @minLength 1 + * @maxLength 255 + */ name: string; /** Extras */ notes: string; parentId?: string | null; + /** @maxLength 255 */ purchaseFrom: string; - /** @example "0" */ - purchasePrice: string; + purchasePrice: number; /** Purchase */ purchaseTime: Date | string; quantity: number; /** Identifications */ serialNumber: string; soldNotes: string; - /** @example "0" */ - soldPrice: string; + soldPrice: number; /** Sold */ soldTime: Date | string; + /** @maxLength 255 */ soldTo: string; warrantyDetails: string; warrantyExpires: Date | string; @@ -323,7 +328,6 @@ export interface NotifierOut { isActive: boolean; name: string; updatedAt: Date | string; - /** URL field is not exposed to the client */ url: string; userId: string; } From 5d3698d0d84d8b9584a041bcf2959d3172d0fc09 Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Sat, 5 Oct 2024 13:31:28 -0400 Subject: [PATCH 13/17] chore: ente update things --- backend/internal/data/ent/attachment.go | 16 +++++-------- .../internal/data/ent/attachment_create.go | 4 ++-- backend/internal/data/ent/attachment_query.go | 21 ++++++++-------- .../internal/data/ent/attachment_update.go | 8 +++---- backend/internal/data/ent/authroles.go | 8 +++---- backend/internal/data/ent/authroles_query.go | 21 ++++++++-------- backend/internal/data/ent/authtokens.go | 16 +++++-------- backend/internal/data/ent/authtokens_query.go | 21 ++++++++-------- backend/internal/data/ent/document.go | 8 +++---- backend/internal/data/ent/document_create.go | 2 +- backend/internal/data/ent/document_query.go | 21 ++++++++-------- backend/internal/data/ent/document_update.go | 4 ++-- backend/internal/data/ent/ent.go | 2 +- backend/internal/data/ent/group_query.go | 21 ++++++++-------- .../internal/data/ent/groupinvitationtoken.go | 8 +++---- .../data/ent/groupinvitationtoken_query.go | 21 ++++++++-------- backend/internal/data/ent/item.go | 24 +++++++------------ backend/internal/data/ent/item_create.go | 2 +- backend/internal/data/ent/item_query.go | 21 ++++++++-------- backend/internal/data/ent/item_update.go | 4 ++-- backend/internal/data/ent/itemfield.go | 8 +++---- backend/internal/data/ent/itemfield_query.go | 21 ++++++++-------- backend/internal/data/ent/label.go | 8 +++---- backend/internal/data/ent/label_create.go | 2 +- backend/internal/data/ent/label_query.go | 21 ++++++++-------- backend/internal/data/ent/label_update.go | 4 ++-- backend/internal/data/ent/location.go | 16 +++++-------- backend/internal/data/ent/location_create.go | 2 +- backend/internal/data/ent/location_query.go | 21 ++++++++-------- backend/internal/data/ent/location_update.go | 4 ++-- backend/internal/data/ent/maintenanceentry.go | 8 +++---- .../data/ent/maintenanceentry_create.go | 2 +- .../data/ent/maintenanceentry_query.go | 21 ++++++++-------- .../data/ent/maintenanceentry_update.go | 4 ++-- backend/internal/data/ent/notifier.go | 16 +++++-------- backend/internal/data/ent/notifier_create.go | 4 ++-- backend/internal/data/ent/notifier_query.go | 21 ++++++++-------- backend/internal/data/ent/notifier_update.go | 8 +++---- backend/internal/data/ent/runtime/runtime.go | 4 ++-- backend/internal/data/ent/user.go | 8 +++---- backend/internal/data/ent/user_create.go | 2 +- backend/internal/data/ent/user_query.go | 21 ++++++++-------- backend/internal/data/ent/user_update.go | 4 ++-- 43 files changed, 230 insertions(+), 253 deletions(-) diff --git a/backend/internal/data/ent/attachment.go b/backend/internal/data/ent/attachment.go index 1a28aa6a..8568b28e 100644 --- a/backend/internal/data/ent/attachment.go +++ b/backend/internal/data/ent/attachment.go @@ -50,12 +50,10 @@ type AttachmentEdges struct { // ItemOrErr returns the Item value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e AttachmentEdges) ItemOrErr() (*Item, error) { - if e.loadedTypes[0] { - if e.Item == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: item.Label} - } + if e.Item != nil { return e.Item, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: item.Label} } return nil, &NotLoadedError{edge: "item"} } @@ -63,12 +61,10 @@ func (e AttachmentEdges) ItemOrErr() (*Item, error) { // DocumentOrErr returns the Document value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e AttachmentEdges) DocumentOrErr() (*Document, error) { - if e.loadedTypes[1] { - if e.Document == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: document.Label} - } + if e.Document != nil { return e.Document, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: document.Label} } return nil, &NotLoadedError{edge: "document"} } diff --git a/backend/internal/data/ent/attachment_create.go b/backend/internal/data/ent/attachment_create.go index 888a7141..3f154f12 100644 --- a/backend/internal/data/ent/attachment_create.go +++ b/backend/internal/data/ent/attachment_create.go @@ -191,10 +191,10 @@ func (ac *AttachmentCreate) check() error { if _, ok := ac.mutation.Primary(); !ok { return &ValidationError{Name: "primary", err: errors.New(`ent: missing required field "Attachment.primary"`)} } - if _, ok := ac.mutation.ItemID(); !ok { + if len(ac.mutation.ItemIDs()) == 0 { return &ValidationError{Name: "item", err: errors.New(`ent: missing required edge "Attachment.item"`)} } - if _, ok := ac.mutation.DocumentID(); !ok { + if len(ac.mutation.DocumentIDs()) == 0 { return &ValidationError{Name: "document", err: errors.New(`ent: missing required edge "Attachment.document"`)} } return nil diff --git a/backend/internal/data/ent/attachment_query.go b/backend/internal/data/ent/attachment_query.go index 0dc087db..70d5b428 100644 --- a/backend/internal/data/ent/attachment_query.go +++ b/backend/internal/data/ent/attachment_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -110,7 +111,7 @@ func (aq *AttachmentQuery) QueryDocument() *DocumentQuery { // First returns the first Attachment entity from the query. // Returns a *NotFoundError when no Attachment was found. func (aq *AttachmentQuery) First(ctx context.Context) (*Attachment, error) { - nodes, err := aq.Limit(1).All(setContextOp(ctx, aq.ctx, "First")) + nodes, err := aq.Limit(1).All(setContextOp(ctx, aq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (aq *AttachmentQuery) FirstX(ctx context.Context) *Attachment { // Returns a *NotFoundError when no Attachment ID was found. func (aq *AttachmentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = aq.Limit(1).IDs(setContextOp(ctx, aq.ctx, "FirstID")); err != nil { + if ids, err = aq.Limit(1).IDs(setContextOp(ctx, aq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (aq *AttachmentQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Attachment entity is found. // Returns a *NotFoundError when no Attachment entities are found. func (aq *AttachmentQuery) Only(ctx context.Context) (*Attachment, error) { - nodes, err := aq.Limit(2).All(setContextOp(ctx, aq.ctx, "Only")) + nodes, err := aq.Limit(2).All(setContextOp(ctx, aq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (aq *AttachmentQuery) OnlyX(ctx context.Context) *Attachment { // Returns a *NotFoundError when no entities are found. func (aq *AttachmentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = aq.Limit(2).IDs(setContextOp(ctx, aq.ctx, "OnlyID")); err != nil { + if ids, err = aq.Limit(2).IDs(setContextOp(ctx, aq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (aq *AttachmentQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Attachments. func (aq *AttachmentQuery) All(ctx context.Context) ([]*Attachment, error) { - ctx = setContextOp(ctx, aq.ctx, "All") + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryAll) if err := aq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (aq *AttachmentQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) if aq.ctx.Unique == nil && aq.path != nil { aq.Unique(true) } - ctx = setContextOp(ctx, aq.ctx, "IDs") + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryIDs) if err = aq.Select(attachment.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (aq *AttachmentQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (aq *AttachmentQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, aq.ctx, "Count") + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryCount) if err := aq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (aq *AttachmentQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (aq *AttachmentQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, aq.ctx, "Exist") + ctx = setContextOp(ctx, aq.ctx, ent.OpQueryExist) switch _, err := aq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -612,7 +613,7 @@ func (agb *AttachmentGroupBy) Aggregate(fns ...AggregateFunc) *AttachmentGroupBy // Scan applies the selector query and scans the result into the given value. func (agb *AttachmentGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, agb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, agb.build.ctx, ent.OpQueryGroupBy) if err := agb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (as *AttachmentSelect) Aggregate(fns ...AggregateFunc) *AttachmentSelect { // Scan applies the selector query and scans the result into the given value. func (as *AttachmentSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, as.ctx, "Select") + ctx = setContextOp(ctx, as.ctx, ent.OpQuerySelect) if err := as.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/attachment_update.go b/backend/internal/data/ent/attachment_update.go index 611747f7..2e57847d 100644 --- a/backend/internal/data/ent/attachment_update.go +++ b/backend/internal/data/ent/attachment_update.go @@ -147,10 +147,10 @@ func (au *AttachmentUpdate) check() error { return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Attachment.type": %w`, err)} } } - if _, ok := au.mutation.ItemID(); au.mutation.ItemCleared() && !ok { + if au.mutation.ItemCleared() && len(au.mutation.ItemIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Attachment.item"`) } - if _, ok := au.mutation.DocumentID(); au.mutation.DocumentCleared() && !ok { + if au.mutation.DocumentCleared() && len(au.mutation.DocumentIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Attachment.document"`) } return nil @@ -384,10 +384,10 @@ func (auo *AttachmentUpdateOne) check() error { return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Attachment.type": %w`, err)} } } - if _, ok := auo.mutation.ItemID(); auo.mutation.ItemCleared() && !ok { + if auo.mutation.ItemCleared() && len(auo.mutation.ItemIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Attachment.item"`) } - if _, ok := auo.mutation.DocumentID(); auo.mutation.DocumentCleared() && !ok { + if auo.mutation.DocumentCleared() && len(auo.mutation.DocumentIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Attachment.document"`) } return nil diff --git a/backend/internal/data/ent/authroles.go b/backend/internal/data/ent/authroles.go index e996839b..2192ef93 100644 --- a/backend/internal/data/ent/authroles.go +++ b/backend/internal/data/ent/authroles.go @@ -39,12 +39,10 @@ type AuthRolesEdges struct { // TokenOrErr returns the Token value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e AuthRolesEdges) TokenOrErr() (*AuthTokens, error) { - if e.loadedTypes[0] { - if e.Token == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: authtokens.Label} - } + if e.Token != nil { return e.Token, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: authtokens.Label} } return nil, &NotLoadedError{edge: "token"} } diff --git a/backend/internal/data/ent/authroles_query.go b/backend/internal/data/ent/authroles_query.go index c850fd1d..ef361228 100644 --- a/backend/internal/data/ent/authroles_query.go +++ b/backend/internal/data/ent/authroles_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -86,7 +87,7 @@ func (arq *AuthRolesQuery) QueryToken() *AuthTokensQuery { // First returns the first AuthRoles entity from the query. // Returns a *NotFoundError when no AuthRoles was found. func (arq *AuthRolesQuery) First(ctx context.Context) (*AuthRoles, error) { - nodes, err := arq.Limit(1).All(setContextOp(ctx, arq.ctx, "First")) + nodes, err := arq.Limit(1).All(setContextOp(ctx, arq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -109,7 +110,7 @@ func (arq *AuthRolesQuery) FirstX(ctx context.Context) *AuthRoles { // Returns a *NotFoundError when no AuthRoles ID was found. func (arq *AuthRolesQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = arq.Limit(1).IDs(setContextOp(ctx, arq.ctx, "FirstID")); err != nil { + if ids, err = arq.Limit(1).IDs(setContextOp(ctx, arq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -132,7 +133,7 @@ func (arq *AuthRolesQuery) FirstIDX(ctx context.Context) int { // Returns a *NotSingularError when more than one AuthRoles entity is found. // Returns a *NotFoundError when no AuthRoles entities are found. func (arq *AuthRolesQuery) Only(ctx context.Context) (*AuthRoles, error) { - nodes, err := arq.Limit(2).All(setContextOp(ctx, arq.ctx, "Only")) + nodes, err := arq.Limit(2).All(setContextOp(ctx, arq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -160,7 +161,7 @@ func (arq *AuthRolesQuery) OnlyX(ctx context.Context) *AuthRoles { // Returns a *NotFoundError when no entities are found. func (arq *AuthRolesQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int - if ids, err = arq.Limit(2).IDs(setContextOp(ctx, arq.ctx, "OnlyID")); err != nil { + if ids, err = arq.Limit(2).IDs(setContextOp(ctx, arq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -185,7 +186,7 @@ func (arq *AuthRolesQuery) OnlyIDX(ctx context.Context) int { // All executes the query and returns a list of AuthRolesSlice. func (arq *AuthRolesQuery) All(ctx context.Context) ([]*AuthRoles, error) { - ctx = setContextOp(ctx, arq.ctx, "All") + ctx = setContextOp(ctx, arq.ctx, ent.OpQueryAll) if err := arq.prepareQuery(ctx); err != nil { return nil, err } @@ -207,7 +208,7 @@ func (arq *AuthRolesQuery) IDs(ctx context.Context) (ids []int, err error) { if arq.ctx.Unique == nil && arq.path != nil { arq.Unique(true) } - ctx = setContextOp(ctx, arq.ctx, "IDs") + ctx = setContextOp(ctx, arq.ctx, ent.OpQueryIDs) if err = arq.Select(authroles.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -225,7 +226,7 @@ func (arq *AuthRolesQuery) IDsX(ctx context.Context) []int { // Count returns the count of the given query. func (arq *AuthRolesQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, arq.ctx, "Count") + ctx = setContextOp(ctx, arq.ctx, ent.OpQueryCount) if err := arq.prepareQuery(ctx); err != nil { return 0, err } @@ -243,7 +244,7 @@ func (arq *AuthRolesQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (arq *AuthRolesQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, arq.ctx, "Exist") + ctx = setContextOp(ctx, arq.ctx, ent.OpQueryExist) switch _, err := arq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -537,7 +538,7 @@ func (argb *AuthRolesGroupBy) Aggregate(fns ...AggregateFunc) *AuthRolesGroupBy // Scan applies the selector query and scans the result into the given value. func (argb *AuthRolesGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, argb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, argb.build.ctx, ent.OpQueryGroupBy) if err := argb.build.prepareQuery(ctx); err != nil { return err } @@ -585,7 +586,7 @@ func (ars *AuthRolesSelect) Aggregate(fns ...AggregateFunc) *AuthRolesSelect { // Scan applies the selector query and scans the result into the given value. func (ars *AuthRolesSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ars.ctx, "Select") + ctx = setContextOp(ctx, ars.ctx, ent.OpQuerySelect) if err := ars.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/authtokens.go b/backend/internal/data/ent/authtokens.go index 40fdbb47..03845acd 100644 --- a/backend/internal/data/ent/authtokens.go +++ b/backend/internal/data/ent/authtokens.go @@ -49,12 +49,10 @@ type AuthTokensEdges struct { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e AuthTokensEdges) UserOrErr() (*User, error) { - if e.loadedTypes[0] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -62,12 +60,10 @@ func (e AuthTokensEdges) UserOrErr() (*User, error) { // RolesOrErr returns the Roles value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e AuthTokensEdges) RolesOrErr() (*AuthRoles, error) { - if e.loadedTypes[1] { - if e.Roles == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: authroles.Label} - } + if e.Roles != nil { return e.Roles, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: authroles.Label} } return nil, &NotLoadedError{edge: "roles"} } diff --git a/backend/internal/data/ent/authtokens_query.go b/backend/internal/data/ent/authtokens_query.go index 2f4bd563..e645e412 100644 --- a/backend/internal/data/ent/authtokens_query.go +++ b/backend/internal/data/ent/authtokens_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -111,7 +112,7 @@ func (atq *AuthTokensQuery) QueryRoles() *AuthRolesQuery { // First returns the first AuthTokens entity from the query. // Returns a *NotFoundError when no AuthTokens was found. func (atq *AuthTokensQuery) First(ctx context.Context) (*AuthTokens, error) { - nodes, err := atq.Limit(1).All(setContextOp(ctx, atq.ctx, "First")) + nodes, err := atq.Limit(1).All(setContextOp(ctx, atq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -134,7 +135,7 @@ func (atq *AuthTokensQuery) FirstX(ctx context.Context) *AuthTokens { // Returns a *NotFoundError when no AuthTokens ID was found. func (atq *AuthTokensQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = atq.Limit(1).IDs(setContextOp(ctx, atq.ctx, "FirstID")); err != nil { + if ids, err = atq.Limit(1).IDs(setContextOp(ctx, atq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -157,7 +158,7 @@ func (atq *AuthTokensQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one AuthTokens entity is found. // Returns a *NotFoundError when no AuthTokens entities are found. func (atq *AuthTokensQuery) Only(ctx context.Context) (*AuthTokens, error) { - nodes, err := atq.Limit(2).All(setContextOp(ctx, atq.ctx, "Only")) + nodes, err := atq.Limit(2).All(setContextOp(ctx, atq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -185,7 +186,7 @@ func (atq *AuthTokensQuery) OnlyX(ctx context.Context) *AuthTokens { // Returns a *NotFoundError when no entities are found. func (atq *AuthTokensQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = atq.Limit(2).IDs(setContextOp(ctx, atq.ctx, "OnlyID")); err != nil { + if ids, err = atq.Limit(2).IDs(setContextOp(ctx, atq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -210,7 +211,7 @@ func (atq *AuthTokensQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of AuthTokensSlice. func (atq *AuthTokensQuery) All(ctx context.Context) ([]*AuthTokens, error) { - ctx = setContextOp(ctx, atq.ctx, "All") + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryAll) if err := atq.prepareQuery(ctx); err != nil { return nil, err } @@ -232,7 +233,7 @@ func (atq *AuthTokensQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error if atq.ctx.Unique == nil && atq.path != nil { atq.Unique(true) } - ctx = setContextOp(ctx, atq.ctx, "IDs") + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryIDs) if err = atq.Select(authtokens.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -250,7 +251,7 @@ func (atq *AuthTokensQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (atq *AuthTokensQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, atq.ctx, "Count") + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryCount) if err := atq.prepareQuery(ctx); err != nil { return 0, err } @@ -268,7 +269,7 @@ func (atq *AuthTokensQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (atq *AuthTokensQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, atq.ctx, "Exist") + ctx = setContextOp(ctx, atq.ctx, ent.OpQueryExist) switch _, err := atq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -609,7 +610,7 @@ func (atgb *AuthTokensGroupBy) Aggregate(fns ...AggregateFunc) *AuthTokensGroupB // Scan applies the selector query and scans the result into the given value. func (atgb *AuthTokensGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, atgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, atgb.build.ctx, ent.OpQueryGroupBy) if err := atgb.build.prepareQuery(ctx); err != nil { return err } @@ -657,7 +658,7 @@ func (ats *AuthTokensSelect) Aggregate(fns ...AggregateFunc) *AuthTokensSelect { // Scan applies the selector query and scans the result into the given value. func (ats *AuthTokensSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ats.ctx, "Select") + ctx = setContextOp(ctx, ats.ctx, ent.OpQuerySelect) if err := ats.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/document.go b/backend/internal/data/ent/document.go index 5acc1c35..9455512d 100644 --- a/backend/internal/data/ent/document.go +++ b/backend/internal/data/ent/document.go @@ -48,12 +48,10 @@ type DocumentEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e DocumentEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } diff --git a/backend/internal/data/ent/document_create.go b/backend/internal/data/ent/document_create.go index 9d666381..715a669d 100644 --- a/backend/internal/data/ent/document_create.go +++ b/backend/internal/data/ent/document_create.go @@ -176,7 +176,7 @@ func (dc *DocumentCreate) check() error { return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Document.path": %w`, err)} } } - if _, ok := dc.mutation.GroupID(); !ok { + if len(dc.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Document.group"`)} } return nil diff --git a/backend/internal/data/ent/document_query.go b/backend/internal/data/ent/document_query.go index 479eac71..b73ff46c 100644 --- a/backend/internal/data/ent/document_query.go +++ b/backend/internal/data/ent/document_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -111,7 +112,7 @@ func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery { // First returns the first Document entity from the query. // Returns a *NotFoundError when no Document was found. func (dq *DocumentQuery) First(ctx context.Context) (*Document, error) { - nodes, err := dq.Limit(1).All(setContextOp(ctx, dq.ctx, "First")) + nodes, err := dq.Limit(1).All(setContextOp(ctx, dq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -134,7 +135,7 @@ func (dq *DocumentQuery) FirstX(ctx context.Context) *Document { // Returns a *NotFoundError when no Document ID was found. func (dq *DocumentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = dq.Limit(1).IDs(setContextOp(ctx, dq.ctx, "FirstID")); err != nil { + if ids, err = dq.Limit(1).IDs(setContextOp(ctx, dq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -157,7 +158,7 @@ func (dq *DocumentQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Document entity is found. // Returns a *NotFoundError when no Document entities are found. func (dq *DocumentQuery) Only(ctx context.Context) (*Document, error) { - nodes, err := dq.Limit(2).All(setContextOp(ctx, dq.ctx, "Only")) + nodes, err := dq.Limit(2).All(setContextOp(ctx, dq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -185,7 +186,7 @@ func (dq *DocumentQuery) OnlyX(ctx context.Context) *Document { // Returns a *NotFoundError when no entities are found. func (dq *DocumentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = dq.Limit(2).IDs(setContextOp(ctx, dq.ctx, "OnlyID")); err != nil { + if ids, err = dq.Limit(2).IDs(setContextOp(ctx, dq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -210,7 +211,7 @@ func (dq *DocumentQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Documents. func (dq *DocumentQuery) All(ctx context.Context) ([]*Document, error) { - ctx = setContextOp(ctx, dq.ctx, "All") + ctx = setContextOp(ctx, dq.ctx, ent.OpQueryAll) if err := dq.prepareQuery(ctx); err != nil { return nil, err } @@ -232,7 +233,7 @@ func (dq *DocumentQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if dq.ctx.Unique == nil && dq.path != nil { dq.Unique(true) } - ctx = setContextOp(ctx, dq.ctx, "IDs") + ctx = setContextOp(ctx, dq.ctx, ent.OpQueryIDs) if err = dq.Select(document.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -250,7 +251,7 @@ func (dq *DocumentQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (dq *DocumentQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, dq.ctx, "Count") + ctx = setContextOp(ctx, dq.ctx, ent.OpQueryCount) if err := dq.prepareQuery(ctx); err != nil { return 0, err } @@ -268,7 +269,7 @@ func (dq *DocumentQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (dq *DocumentQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, dq.ctx, "Exist") + ctx = setContextOp(ctx, dq.ctx, ent.OpQueryExist) switch _, err := dq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -613,7 +614,7 @@ func (dgb *DocumentGroupBy) Aggregate(fns ...AggregateFunc) *DocumentGroupBy { // Scan applies the selector query and scans the result into the given value. func (dgb *DocumentGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, dgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, dgb.build.ctx, ent.OpQueryGroupBy) if err := dgb.build.prepareQuery(ctx); err != nil { return err } @@ -661,7 +662,7 @@ func (ds *DocumentSelect) Aggregate(fns ...AggregateFunc) *DocumentSelect { // Scan applies the selector query and scans the result into the given value. func (ds *DocumentSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ds.ctx, "Select") + ctx = setContextOp(ctx, ds.ctx, ent.OpQuerySelect) if err := ds.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/document_update.go b/backend/internal/data/ent/document_update.go index fac957b5..0cef5c97 100644 --- a/backend/internal/data/ent/document_update.go +++ b/backend/internal/data/ent/document_update.go @@ -171,7 +171,7 @@ func (du *DocumentUpdate) check() error { return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Document.path": %w`, err)} } } - if _, ok := du.mutation.GroupID(); du.mutation.GroupCleared() && !ok { + if du.mutation.GroupCleared() && len(du.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Document.group"`) } return nil @@ -445,7 +445,7 @@ func (duo *DocumentUpdateOne) check() error { return &ValidationError{Name: "path", err: fmt.Errorf(`ent: validator failed for field "Document.path": %w`, err)} } } - if _, ok := duo.mutation.GroupID(); duo.mutation.GroupCleared() && !ok { + if duo.mutation.GroupCleared() && len(duo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Document.group"`) } return nil diff --git a/backend/internal/data/ent/ent.go b/backend/internal/data/ent/ent.go index 8a0ddc4e..0532cd23 100644 --- a/backend/internal/data/ent/ent.go +++ b/backend/internal/data/ent/ent.go @@ -81,7 +81,7 @@ var ( columnCheck sql.ColumnCheck ) -// columnChecker checks if the column exists in the given table. +// checkColumn checks if the column exists in the given table. func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ diff --git a/backend/internal/data/ent/group_query.go b/backend/internal/data/ent/group_query.go index 6f8aa70f..7067c169 100644 --- a/backend/internal/data/ent/group_query.go +++ b/backend/internal/data/ent/group_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -230,7 +231,7 @@ func (gq *GroupQuery) QueryNotifiers() *NotifierQuery { // First returns the first Group entity from the query. // Returns a *NotFoundError when no Group was found. func (gq *GroupQuery) First(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, "First")) + nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -253,7 +254,7 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group { // Returns a *NotFoundError when no Group ID was found. func (gq *GroupQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, "FirstID")); err != nil { + if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -276,7 +277,7 @@ func (gq *GroupQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Group entity is found. // Returns a *NotFoundError when no Group entities are found. func (gq *GroupQuery) Only(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, "Only")) + nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -304,7 +305,7 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group { // Returns a *NotFoundError when no entities are found. func (gq *GroupQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, "OnlyID")); err != nil { + if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -329,7 +330,7 @@ func (gq *GroupQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Groups. func (gq *GroupQuery) All(ctx context.Context) ([]*Group, error) { - ctx = setContextOp(ctx, gq.ctx, "All") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryAll) if err := gq.prepareQuery(ctx); err != nil { return nil, err } @@ -351,7 +352,7 @@ func (gq *GroupQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if gq.ctx.Unique == nil && gq.path != nil { gq.Unique(true) } - ctx = setContextOp(ctx, gq.ctx, "IDs") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryIDs) if err = gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -369,7 +370,7 @@ func (gq *GroupQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gq *GroupQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gq.ctx, "Count") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryCount) if err := gq.prepareQuery(ctx); err != nil { return 0, err } @@ -387,7 +388,7 @@ func (gq *GroupQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gq *GroupQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gq.ctx, "Exist") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryExist) switch _, err := gq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -981,7 +982,7 @@ func (ggb *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy { // Scan applies the selector query and scans the result into the given value. func (ggb *GroupGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ggb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ggb.build.ctx, ent.OpQueryGroupBy) if err := ggb.build.prepareQuery(ctx); err != nil { return err } @@ -1029,7 +1030,7 @@ func (gs *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect { // Scan applies the selector query and scans the result into the given value. func (gs *GroupSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gs.ctx, "Select") + ctx = setContextOp(ctx, gs.ctx, ent.OpQuerySelect) if err := gs.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/groupinvitationtoken.go b/backend/internal/data/ent/groupinvitationtoken.go index 239614a9..4e5d3d5c 100644 --- a/backend/internal/data/ent/groupinvitationtoken.go +++ b/backend/internal/data/ent/groupinvitationtoken.go @@ -48,12 +48,10 @@ type GroupInvitationTokenEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e GroupInvitationTokenEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } diff --git a/backend/internal/data/ent/groupinvitationtoken_query.go b/backend/internal/data/ent/groupinvitationtoken_query.go index bebf8533..dfd78746 100644 --- a/backend/internal/data/ent/groupinvitationtoken_query.go +++ b/backend/internal/data/ent/groupinvitationtoken_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -86,7 +87,7 @@ func (gitq *GroupInvitationTokenQuery) QueryGroup() *GroupQuery { // First returns the first GroupInvitationToken entity from the query. // Returns a *NotFoundError when no GroupInvitationToken was found. func (gitq *GroupInvitationTokenQuery) First(ctx context.Context) (*GroupInvitationToken, error) { - nodes, err := gitq.Limit(1).All(setContextOp(ctx, gitq.ctx, "First")) + nodes, err := gitq.Limit(1).All(setContextOp(ctx, gitq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -109,7 +110,7 @@ func (gitq *GroupInvitationTokenQuery) FirstX(ctx context.Context) *GroupInvitat // Returns a *NotFoundError when no GroupInvitationToken ID was found. func (gitq *GroupInvitationTokenQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gitq.Limit(1).IDs(setContextOp(ctx, gitq.ctx, "FirstID")); err != nil { + if ids, err = gitq.Limit(1).IDs(setContextOp(ctx, gitq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -132,7 +133,7 @@ func (gitq *GroupInvitationTokenQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one GroupInvitationToken entity is found. // Returns a *NotFoundError when no GroupInvitationToken entities are found. func (gitq *GroupInvitationTokenQuery) Only(ctx context.Context) (*GroupInvitationToken, error) { - nodes, err := gitq.Limit(2).All(setContextOp(ctx, gitq.ctx, "Only")) + nodes, err := gitq.Limit(2).All(setContextOp(ctx, gitq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -160,7 +161,7 @@ func (gitq *GroupInvitationTokenQuery) OnlyX(ctx context.Context) *GroupInvitati // Returns a *NotFoundError when no entities are found. func (gitq *GroupInvitationTokenQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gitq.Limit(2).IDs(setContextOp(ctx, gitq.ctx, "OnlyID")); err != nil { + if ids, err = gitq.Limit(2).IDs(setContextOp(ctx, gitq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -185,7 +186,7 @@ func (gitq *GroupInvitationTokenQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of GroupInvitationTokens. func (gitq *GroupInvitationTokenQuery) All(ctx context.Context) ([]*GroupInvitationToken, error) { - ctx = setContextOp(ctx, gitq.ctx, "All") + ctx = setContextOp(ctx, gitq.ctx, ent.OpQueryAll) if err := gitq.prepareQuery(ctx); err != nil { return nil, err } @@ -207,7 +208,7 @@ func (gitq *GroupInvitationTokenQuery) IDs(ctx context.Context) (ids []uuid.UUID if gitq.ctx.Unique == nil && gitq.path != nil { gitq.Unique(true) } - ctx = setContextOp(ctx, gitq.ctx, "IDs") + ctx = setContextOp(ctx, gitq.ctx, ent.OpQueryIDs) if err = gitq.Select(groupinvitationtoken.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -225,7 +226,7 @@ func (gitq *GroupInvitationTokenQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gitq *GroupInvitationTokenQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gitq.ctx, "Count") + ctx = setContextOp(ctx, gitq.ctx, ent.OpQueryCount) if err := gitq.prepareQuery(ctx); err != nil { return 0, err } @@ -243,7 +244,7 @@ func (gitq *GroupInvitationTokenQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gitq *GroupInvitationTokenQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gitq.ctx, "Exist") + ctx = setContextOp(ctx, gitq.ctx, ent.OpQueryExist) switch _, err := gitq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -537,7 +538,7 @@ func (gitgb *GroupInvitationTokenGroupBy) Aggregate(fns ...AggregateFunc) *Group // Scan applies the selector query and scans the result into the given value. func (gitgb *GroupInvitationTokenGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gitgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, gitgb.build.ctx, ent.OpQueryGroupBy) if err := gitgb.build.prepareQuery(ctx); err != nil { return err } @@ -585,7 +586,7 @@ func (gits *GroupInvitationTokenSelect) Aggregate(fns ...AggregateFunc) *GroupIn // Scan applies the selector query and scans the result into the given value. func (gits *GroupInvitationTokenSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gits.ctx, "Select") + ctx = setContextOp(ctx, gits.ctx, ent.OpQuerySelect) if err := gits.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/item.go b/backend/internal/data/ent/item.go index 8ce24934..682616b0 100644 --- a/backend/internal/data/ent/item.go +++ b/backend/internal/data/ent/item.go @@ -101,12 +101,10 @@ type ItemEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e ItemEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } @@ -114,12 +112,10 @@ func (e ItemEdges) GroupOrErr() (*Group, error) { // ParentOrErr returns the Parent value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e ItemEdges) ParentOrErr() (*Item, error) { - if e.loadedTypes[1] { - if e.Parent == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: item.Label} - } + if e.Parent != nil { return e.Parent, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: item.Label} } return nil, &NotLoadedError{edge: "parent"} } @@ -145,12 +141,10 @@ func (e ItemEdges) LabelOrErr() ([]*Label, error) { // LocationOrErr returns the Location value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e ItemEdges) LocationOrErr() (*Location, error) { - if e.loadedTypes[4] { - if e.Location == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: location.Label} - } + if e.Location != nil { return e.Location, nil + } else if e.loadedTypes[4] { + return nil, &NotFoundError{label: location.Label} } return nil, &NotLoadedError{edge: "location"} } diff --git a/backend/internal/data/ent/item_create.go b/backend/internal/data/ent/item_create.go index 0bdc2c79..97ed01ea 100644 --- a/backend/internal/data/ent/item_create.go +++ b/backend/internal/data/ent/item_create.go @@ -633,7 +633,7 @@ func (ic *ItemCreate) check() error { return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} } } - if _, ok := ic.mutation.GroupID(); !ok { + if len(ic.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Item.group"`)} } return nil diff --git a/backend/internal/data/ent/item_query.go b/backend/internal/data/ent/item_query.go index 15028b84..d83ddb89 100644 --- a/backend/internal/data/ent/item_query.go +++ b/backend/internal/data/ent/item_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -253,7 +254,7 @@ func (iq *ItemQuery) QueryAttachments() *AttachmentQuery { // First returns the first Item entity from the query. // Returns a *NotFoundError when no Item was found. func (iq *ItemQuery) First(ctx context.Context) (*Item, error) { - nodes, err := iq.Limit(1).All(setContextOp(ctx, iq.ctx, "First")) + nodes, err := iq.Limit(1).All(setContextOp(ctx, iq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -276,7 +277,7 @@ func (iq *ItemQuery) FirstX(ctx context.Context) *Item { // Returns a *NotFoundError when no Item ID was found. func (iq *ItemQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = iq.Limit(1).IDs(setContextOp(ctx, iq.ctx, "FirstID")); err != nil { + if ids, err = iq.Limit(1).IDs(setContextOp(ctx, iq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -299,7 +300,7 @@ func (iq *ItemQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Item entity is found. // Returns a *NotFoundError when no Item entities are found. func (iq *ItemQuery) Only(ctx context.Context) (*Item, error) { - nodes, err := iq.Limit(2).All(setContextOp(ctx, iq.ctx, "Only")) + nodes, err := iq.Limit(2).All(setContextOp(ctx, iq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -327,7 +328,7 @@ func (iq *ItemQuery) OnlyX(ctx context.Context) *Item { // Returns a *NotFoundError when no entities are found. func (iq *ItemQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = iq.Limit(2).IDs(setContextOp(ctx, iq.ctx, "OnlyID")); err != nil { + if ids, err = iq.Limit(2).IDs(setContextOp(ctx, iq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -352,7 +353,7 @@ func (iq *ItemQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Items. func (iq *ItemQuery) All(ctx context.Context) ([]*Item, error) { - ctx = setContextOp(ctx, iq.ctx, "All") + ctx = setContextOp(ctx, iq.ctx, ent.OpQueryAll) if err := iq.prepareQuery(ctx); err != nil { return nil, err } @@ -374,7 +375,7 @@ func (iq *ItemQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if iq.ctx.Unique == nil && iq.path != nil { iq.Unique(true) } - ctx = setContextOp(ctx, iq.ctx, "IDs") + ctx = setContextOp(ctx, iq.ctx, ent.OpQueryIDs) if err = iq.Select(item.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -392,7 +393,7 @@ func (iq *ItemQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (iq *ItemQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, iq.ctx, "Count") + ctx = setContextOp(ctx, iq.ctx, ent.OpQueryCount) if err := iq.prepareQuery(ctx); err != nil { return 0, err } @@ -410,7 +411,7 @@ func (iq *ItemQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (iq *ItemQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, iq.ctx, "Exist") + ctx = setContextOp(ctx, iq.ctx, ent.OpQueryExist) switch _, err := iq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -1090,7 +1091,7 @@ func (igb *ItemGroupBy) Aggregate(fns ...AggregateFunc) *ItemGroupBy { // Scan applies the selector query and scans the result into the given value. func (igb *ItemGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, igb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, igb.build.ctx, ent.OpQueryGroupBy) if err := igb.build.prepareQuery(ctx); err != nil { return err } @@ -1138,7 +1139,7 @@ func (is *ItemSelect) Aggregate(fns ...AggregateFunc) *ItemSelect { // Scan applies the selector query and scans the result into the given value. func (is *ItemSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, is.ctx, "Select") + ctx = setContextOp(ctx, is.ctx, ent.OpQuerySelect) if err := is.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/item_update.go b/backend/internal/data/ent/item_update.go index 57616ab4..16c3464b 100644 --- a/backend/internal/data/ent/item_update.go +++ b/backend/internal/data/ent/item_update.go @@ -776,7 +776,7 @@ func (iu *ItemUpdate) check() error { return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} } } - if _, ok := iu.mutation.GroupID(); iu.mutation.GroupCleared() && !ok { + if iu.mutation.GroupCleared() && len(iu.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Item.group"`) } return nil @@ -1997,7 +1997,7 @@ func (iuo *ItemUpdateOne) check() error { return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} } } - if _, ok := iuo.mutation.GroupID(); iuo.mutation.GroupCleared() && !ok { + if iuo.mutation.GroupCleared() && len(iuo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Item.group"`) } return nil diff --git a/backend/internal/data/ent/itemfield.go b/backend/internal/data/ent/itemfield.go index 0c1690cc..f29dcc0d 100644 --- a/backend/internal/data/ent/itemfield.go +++ b/backend/internal/data/ent/itemfield.go @@ -56,12 +56,10 @@ type ItemFieldEdges struct { // ItemOrErr returns the Item value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e ItemFieldEdges) ItemOrErr() (*Item, error) { - if e.loadedTypes[0] { - if e.Item == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: item.Label} - } + if e.Item != nil { return e.Item, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: item.Label} } return nil, &NotLoadedError{edge: "item"} } diff --git a/backend/internal/data/ent/itemfield_query.go b/backend/internal/data/ent/itemfield_query.go index 3c6072a8..a11a1840 100644 --- a/backend/internal/data/ent/itemfield_query.go +++ b/backend/internal/data/ent/itemfield_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -86,7 +87,7 @@ func (ifq *ItemFieldQuery) QueryItem() *ItemQuery { // First returns the first ItemField entity from the query. // Returns a *NotFoundError when no ItemField was found. func (ifq *ItemFieldQuery) First(ctx context.Context) (*ItemField, error) { - nodes, err := ifq.Limit(1).All(setContextOp(ctx, ifq.ctx, "First")) + nodes, err := ifq.Limit(1).All(setContextOp(ctx, ifq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -109,7 +110,7 @@ func (ifq *ItemFieldQuery) FirstX(ctx context.Context) *ItemField { // Returns a *NotFoundError when no ItemField ID was found. func (ifq *ItemFieldQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = ifq.Limit(1).IDs(setContextOp(ctx, ifq.ctx, "FirstID")); err != nil { + if ids, err = ifq.Limit(1).IDs(setContextOp(ctx, ifq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -132,7 +133,7 @@ func (ifq *ItemFieldQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one ItemField entity is found. // Returns a *NotFoundError when no ItemField entities are found. func (ifq *ItemFieldQuery) Only(ctx context.Context) (*ItemField, error) { - nodes, err := ifq.Limit(2).All(setContextOp(ctx, ifq.ctx, "Only")) + nodes, err := ifq.Limit(2).All(setContextOp(ctx, ifq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -160,7 +161,7 @@ func (ifq *ItemFieldQuery) OnlyX(ctx context.Context) *ItemField { // Returns a *NotFoundError when no entities are found. func (ifq *ItemFieldQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = ifq.Limit(2).IDs(setContextOp(ctx, ifq.ctx, "OnlyID")); err != nil { + if ids, err = ifq.Limit(2).IDs(setContextOp(ctx, ifq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -185,7 +186,7 @@ func (ifq *ItemFieldQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of ItemFields. func (ifq *ItemFieldQuery) All(ctx context.Context) ([]*ItemField, error) { - ctx = setContextOp(ctx, ifq.ctx, "All") + ctx = setContextOp(ctx, ifq.ctx, ent.OpQueryAll) if err := ifq.prepareQuery(ctx); err != nil { return nil, err } @@ -207,7 +208,7 @@ func (ifq *ItemFieldQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) if ifq.ctx.Unique == nil && ifq.path != nil { ifq.Unique(true) } - ctx = setContextOp(ctx, ifq.ctx, "IDs") + ctx = setContextOp(ctx, ifq.ctx, ent.OpQueryIDs) if err = ifq.Select(itemfield.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -225,7 +226,7 @@ func (ifq *ItemFieldQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (ifq *ItemFieldQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, ifq.ctx, "Count") + ctx = setContextOp(ctx, ifq.ctx, ent.OpQueryCount) if err := ifq.prepareQuery(ctx); err != nil { return 0, err } @@ -243,7 +244,7 @@ func (ifq *ItemFieldQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (ifq *ItemFieldQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, ifq.ctx, "Exist") + ctx = setContextOp(ctx, ifq.ctx, ent.OpQueryExist) switch _, err := ifq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -537,7 +538,7 @@ func (ifgb *ItemFieldGroupBy) Aggregate(fns ...AggregateFunc) *ItemFieldGroupBy // Scan applies the selector query and scans the result into the given value. func (ifgb *ItemFieldGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ifgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ifgb.build.ctx, ent.OpQueryGroupBy) if err := ifgb.build.prepareQuery(ctx); err != nil { return err } @@ -585,7 +586,7 @@ func (ifs *ItemFieldSelect) Aggregate(fns ...AggregateFunc) *ItemFieldSelect { // Scan applies the selector query and scans the result into the given value. func (ifs *ItemFieldSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ifs.ctx, "Select") + ctx = setContextOp(ctx, ifs.ctx, ent.OpQuerySelect) if err := ifs.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/label.go b/backend/internal/data/ent/label.go index 8af41d34..e2a82a56 100644 --- a/backend/internal/data/ent/label.go +++ b/backend/internal/data/ent/label.go @@ -50,12 +50,10 @@ type LabelEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e LabelEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } diff --git a/backend/internal/data/ent/label_create.go b/backend/internal/data/ent/label_create.go index 42dab66b..7434b815 100644 --- a/backend/internal/data/ent/label_create.go +++ b/backend/internal/data/ent/label_create.go @@ -200,7 +200,7 @@ func (lc *LabelCreate) check() error { return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Label.color": %w`, err)} } } - if _, ok := lc.mutation.GroupID(); !ok { + if len(lc.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Label.group"`)} } return nil diff --git a/backend/internal/data/ent/label_query.go b/backend/internal/data/ent/label_query.go index e0964fbb..b03c9bfc 100644 --- a/backend/internal/data/ent/label_query.go +++ b/backend/internal/data/ent/label_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -111,7 +112,7 @@ func (lq *LabelQuery) QueryItems() *ItemQuery { // First returns the first Label entity from the query. // Returns a *NotFoundError when no Label was found. func (lq *LabelQuery) First(ctx context.Context) (*Label, error) { - nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, "First")) + nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -134,7 +135,7 @@ func (lq *LabelQuery) FirstX(ctx context.Context) *Label { // Returns a *NotFoundError when no Label ID was found. func (lq *LabelQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, "FirstID")); err != nil { + if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -157,7 +158,7 @@ func (lq *LabelQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Label entity is found. // Returns a *NotFoundError when no Label entities are found. func (lq *LabelQuery) Only(ctx context.Context) (*Label, error) { - nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, "Only")) + nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -185,7 +186,7 @@ func (lq *LabelQuery) OnlyX(ctx context.Context) *Label { // Returns a *NotFoundError when no entities are found. func (lq *LabelQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, "OnlyID")); err != nil { + if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -210,7 +211,7 @@ func (lq *LabelQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Labels. func (lq *LabelQuery) All(ctx context.Context) ([]*Label, error) { - ctx = setContextOp(ctx, lq.ctx, "All") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryAll) if err := lq.prepareQuery(ctx); err != nil { return nil, err } @@ -232,7 +233,7 @@ func (lq *LabelQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if lq.ctx.Unique == nil && lq.path != nil { lq.Unique(true) } - ctx = setContextOp(ctx, lq.ctx, "IDs") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryIDs) if err = lq.Select(label.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -250,7 +251,7 @@ func (lq *LabelQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (lq *LabelQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, lq.ctx, "Count") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryCount) if err := lq.prepareQuery(ctx); err != nil { return 0, err } @@ -268,7 +269,7 @@ func (lq *LabelQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (lq *LabelQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, lq.ctx, "Exist") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryExist) switch _, err := lq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -643,7 +644,7 @@ func (lgb *LabelGroupBy) Aggregate(fns ...AggregateFunc) *LabelGroupBy { // Scan applies the selector query and scans the result into the given value. func (lgb *LabelGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, lgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, lgb.build.ctx, ent.OpQueryGroupBy) if err := lgb.build.prepareQuery(ctx); err != nil { return err } @@ -691,7 +692,7 @@ func (ls *LabelSelect) Aggregate(fns ...AggregateFunc) *LabelSelect { // Scan applies the selector query and scans the result into the given value. func (ls *LabelSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ls.ctx, "Select") + ctx = setContextOp(ctx, ls.ctx, ent.OpQuerySelect) if err := ls.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/label_update.go b/backend/internal/data/ent/label_update.go index 10475eea..1827d392 100644 --- a/backend/internal/data/ent/label_update.go +++ b/backend/internal/data/ent/label_update.go @@ -202,7 +202,7 @@ func (lu *LabelUpdate) check() error { return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Label.color": %w`, err)} } } - if _, ok := lu.mutation.GroupID(); lu.mutation.GroupCleared() && !ok { + if lu.mutation.GroupCleared() && len(lu.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Label.group"`) } return nil @@ -516,7 +516,7 @@ func (luo *LabelUpdateOne) check() error { return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Label.color": %w`, err)} } } - if _, ok := luo.mutation.GroupID(); luo.mutation.GroupCleared() && !ok { + if luo.mutation.GroupCleared() && len(luo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Label.group"`) } return nil diff --git a/backend/internal/data/ent/location.go b/backend/internal/data/ent/location.go index 784b4056..ce52b2bb 100644 --- a/backend/internal/data/ent/location.go +++ b/backend/internal/data/ent/location.go @@ -53,12 +53,10 @@ type LocationEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e LocationEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } @@ -66,12 +64,10 @@ func (e LocationEdges) GroupOrErr() (*Group, error) { // ParentOrErr returns the Parent value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e LocationEdges) ParentOrErr() (*Location, error) { - if e.loadedTypes[1] { - if e.Parent == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: location.Label} - } + if e.Parent != nil { return e.Parent, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: location.Label} } return nil, &NotLoadedError{edge: "parent"} } diff --git a/backend/internal/data/ent/location_create.go b/backend/internal/data/ent/location_create.go index 675de7a1..7a7cdbda 100644 --- a/backend/internal/data/ent/location_create.go +++ b/backend/internal/data/ent/location_create.go @@ -215,7 +215,7 @@ func (lc *LocationCreate) check() error { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)} } } - if _, ok := lc.mutation.GroupID(); !ok { + if len(lc.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Location.group"`)} } return nil diff --git a/backend/internal/data/ent/location_query.go b/backend/internal/data/ent/location_query.go index 8c7c3e98..42dae357 100644 --- a/backend/internal/data/ent/location_query.go +++ b/backend/internal/data/ent/location_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -157,7 +158,7 @@ func (lq *LocationQuery) QueryItems() *ItemQuery { // First returns the first Location entity from the query. // Returns a *NotFoundError when no Location was found. func (lq *LocationQuery) First(ctx context.Context) (*Location, error) { - nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, "First")) + nodes, err := lq.Limit(1).All(setContextOp(ctx, lq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -180,7 +181,7 @@ func (lq *LocationQuery) FirstX(ctx context.Context) *Location { // Returns a *NotFoundError when no Location ID was found. func (lq *LocationQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, "FirstID")); err != nil { + if ids, err = lq.Limit(1).IDs(setContextOp(ctx, lq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -203,7 +204,7 @@ func (lq *LocationQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Location entity is found. // Returns a *NotFoundError when no Location entities are found. func (lq *LocationQuery) Only(ctx context.Context) (*Location, error) { - nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, "Only")) + nodes, err := lq.Limit(2).All(setContextOp(ctx, lq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -231,7 +232,7 @@ func (lq *LocationQuery) OnlyX(ctx context.Context) *Location { // Returns a *NotFoundError when no entities are found. func (lq *LocationQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, "OnlyID")); err != nil { + if ids, err = lq.Limit(2).IDs(setContextOp(ctx, lq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -256,7 +257,7 @@ func (lq *LocationQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Locations. func (lq *LocationQuery) All(ctx context.Context) ([]*Location, error) { - ctx = setContextOp(ctx, lq.ctx, "All") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryAll) if err := lq.prepareQuery(ctx); err != nil { return nil, err } @@ -278,7 +279,7 @@ func (lq *LocationQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if lq.ctx.Unique == nil && lq.path != nil { lq.Unique(true) } - ctx = setContextOp(ctx, lq.ctx, "IDs") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryIDs) if err = lq.Select(location.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -296,7 +297,7 @@ func (lq *LocationQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (lq *LocationQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, lq.ctx, "Count") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryCount) if err := lq.prepareQuery(ctx); err != nil { return 0, err } @@ -314,7 +315,7 @@ func (lq *LocationQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (lq *LocationQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, lq.ctx, "Exist") + ctx = setContextOp(ctx, lq.ctx, ent.OpQueryExist) switch _, err := lq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -761,7 +762,7 @@ func (lgb *LocationGroupBy) Aggregate(fns ...AggregateFunc) *LocationGroupBy { // Scan applies the selector query and scans the result into the given value. func (lgb *LocationGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, lgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, lgb.build.ctx, ent.OpQueryGroupBy) if err := lgb.build.prepareQuery(ctx); err != nil { return err } @@ -809,7 +810,7 @@ func (ls *LocationSelect) Aggregate(fns ...AggregateFunc) *LocationSelect { // Scan applies the selector query and scans the result into the given value. func (ls *LocationSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ls.ctx, "Select") + ctx = setContextOp(ctx, ls.ctx, ent.OpQuerySelect) if err := ls.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/location_update.go b/backend/internal/data/ent/location_update.go index a937d4ad..f89d50b3 100644 --- a/backend/internal/data/ent/location_update.go +++ b/backend/internal/data/ent/location_update.go @@ -238,7 +238,7 @@ func (lu *LocationUpdate) check() error { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)} } } - if _, ok := lu.mutation.GroupID(); lu.mutation.GroupCleared() && !ok { + if lu.mutation.GroupCleared() && len(lu.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Location.group"`) } return nil @@ -656,7 +656,7 @@ func (luo *LocationUpdateOne) check() error { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Location.description": %w`, err)} } } - if _, ok := luo.mutation.GroupID(); luo.mutation.GroupCleared() && !ok { + if luo.mutation.GroupCleared() && len(luo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Location.group"`) } return nil diff --git a/backend/internal/data/ent/maintenanceentry.go b/backend/internal/data/ent/maintenanceentry.go index 106ec318..c5417d21 100644 --- a/backend/internal/data/ent/maintenanceentry.go +++ b/backend/internal/data/ent/maintenanceentry.go @@ -53,12 +53,10 @@ type MaintenanceEntryEdges struct { // ItemOrErr returns the Item value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e MaintenanceEntryEdges) ItemOrErr() (*Item, error) { - if e.loadedTypes[0] { - if e.Item == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: item.Label} - } + if e.Item != nil { return e.Item, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: item.Label} } return nil, &NotLoadedError{edge: "item"} } diff --git a/backend/internal/data/ent/maintenanceentry_create.go b/backend/internal/data/ent/maintenanceentry_create.go index ceeeb2b3..b8df2734 100644 --- a/backend/internal/data/ent/maintenanceentry_create.go +++ b/backend/internal/data/ent/maintenanceentry_create.go @@ -217,7 +217,7 @@ func (mec *MaintenanceEntryCreate) check() error { if _, ok := mec.mutation.Cost(); !ok { return &ValidationError{Name: "cost", err: errors.New(`ent: missing required field "MaintenanceEntry.cost"`)} } - if _, ok := mec.mutation.ItemID(); !ok { + if len(mec.mutation.ItemIDs()) == 0 { return &ValidationError{Name: "item", err: errors.New(`ent: missing required edge "MaintenanceEntry.item"`)} } return nil diff --git a/backend/internal/data/ent/maintenanceentry_query.go b/backend/internal/data/ent/maintenanceentry_query.go index 3c68c1ab..1879e6b7 100644 --- a/backend/internal/data/ent/maintenanceentry_query.go +++ b/backend/internal/data/ent/maintenanceentry_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -85,7 +86,7 @@ func (meq *MaintenanceEntryQuery) QueryItem() *ItemQuery { // First returns the first MaintenanceEntry entity from the query. // Returns a *NotFoundError when no MaintenanceEntry was found. func (meq *MaintenanceEntryQuery) First(ctx context.Context) (*MaintenanceEntry, error) { - nodes, err := meq.Limit(1).All(setContextOp(ctx, meq.ctx, "First")) + nodes, err := meq.Limit(1).All(setContextOp(ctx, meq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -108,7 +109,7 @@ func (meq *MaintenanceEntryQuery) FirstX(ctx context.Context) *MaintenanceEntry // Returns a *NotFoundError when no MaintenanceEntry ID was found. func (meq *MaintenanceEntryQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = meq.Limit(1).IDs(setContextOp(ctx, meq.ctx, "FirstID")); err != nil { + if ids, err = meq.Limit(1).IDs(setContextOp(ctx, meq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -131,7 +132,7 @@ func (meq *MaintenanceEntryQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one MaintenanceEntry entity is found. // Returns a *NotFoundError when no MaintenanceEntry entities are found. func (meq *MaintenanceEntryQuery) Only(ctx context.Context) (*MaintenanceEntry, error) { - nodes, err := meq.Limit(2).All(setContextOp(ctx, meq.ctx, "Only")) + nodes, err := meq.Limit(2).All(setContextOp(ctx, meq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -159,7 +160,7 @@ func (meq *MaintenanceEntryQuery) OnlyX(ctx context.Context) *MaintenanceEntry { // Returns a *NotFoundError when no entities are found. func (meq *MaintenanceEntryQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = meq.Limit(2).IDs(setContextOp(ctx, meq.ctx, "OnlyID")); err != nil { + if ids, err = meq.Limit(2).IDs(setContextOp(ctx, meq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -184,7 +185,7 @@ func (meq *MaintenanceEntryQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of MaintenanceEntries. func (meq *MaintenanceEntryQuery) All(ctx context.Context) ([]*MaintenanceEntry, error) { - ctx = setContextOp(ctx, meq.ctx, "All") + ctx = setContextOp(ctx, meq.ctx, ent.OpQueryAll) if err := meq.prepareQuery(ctx); err != nil { return nil, err } @@ -206,7 +207,7 @@ func (meq *MaintenanceEntryQuery) IDs(ctx context.Context) (ids []uuid.UUID, err if meq.ctx.Unique == nil && meq.path != nil { meq.Unique(true) } - ctx = setContextOp(ctx, meq.ctx, "IDs") + ctx = setContextOp(ctx, meq.ctx, ent.OpQueryIDs) if err = meq.Select(maintenanceentry.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -224,7 +225,7 @@ func (meq *MaintenanceEntryQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (meq *MaintenanceEntryQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, meq.ctx, "Count") + ctx = setContextOp(ctx, meq.ctx, ent.OpQueryCount) if err := meq.prepareQuery(ctx); err != nil { return 0, err } @@ -242,7 +243,7 @@ func (meq *MaintenanceEntryQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (meq *MaintenanceEntryQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, meq.ctx, "Exist") + ctx = setContextOp(ctx, meq.ctx, ent.OpQueryExist) switch _, err := meq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -529,7 +530,7 @@ func (megb *MaintenanceEntryGroupBy) Aggregate(fns ...AggregateFunc) *Maintenanc // Scan applies the selector query and scans the result into the given value. func (megb *MaintenanceEntryGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, megb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, megb.build.ctx, ent.OpQueryGroupBy) if err := megb.build.prepareQuery(ctx); err != nil { return err } @@ -577,7 +578,7 @@ func (mes *MaintenanceEntrySelect) Aggregate(fns ...AggregateFunc) *MaintenanceE // Scan applies the selector query and scans the result into the given value. func (mes *MaintenanceEntrySelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, mes.ctx, "Select") + ctx = setContextOp(ctx, mes.ctx, ent.OpQuerySelect) if err := mes.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/maintenanceentry_update.go b/backend/internal/data/ent/maintenanceentry_update.go index 5aeb6e0d..813cd189 100644 --- a/backend/internal/data/ent/maintenanceentry_update.go +++ b/backend/internal/data/ent/maintenanceentry_update.go @@ -209,7 +209,7 @@ func (meu *MaintenanceEntryUpdate) check() error { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)} } } - if _, ok := meu.mutation.ItemID(); meu.mutation.ItemCleared() && !ok { + if meu.mutation.ItemCleared() && len(meu.mutation.ItemIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`) } return nil @@ -498,7 +498,7 @@ func (meuo *MaintenanceEntryUpdateOne) check() error { return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)} } } - if _, ok := meuo.mutation.ItemID(); meuo.mutation.ItemCleared() && !ok { + if meuo.mutation.ItemCleared() && len(meuo.mutation.ItemIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`) } return nil diff --git a/backend/internal/data/ent/notifier.go b/backend/internal/data/ent/notifier.go index 55b062b9..03b4920e 100644 --- a/backend/internal/data/ent/notifier.go +++ b/backend/internal/data/ent/notifier.go @@ -54,12 +54,10 @@ type NotifierEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e NotifierEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } @@ -67,12 +65,10 @@ func (e NotifierEdges) GroupOrErr() (*Group, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e NotifierEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } diff --git a/backend/internal/data/ent/notifier_create.go b/backend/internal/data/ent/notifier_create.go index 20debb82..03e72335 100644 --- a/backend/internal/data/ent/notifier_create.go +++ b/backend/internal/data/ent/notifier_create.go @@ -199,10 +199,10 @@ func (nc *NotifierCreate) check() error { if _, ok := nc.mutation.IsActive(); !ok { return &ValidationError{Name: "is_active", err: errors.New(`ent: missing required field "Notifier.is_active"`)} } - if _, ok := nc.mutation.GroupID(); !ok { + if len(nc.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Notifier.group"`)} } - if _, ok := nc.mutation.UserID(); !ok { + if len(nc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "Notifier.user"`)} } return nil diff --git a/backend/internal/data/ent/notifier_query.go b/backend/internal/data/ent/notifier_query.go index dcde6dc3..232b8113 100644 --- a/backend/internal/data/ent/notifier_query.go +++ b/backend/internal/data/ent/notifier_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -109,7 +110,7 @@ func (nq *NotifierQuery) QueryUser() *UserQuery { // First returns the first Notifier entity from the query. // Returns a *NotFoundError when no Notifier was found. func (nq *NotifierQuery) First(ctx context.Context) (*Notifier, error) { - nodes, err := nq.Limit(1).All(setContextOp(ctx, nq.ctx, "First")) + nodes, err := nq.Limit(1).All(setContextOp(ctx, nq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -132,7 +133,7 @@ func (nq *NotifierQuery) FirstX(ctx context.Context) *Notifier { // Returns a *NotFoundError when no Notifier ID was found. func (nq *NotifierQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = nq.Limit(1).IDs(setContextOp(ctx, nq.ctx, "FirstID")); err != nil { + if ids, err = nq.Limit(1).IDs(setContextOp(ctx, nq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -155,7 +156,7 @@ func (nq *NotifierQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Notifier entity is found. // Returns a *NotFoundError when no Notifier entities are found. func (nq *NotifierQuery) Only(ctx context.Context) (*Notifier, error) { - nodes, err := nq.Limit(2).All(setContextOp(ctx, nq.ctx, "Only")) + nodes, err := nq.Limit(2).All(setContextOp(ctx, nq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -183,7 +184,7 @@ func (nq *NotifierQuery) OnlyX(ctx context.Context) *Notifier { // Returns a *NotFoundError when no entities are found. func (nq *NotifierQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = nq.Limit(2).IDs(setContextOp(ctx, nq.ctx, "OnlyID")); err != nil { + if ids, err = nq.Limit(2).IDs(setContextOp(ctx, nq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -208,7 +209,7 @@ func (nq *NotifierQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Notifiers. func (nq *NotifierQuery) All(ctx context.Context) ([]*Notifier, error) { - ctx = setContextOp(ctx, nq.ctx, "All") + ctx = setContextOp(ctx, nq.ctx, ent.OpQueryAll) if err := nq.prepareQuery(ctx); err != nil { return nil, err } @@ -230,7 +231,7 @@ func (nq *NotifierQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if nq.ctx.Unique == nil && nq.path != nil { nq.Unique(true) } - ctx = setContextOp(ctx, nq.ctx, "IDs") + ctx = setContextOp(ctx, nq.ctx, ent.OpQueryIDs) if err = nq.Select(notifier.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -248,7 +249,7 @@ func (nq *NotifierQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (nq *NotifierQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, nq.ctx, "Count") + ctx = setContextOp(ctx, nq.ctx, ent.OpQueryCount) if err := nq.prepareQuery(ctx); err != nil { return 0, err } @@ -266,7 +267,7 @@ func (nq *NotifierQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (nq *NotifierQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, nq.ctx, "Exist") + ctx = setContextOp(ctx, nq.ctx, ent.OpQueryExist) switch _, err := nq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -604,7 +605,7 @@ func (ngb *NotifierGroupBy) Aggregate(fns ...AggregateFunc) *NotifierGroupBy { // Scan applies the selector query and scans the result into the given value. func (ngb *NotifierGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ngb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ngb.build.ctx, ent.OpQueryGroupBy) if err := ngb.build.prepareQuery(ctx); err != nil { return err } @@ -652,7 +653,7 @@ func (ns *NotifierSelect) Aggregate(fns ...AggregateFunc) *NotifierSelect { // Scan applies the selector query and scans the result into the given value. func (ns *NotifierSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ns.ctx, "Select") + ctx = setContextOp(ctx, ns.ctx, ent.OpQuerySelect) if err := ns.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/notifier_update.go b/backend/internal/data/ent/notifier_update.go index 92b87be1..683c413c 100644 --- a/backend/internal/data/ent/notifier_update.go +++ b/backend/internal/data/ent/notifier_update.go @@ -182,10 +182,10 @@ func (nu *NotifierUpdate) check() error { return &ValidationError{Name: "url", err: fmt.Errorf(`ent: validator failed for field "Notifier.url": %w`, err)} } } - if _, ok := nu.mutation.GroupID(); nu.mutation.GroupCleared() && !ok { + if nu.mutation.GroupCleared() && len(nu.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Notifier.group"`) } - if _, ok := nu.mutation.UserID(); nu.mutation.UserCleared() && !ok { + if nu.mutation.UserCleared() && len(nu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Notifier.user"`) } return nil @@ -457,10 +457,10 @@ func (nuo *NotifierUpdateOne) check() error { return &ValidationError{Name: "url", err: fmt.Errorf(`ent: validator failed for field "Notifier.url": %w`, err)} } } - if _, ok := nuo.mutation.GroupID(); nuo.mutation.GroupCleared() && !ok { + if nuo.mutation.GroupCleared() && len(nuo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Notifier.group"`) } - if _, ok := nuo.mutation.UserID(); nuo.mutation.UserCleared() && !ok { + if nuo.mutation.UserCleared() && len(nuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Notifier.user"`) } return nil diff --git a/backend/internal/data/ent/runtime/runtime.go b/backend/internal/data/ent/runtime/runtime.go index dcbee86e..bb04574c 100644 --- a/backend/internal/data/ent/runtime/runtime.go +++ b/backend/internal/data/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in github.com/sysadminsmedia/homebox/backend/internal/data/ent/runtime.go const ( - Version = "v0.12.5" // Version of ent codegen. - Sum = "h1:KREM5E4CSoej4zeGa88Ou/gfturAnpUv0mzAjch1sj4=" // Sum of ent codegen. + Version = "v0.14.1" // Version of ent codegen. + Sum = "h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=" // Sum of ent codegen. ) diff --git a/backend/internal/data/ent/user.go b/backend/internal/data/ent/user.go index b00f838b..c8d9b99b 100644 --- a/backend/internal/data/ent/user.go +++ b/backend/internal/data/ent/user.go @@ -60,12 +60,10 @@ type UserEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e UserEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } diff --git a/backend/internal/data/ent/user_create.go b/backend/internal/data/ent/user_create.go index 7367ddb7..529ce637 100644 --- a/backend/internal/data/ent/user_create.go +++ b/backend/internal/data/ent/user_create.go @@ -288,7 +288,7 @@ func (uc *UserCreate) check() error { return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)} } } - if _, ok := uc.mutation.GroupID(); !ok { + if len(uc.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "User.group"`)} } return nil diff --git a/backend/internal/data/ent/user_query.go b/backend/internal/data/ent/user_query.go index dce4037d..bd75ecd8 100644 --- a/backend/internal/data/ent/user_query.go +++ b/backend/internal/data/ent/user_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -135,7 +136,7 @@ func (uq *UserQuery) QueryNotifiers() *NotifierQuery { // First returns the first User entity from the query. // Returns a *NotFoundError when no User was found. func (uq *UserQuery) First(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First")) + nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -158,7 +159,7 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User { // Returns a *NotFoundError when no User ID was found. func (uq *UserQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil { + if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -181,7 +182,7 @@ func (uq *UserQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one User entity is found. // Returns a *NotFoundError when no User entities are found. func (uq *UserQuery) Only(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only")) + nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -209,7 +210,7 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User { // Returns a *NotFoundError when no entities are found. func (uq *UserQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil { + if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -234,7 +235,7 @@ func (uq *UserQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Users. func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { - ctx = setContextOp(ctx, uq.ctx, "All") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryAll) if err := uq.prepareQuery(ctx); err != nil { return nil, err } @@ -256,7 +257,7 @@ func (uq *UserQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if uq.ctx.Unique == nil && uq.path != nil { uq.Unique(true) } - ctx = setContextOp(ctx, uq.ctx, "IDs") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryIDs) if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -274,7 +275,7 @@ func (uq *UserQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (uq *UserQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, uq.ctx, "Count") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryCount) if err := uq.prepareQuery(ctx); err != nil { return 0, err } @@ -292,7 +293,7 @@ func (uq *UserQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, uq.ctx, "Exist") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryExist) switch _, err := uq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -687,7 +688,7 @@ func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy { // Scan applies the selector query and scans the result into the given value. func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ugb.build.ctx, ent.OpQueryGroupBy) if err := ugb.build.prepareQuery(ctx); err != nil { return err } @@ -735,7 +736,7 @@ func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect { // Scan applies the selector query and scans the result into the given value. func (us *UserSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, us.ctx, "Select") + ctx = setContextOp(ctx, us.ctx, ent.OpQuerySelect) if err := us.prepareQuery(ctx); err != nil { return err } diff --git a/backend/internal/data/ent/user_update.go b/backend/internal/data/ent/user_update.go index 3277713d..8697a637 100644 --- a/backend/internal/data/ent/user_update.go +++ b/backend/internal/data/ent/user_update.go @@ -294,7 +294,7 @@ func (uu *UserUpdate) check() error { return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)} } } - if _, ok := uu.mutation.GroupID(); uu.mutation.GroupCleared() && !ok { + if uu.mutation.GroupCleared() && len(uu.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "User.group"`) } return nil @@ -753,7 +753,7 @@ func (uuo *UserUpdateOne) check() error { return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "User.role": %w`, err)} } } - if _, ok := uuo.mutation.GroupID(); uuo.mutation.GroupCleared() && !ok { + if uuo.mutation.GroupCleared() && len(uuo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "User.group"`) } return nil From c6158e7c9ebf8ce4c921078b71f71fe2e16606c4 Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Sat, 5 Oct 2024 15:38:31 -0400 Subject: [PATCH 14/17] fix: javascript handles nulls in an incredibly stupid way. --- backend/app/api/static/docs/docs.go | 17 +++++------ backend/app/api/static/docs/swagger.json | 17 +++++------ backend/app/api/static/docs/swagger.yaml | 13 +++++---- backend/internal/data/repo/repo_items.go | 8 +++--- docs/docs/api/openapi-2.0.json | 36 ++++++++++++++---------- frontend/lib/api/types/data-contracts.ts | 13 ++++----- frontend/pages/item/[id]/index/edit.vue | 12 ++++++++ 7 files changed, 67 insertions(+), 49 deletions(-) diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 79d62ccc..4e3a5db2 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -2217,8 +2217,7 @@ const docTemplate = `{ "type": "string" }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "purchaseTime": { "description": "Purchase", @@ -2234,8 +2233,7 @@ const docTemplate = `{ "type": "string" }, "soldPrice": { - "type": "string", - "example": "0" + "type": "number" }, "soldTime": { "description": "Sold", @@ -2323,8 +2321,7 @@ const docTemplate = `{ "type": "string" }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "quantity": { "type": "integer" @@ -2412,7 +2409,9 @@ const docTemplate = `{ "maxLength": 255 }, "purchasePrice": { - "type": "number" + "type": "number", + "x-nullable": true, + "x-omitempty": true }, "purchaseTime": { "description": "Purchase", @@ -2429,7 +2428,9 @@ const docTemplate = `{ "type": "string" }, "soldPrice": { - "type": "number" + "type": "number", + "x-nullable": true, + "x-omitempty": true }, "soldTime": { "description": "Sold", diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index addf7280..532020b8 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -2210,8 +2210,7 @@ "type": "string" }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "purchaseTime": { "description": "Purchase", @@ -2227,8 +2226,7 @@ "type": "string" }, "soldPrice": { - "type": "string", - "example": "0" + "type": "number" }, "soldTime": { "description": "Sold", @@ -2316,8 +2314,7 @@ "type": "string" }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "quantity": { "type": "integer" @@ -2405,7 +2402,9 @@ "maxLength": 255 }, "purchasePrice": { - "type": "number" + "type": "number", + "x-nullable": true, + "x-omitempty": true }, "purchaseTime": { "description": "Purchase", @@ -2422,7 +2421,9 @@ "type": "string" }, "soldPrice": { - "type": "number" + "type": "number", + "x-nullable": true, + "x-omitempty": true }, "soldTime": { "description": "Sold", diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index a7211acb..7939eb3d 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -171,8 +171,7 @@ definitions: purchaseFrom: type: string purchasePrice: - example: "0" - type: string + type: number purchaseTime: description: Purchase type: string @@ -183,8 +182,7 @@ definitions: soldNotes: type: string soldPrice: - example: "0" - type: string + type: number soldTime: description: Sold type: string @@ -242,8 +240,7 @@ definitions: name: type: string purchasePrice: - example: "0" - type: string + type: number quantity: type: integer updatedAt: @@ -304,6 +301,8 @@ definitions: type: string purchasePrice: type: number + x-nullable: true + x-omitempty: true purchaseTime: description: Purchase type: string @@ -316,6 +315,8 @@ definitions: type: string soldPrice: type: number + x-nullable: true + x-omitempty: true soldTime: description: Sold type: string diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index d67a60a3..cffc910f 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -93,12 +93,12 @@ type ( // Purchase PurchaseTime types.Date `json:"purchaseTime"` PurchaseFrom string `json:"purchaseFrom" validate:"max=255"` - PurchasePrice float64 `json:"purchasePrice"` + PurchasePrice float64 `json:"purchasePrice" extensions:"x-nullable,x-omitempty"` // Sold SoldTime types.Date `json:"soldTime"` SoldTo string `json:"soldTo" validate:"max=255"` - SoldPrice float64 `json:"soldPrice"` + SoldPrice float64 `json:"soldPrice" extensions:"x-nullable,x-omitempty"` SoldNotes string `json:"soldNotes"` // Extras @@ -123,7 +123,7 @@ type ( CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` - PurchasePrice float64 `json:"purchasePrice,string"` + PurchasePrice float64 `json:"purchasePrice"` // Edges Location *LocationSummary `json:"location,omitempty" extensions:"x-nullable,x-omitempty"` @@ -153,7 +153,7 @@ type ( // Sold SoldTime types.Date `json:"soldTime"` SoldTo string `json:"soldTo"` - SoldPrice float64 `json:"soldPrice,string"` + SoldPrice float64 `json:"soldPrice"` SoldNotes string `json:"soldNotes"` // Extras diff --git a/docs/docs/api/openapi-2.0.json b/docs/docs/api/openapi-2.0.json index 12e556ce..532020b8 100644 --- a/docs/docs/api/openapi-2.0.json +++ b/docs/docs/api/openapi-2.0.json @@ -2210,8 +2210,7 @@ "type": "string" }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "purchaseTime": { "description": "Purchase", @@ -2227,8 +2226,7 @@ "type": "string" }, "soldPrice": { - "type": "string", - "example": "0" + "type": "number" }, "soldTime": { "description": "Sold", @@ -2316,8 +2314,7 @@ "type": "string" }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number" }, "quantity": { "type": "integer" @@ -2340,6 +2337,9 @@ }, "repo.ItemUpdate": { "type": "object", + "required": [ + "name" + ], "properties": { "archived": { "type": "boolean" @@ -2348,7 +2348,8 @@ "type": "string" }, "description": { - "type": "string" + "type": "string", + "maxLength": 1000 }, "fields": { "type": "array", @@ -2383,7 +2384,9 @@ "type": "string" }, "name": { - "type": "string" + "type": "string", + "maxLength": 255, + "minLength": 1 }, "notes": { "description": "Extras", @@ -2395,11 +2398,13 @@ "x-omitempty": true }, "purchaseFrom": { - "type": "string" + "type": "string", + "maxLength": 255 }, "purchasePrice": { - "type": "string", - "example": "0" + "type": "number", + "x-nullable": true, + "x-omitempty": true }, "purchaseTime": { "description": "Purchase", @@ -2416,15 +2421,17 @@ "type": "string" }, "soldPrice": { - "type": "string", - "example": "0" + "type": "number", + "x-nullable": true, + "x-omitempty": true }, "soldTime": { "description": "Sold", "type": "string" }, "soldTo": { - "type": "string" + "type": "string", + "maxLength": 255 }, "warrantyDetails": { "type": "string" @@ -2756,7 +2763,6 @@ "type": "string" }, "url": { - "description": "URL field is not exposed to the client", "type": "string" }, "userId": { diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index 952e4f1e..c664c93f 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -106,15 +106,13 @@ export interface ItemOut { notes: string; parent?: ItemSummary | null; purchaseFrom: string; - /** @example "0" */ - purchasePrice: string; + purchasePrice: number; /** Purchase */ purchaseTime: Date | string; quantity: number; serialNumber: string; soldNotes: string; - /** @example "0" */ - soldPrice: string; + soldPrice: number; /** Sold */ soldTime: Date | string; soldTo: string; @@ -145,8 +143,7 @@ export interface ItemSummary { /** Edges */ location?: LocationSummary | null; name: string; - /** @example "0" */ - purchasePrice: string; + purchasePrice: number; quantity: number; updatedAt: Date | string; } @@ -181,14 +178,14 @@ export interface ItemUpdate { parentId?: string | null; /** @maxLength 255 */ purchaseFrom: string; - purchasePrice: number; + purchasePrice?: number | null; /** Purchase */ purchaseTime: Date | string; quantity: number; /** Identifications */ serialNumber: string; soldNotes: string; - soldPrice: number; + soldPrice?: number | null; /** Sold */ soldTime: Date | string; /** @maxLength 255 */ diff --git a/frontend/pages/item/[id]/index/edit.vue b/frontend/pages/item/[id]/index/edit.vue index 2d9c9a70..1f3cd0bc 100644 --- a/frontend/pages/item/[id]/index/edit.vue +++ b/frontend/pages/item/[id]/index/edit.vue @@ -65,12 +65,24 @@ return; } + let purchasePrice = 0; + let soldPrice = 0; + if (item.value.purchasePrice) { + purchasePrice = item.value.purchasePrice; + } + if (item.value.soldPrice) { + soldPrice = item.value.soldPrice; + } + console.log((item.value.purchasePrice ??= 0)); + console.log((item.value.soldPrice ??= 0)); const payload: ItemUpdate = { ...item.value, locationId: item.value.location?.id, labelIds: item.value.labels.map(l => l.id), parentId: parent.value ? parent.value.id : null, assetId: item.value.assetId, + purchasePrice, + soldPrice, }; const { error } = await api.items.update(itemId.value, payload); From ed780e292bda28824852c72a5855f8ca9407f6fe Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Tue, 8 Oct 2024 15:46:10 -0400 Subject: [PATCH 15/17] chore: split arm docker builds into their own tags (#264) Reduces overall build times significantly, and reduces the chances of architecture specific issues causing build timeouts. BREAKING CHANGE: Those using ARM based architecture docker installations will need to update the tag they use to have the `-arm` suffix. --- .github/workflows/docker-publish-arm.yaml | 107 +++++++++++++++++ .../docker-publish-rootless-arm.yaml | 108 ++++++++++++++++++ .../workflows/docker-publish-rootless.yaml | 2 +- .github/workflows/docker-publish.yaml | 2 +- 4 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker-publish-arm.yaml create mode 100644 .github/workflows/docker-publish-rootless-arm.yaml diff --git a/.github/workflows/docker-publish-arm.yaml b/.github/workflows/docker-publish-arm.yaml new file mode 100644 index 00000000..70564126 --- /dev/null +++ b/.github/workflows/docker-publish-arm.yaml @@ -0,0 +1,107 @@ +name: Docker publish + +on: + schedule: + - cron: '00 0 * * *' + push: + branches: [ "main" ] + paths: + - 'backend/**' + - 'frontend/**' + - 'Dockerfile' + - 'Dockerfile.rootless' + - '.dockerignore' + - '.github/workflows' + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + paths: + - 'backend/**' + - 'frontend/**' + - 'Dockerfile' + - 'Dockerfile.rootless' + - '.dockerignore' + - '.github/workflows' + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.0.0 # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5.0.0 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=schedule,pattern=nightly + flavor: | + suffix=-arm,onlatest=true + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5.0.0 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/arm64,linux/arm/v7 + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + VERSION=${{ github.ref_name }} + COMMIT=${{ github.sha }} + + - name: Attest + uses: actions/attest-build-provenance@v1 + id: attest + if: ${{ github.event_name != 'pull_request' }} + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + subject-digest: ${{ steps.build-and-push.outputs.digest }} + push-to-registry: true diff --git a/.github/workflows/docker-publish-rootless-arm.yaml b/.github/workflows/docker-publish-rootless-arm.yaml new file mode 100644 index 00000000..65c36cf5 --- /dev/null +++ b/.github/workflows/docker-publish-rootless-arm.yaml @@ -0,0 +1,108 @@ +name: Docker publish rootless + +on: + schedule: + - cron: '00 0 * * *' + push: + branches: [ "main" ] + paths: + - 'backend/**' + - 'frontend/**' + - 'Dockerfile' + - 'Dockerfile.rootless' + - '.dockerignore' + - '.github/workflows' + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + paths: + - 'backend/**' + - 'frontend/**' + - 'Dockerfile' + - 'Dockerfile.rootless' + - '.dockerignore' + - '.github/workflows' + + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build-rootless: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.0.0 # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: metadata + uses: docker/metadata-action@v5.0.0 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=schedule,pattern=nightly + flavor: | + suffix=-rootless-arm,onlatest=true + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5.0.0 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} + platforms: linux/arm64,linux/arm/v7 + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + VERSION=${{ github.ref_name }} + COMMIT=${{ github.sha }} + + - name: Attest + uses: actions/attest-build-provenance@v1 + id: attest + if: ${{ github.event_name != 'pull_request' }} + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + subject-digest: ${{ steps.build-and-push.outputs.digest }} + push-to-registry: true diff --git a/.github/workflows/docker-publish-rootless.yaml b/.github/workflows/docker-publish-rootless.yaml index 745c089b..f5d022c6 100644 --- a/.github/workflows/docker-publish-rootless.yaml +++ b/.github/workflows/docker-publish-rootless.yaml @@ -91,7 +91,7 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.metadata.outputs.tags }} labels: ${{ steps.metadata.outputs.labels }} - platforms: linux/amd64,linux/arm64,linux/arm/v7 + platforms: linux/amd64 cache-from: type=gha cache-to: type=gha,mode=max build-args: | diff --git a/.github/workflows/docker-publish.yaml b/.github/workflows/docker-publish.yaml index cf05d993..ab226bdb 100644 --- a/.github/workflows/docker-publish.yaml +++ b/.github/workflows/docker-publish.yaml @@ -88,7 +88,7 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64,linux/arm/v7 + platforms: linux/amd64 cache-from: type=gha cache-to: type=gha,mode=max build-args: | From 3fd14aac474ec30d71784f0b7fe267df94fa52a8 Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Tue, 8 Oct 2024 15:47:12 -0400 Subject: [PATCH 16/17] Update docker-publish-arm.yaml --- .github/workflows/docker-publish-arm.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish-arm.yaml b/.github/workflows/docker-publish-arm.yaml index 70564126..9e43e473 100644 --- a/.github/workflows/docker-publish-arm.yaml +++ b/.github/workflows/docker-publish-arm.yaml @@ -1,4 +1,4 @@ -name: Docker publish +name: Docker publish ARM on: schedule: From c9ed50afadf765dc688ec604a4cf20929e404607 Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Tue, 8 Oct 2024 15:47:22 -0400 Subject: [PATCH 17/17] Update docker-publish-rootless-arm.yaml --- .github/workflows/docker-publish-rootless-arm.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish-rootless-arm.yaml b/.github/workflows/docker-publish-rootless-arm.yaml index 65c36cf5..fde1e86a 100644 --- a/.github/workflows/docker-publish-rootless-arm.yaml +++ b/.github/workflows/docker-publish-rootless-arm.yaml @@ -1,4 +1,4 @@ -name: Docker publish rootless +name: Docker publish rootless ARM on: schedule: