From bd321af29fb9f6c0c7d7d10cd049740be757ff5a Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:41:01 -0900 Subject: [PATCH] chore: developer cleanup (#300) * new PR tasks * add homebox to know words * formatting * bump deps * generate db models * ts errors * drop id * fix accessor * drop unused time field * change CI * add expected error * add type check * resolve serveral type errors * hoise in CI --- .github/workflows/partial-frontend.yaml | 32 +- .vscode/settings.json | 3 +- Taskfile.yml | 19 + backend/app/api/handlers/v1/v1_ctrl_assets.go | 1 - backend/app/api/handlers/v1/v1_ctrl_auth.go | 2 - backend/app/api/handlers/v1/v1_ctrl_items.go | 2 - .../handlers/v1/v1_ctrl_items_attachments.go | 1 - .../app/api/handlers/v1/v1_ctrl_locations.go | 1 - backend/app/api/handlers/v1/v1_ctrl_user.go | 1 - backend/app/api/main.go | 2 +- backend/app/api/middleware.go | 4 +- backend/app/api/static/docs/docs.go | 3 - backend/app/api/static/docs/swagger.json | 3 - backend/app/api/static/docs/swagger.yaml | 2 - backend/go.sum | 4 - .../service_items_attachments_test.go | 1 - .../internal/core/services/service_user.go | 3 - backend/internal/data/ent/attachment.go | 6 - .../internal/data/ent/attachment_create.go | 8 +- .../internal/data/ent/attachment_delete.go | 10 +- backend/internal/data/ent/attachment_query.go | 24 +- .../internal/data/ent/attachment_update.go | 28 +- backend/internal/data/ent/authroles.go | 6 - backend/internal/data/ent/authroles_create.go | 8 +- backend/internal/data/ent/authroles_delete.go | 10 +- backend/internal/data/ent/authroles_query.go | 24 +- backend/internal/data/ent/authroles_update.go | 28 +- backend/internal/data/ent/authtokens.go | 6 - .../internal/data/ent/authtokens_create.go | 8 +- .../internal/data/ent/authtokens_delete.go | 10 +- backend/internal/data/ent/authtokens_query.go | 24 +- .../internal/data/ent/authtokens_update.go | 28 +- backend/internal/data/ent/client.go | 24 +- backend/internal/data/ent/document.go | 6 - backend/internal/data/ent/document_create.go | 8 +- backend/internal/data/ent/document_delete.go | 10 +- backend/internal/data/ent/document_query.go | 24 +- backend/internal/data/ent/document_update.go | 28 +- backend/internal/data/ent/group.go | 6 - backend/internal/data/ent/group_create.go | 8 +- backend/internal/data/ent/group_delete.go | 10 +- backend/internal/data/ent/group_query.go | 24 +- backend/internal/data/ent/group_update.go | 28 +- .../internal/data/ent/groupinvitationtoken.go | 6 - .../data/ent/groupinvitationtoken_create.go | 8 +- .../data/ent/groupinvitationtoken_delete.go | 10 +- .../data/ent/groupinvitationtoken_query.go | 24 +- .../data/ent/groupinvitationtoken_update.go | 28 +- backend/internal/data/ent/item.go | 6 - backend/internal/data/ent/item_create.go | 8 +- backend/internal/data/ent/item_delete.go | 10 +- backend/internal/data/ent/item_query.go | 24 +- backend/internal/data/ent/item_update.go | 28 +- backend/internal/data/ent/itemfield.go | 6 - backend/internal/data/ent/itemfield_create.go | 8 +- backend/internal/data/ent/itemfield_delete.go | 10 +- backend/internal/data/ent/itemfield_query.go | 24 +- backend/internal/data/ent/itemfield_update.go | 28 +- backend/internal/data/ent/label.go | 6 - backend/internal/data/ent/label_create.go | 8 +- backend/internal/data/ent/label_delete.go | 10 +- backend/internal/data/ent/label_query.go | 24 +- backend/internal/data/ent/label_update.go | 28 +- backend/internal/data/ent/location.go | 6 - backend/internal/data/ent/location_create.go | 8 +- backend/internal/data/ent/location_delete.go | 10 +- backend/internal/data/ent/location_query.go | 24 +- backend/internal/data/ent/location_update.go | 28 +- backend/internal/data/ent/maintenanceentry.go | 6 - .../data/ent/maintenanceentry_create.go | 8 +- .../data/ent/maintenanceentry_delete.go | 10 +- .../data/ent/maintenanceentry_query.go | 24 +- .../data/ent/maintenanceentry_update.go | 28 +- backend/internal/data/ent/runtime/runtime.go | 4 +- backend/internal/data/ent/user.go | 6 - backend/internal/data/ent/user_create.go | 8 +- backend/internal/data/ent/user_delete.go | 10 +- backend/internal/data/ent/user_query.go | 24 +- backend/internal/data/ent/user_update.go | 28 +- .../internal/data/migrations/migrations.go | 4 +- backend/internal/data/repo/repo_documents.go | 6 +- .../internal/data/repo/repo_documents_test.go | 1 - backend/internal/data/repo/repo_group.go | 11 +- .../data/repo/repo_item_attachments.go | 1 - .../data/repo/repo_item_attachments_test.go | 2 - backend/internal/data/repo/repo_items.go | 21 +- backend/internal/data/repo/repo_items_test.go | 2 - backend/internal/data/repo/repo_labels.go | 1 - backend/internal/data/repo/repo_locations.go | 7 +- .../internal/data/repo/repo_locations_test.go | 2 - .../data/repo/repo_maintenance_entry.go | 1 - .../data/repo/repo_maintenance_entry_test.go | 1 - backend/internal/data/repo/repo_tokens.go | 5 - backend/internal/data/repo/repo_users.go | 1 - backend/internal/data/repo/repo_users_test.go | 1 - backend/internal/data/types/date.go | 57 +- backend/internal/sys/config/conf.go | 6 +- .../internal/sys/config/conf_mailer_test.go | 1 - backend/internal/sys/validate/errors.go | 3 +- backend/internal/sys/validate/validate.go | 1 - backend/internal/web/mid/errors.go | 1 - backend/internal/web/mid/logger.go | 1 - backend/pkgs/faker/random.go | 4 +- backend/pkgs/faker/randoms_test.go | 9 +- backend/pkgs/mailer/mailer_test.go | 3 - backend/pkgs/mailer/templates.go | 1 - backend/pkgs/server/middleware.go | 1 - backend/pkgs/server/mux.go | 1 - backend/pkgs/server/response_test.go | 1 - backend/pkgs/server/server.go | 1 - backend/pkgs/server/server_test.go | 1 - backend/pkgs/server/worker.go | 3 +- backend/pkgs/set/funcs.go | 1 - backend/pkgs/set/funcs_test.go | 1 - frontend/components/Form/Autocomplete.vue | 12 +- frontend/components/Form/Multiselect.vue | 2 - frontend/components/Form/Select.vue | 3 - frontend/components/Item/CreateModal.vue | 11 +- frontend/components/global/DropZone.vue | 2 +- frontend/composables/use-confirm.ts | 3 +- frontend/composables/use-route-params.ts | 2 +- frontend/composables/use-theme.ts | 4 +- frontend/lib/api/__test__/factories/index.ts | 10 +- frontend/lib/api/__test__/user/items.test.ts | 9 +- .../lib/api/__test__/user/locations.test.ts | 2 + frontend/lib/api/__test__/user/stats.test.ts | 19 +- frontend/lib/api/base/base-api.ts | 4 +- frontend/lib/api/classes/items.ts | 4 + frontend/lib/api/classes/reports.ts | 24 +- frontend/lib/api/types/data-contracts.ts | 1 - frontend/lib/requests/requests.ts | 2 + frontend/package.json | 6 +- frontend/pages/index.vue | 1 + frontend/pages/item/[id]/index.vue | 2 +- frontend/pages/items.vue | 2 +- frontend/pages/label/[id].vue | 8 +- frontend/pages/location/[id].vue | 7 +- frontend/pages/tools.vue | 4 +- frontend/pnpm-lock.yaml | 646 ++++++++++-------- frontend/stores/labels.ts | 10 +- frontend/stores/locations.ts | 27 +- frontend/test/setup.ts | 2 +- 142 files changed, 817 insertions(+), 1200 deletions(-) diff --git a/.github/workflows/partial-frontend.yaml b/.github/workflows/partial-frontend.yaml index 4f36af5..9f85179 100644 --- a/.github/workflows/partial-frontend.yaml +++ b/.github/workflows/partial-frontend.yaml @@ -4,7 +4,33 @@ on: workflow_call: jobs: - Frontend: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: pnpm/action-setup@v2.2.4 + with: + version: 6.0.2 + + - name: Install dependencies + run: pnpm install --shamefully-hoist + working-directory: frontend + + - name: Run Lint + run: pnpm run lint:ci + working-directory: frontend + + - name: Run Typecheck + run: pnpm run typecheck + working-directory: frontend + + integration-tests: + name: Integration Tests runs-on: ubuntu-latest steps: - name: Checkout @@ -34,9 +60,5 @@ jobs: run: pnpm install working-directory: frontend - - name: Run linter 👀 - run: pnpm lint - working-directory: "frontend" - - name: Run Integration Tests run: task test:ci diff --git a/.vscode/settings.json b/.vscode/settings.json index d0ae55d..2383c21 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,8 @@ "README.md": "LICENSE, SECURITY.md" }, "cSpell.words": [ - "debughandlers" + "debughandlers", + "Homebox" ], // use ESLint to format code on save "editor.formatOnSave": false, diff --git a/Taskfile.yml b/Taskfile.yml index a16daa5..e619395 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -108,6 +108,16 @@ tasks: cmds: - cd frontend && pnpm dev + ui:fix: + desc: Runs prettier and eslint on the frontend + cmds: + - cd frontend && pnpm run lint:fix + + ui:check: + desc: Runs type checking + cmds: + - cd frontend && pnpm run typecheck + test:ci: desc: Runs end-to-end test on a live server (only for use in CI) cmds: @@ -116,3 +126,12 @@ tasks: - sleep 5 - cd frontend && pnpm run test:ci silent: true + + pr: + desc: Runs all tasks required for a PR + cmds: + - task: generate + - task: go:all + - task: ui:check + - task: ui:fix + - task: test:ci \ No newline at end of file diff --git a/backend/app/api/handlers/v1/v1_ctrl_assets.go b/backend/app/api/handlers/v1/v1_ctrl_assets.go index 82653fe..f91a009 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_assets.go +++ b/backend/app/api/handlers/v1/v1_ctrl_assets.go @@ -49,7 +49,6 @@ func (ctrl *V1Controller) HandleAssetGet() server.HandlerFunc { return server.Respond(w, http.StatusBadRequest, "Invalid page size") } } - items, err := ctrl.repo.Items.QueryByAssetID(r.Context(), ctx.GID, repo.AssetID(assetId), int(page), int(pageSize)) if err != nil { diff --git a/backend/app/api/handlers/v1/v1_ctrl_auth.go b/backend/app/api/handlers/v1/v1_ctrl_auth.go index 95a5cb2..a3dbc58 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_auth.go +++ b/backend/app/api/handlers/v1/v1_ctrl_auth.go @@ -50,7 +50,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc { loginForm.Password = r.PostFormValue("password") case server.ContentJSON: err := server.Decode(r, loginForm) - if err != nil { log.Err(err).Msg("failed to decode login form") } @@ -72,7 +71,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc { } newToken, err := ctrl.svc.User.Login(r.Context(), strings.ToLower(loginForm.Username), loginForm.Password) - if err != nil { return validate.NewRequestError(errors.New("authentication failed"), http.StatusInternalServerError) } diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index ec8f580..b82d2f3 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -26,7 +26,6 @@ import ( // @Router /v1/items [GET] // @Security Bearer func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc { - extractQuery := func(r *http.Request) repo.ItemQuery { params := r.URL.Query() @@ -244,7 +243,6 @@ func (ctrl *V1Controller) HandleGetAllCustomFieldValues() server.HandlerFunc { // @Security Bearer func (ctrl *V1Controller) HandleItemsImport() server.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) error { - err := r.ParseMultipartForm(ctrl.maxUploadSize << 20) if err != nil { log.Err(err).Msg("failed to parse multipart form") diff --git a/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go b/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go index 033f683..00545a4 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go @@ -82,7 +82,6 @@ func (ctrl *V1Controller) HandleItemAttachmentCreate() server.HandlerFunc { attachment.Type(attachmentType), file, ) - if err != nil { log.Err(err).Msg("failed to add attachment") return validate.NewRequestError(err, http.StatusInternalServerError) diff --git a/backend/app/api/handlers/v1/v1_ctrl_locations.go b/backend/app/api/handlers/v1/v1_ctrl_locations.go index ee2785a..8f71ab9 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_locations.go +++ b/backend/app/api/handlers/v1/v1_ctrl_locations.go @@ -34,7 +34,6 @@ func (ctrl *V1Controller) HandleLocationTreeQuery() server.HandlerFunc { WithItems: withItems, }, ) - if err != nil { log.Err(err).Msg("failed to get locations tree") return validate.NewRequestError(err, http.StatusInternalServerError) diff --git a/backend/app/api/handlers/v1/v1_ctrl_user.go b/backend/app/api/handlers/v1/v1_ctrl_user.go index 98bc75e..0d034c2 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_user.go +++ b/backend/app/api/handlers/v1/v1_ctrl_user.go @@ -80,7 +80,6 @@ func (ctrl *V1Controller) HandleUserSelfUpdate() server.HandlerFunc { actor := services.UseUserCtx(r.Context()) newData, err := ctrl.svc.User.UpdateSelf(r.Context(), actor.ID, updateData) - if err != nil { return validate.NewRequestError(err, http.StatusInternalServerError) } diff --git a/backend/app/api/main.go b/backend/app/api/main.go index c505eea..b17b0fa 100644 --- a/backend/app/api/main.go +++ b/backend/app/api/main.go @@ -57,7 +57,7 @@ func run(cfg *config.Config) error { // ========================================================================= // Initialize Database & Repos - err := os.MkdirAll(cfg.Storage.Data, 0755) + err := os.MkdirAll(cfg.Storage.Data, 0o755) if err != nil { log.Fatal().Err(err).Msg("failed to create data directory") } diff --git a/backend/app/api/middleware.go b/backend/app/api/middleware.go index 8baddfb..b41c913 100644 --- a/backend/app/api/middleware.go +++ b/backend/app/api/middleware.go @@ -15,9 +15,7 @@ type tokenHasKey struct { key string } -var ( - hashedToken = tokenHasKey{key: "hashedToken"} -) +var hashedToken = tokenHasKey{key: "hashedToken"} type RoleMode int diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index e24f140..8ceb1cf 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -1722,9 +1722,6 @@ const docTemplate = `{ "textValue": { "type": "string" }, - "timeValue": { - "type": "string" - }, "type": { "type": "string" } diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 6319ff9..3808fb5 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -1714,9 +1714,6 @@ "textValue": { "type": "string" }, - "timeValue": { - "type": "string" - }, "type": { "type": "string" } diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index 301dd3d..c461867 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -93,8 +93,6 @@ definitions: type: integer textValue: type: string - timeValue: - type: string type: type: string type: object diff --git a/backend/go.sum b/backend/go.sum index a0b4a5a..e0fca76 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,7 +1,5 @@ ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb h1:mbsFtavDqGdYwdDpP50LGOOZ2hgyGoJcZeOpbgKMyu4= ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU= -entgo.io/ent v0.11.7 h1:V+wKFh0jhAbY/FoU+PPbdMOf2Ma5vh07R/IdF+N/nFg= -entgo.io/ent v0.11.7/go.mod h1:ericBi6Q8l3wBH1wEIDfKxw7rcQEuRPyBfbIzjtxJ18= entgo.io/ent v0.11.8 h1:M/M0QL1CYCUSdqGRXUrXhFYSDRJPsOOrr+RLEej/gyQ= entgo.io/ent v0.11.8/go.mod h1:ericBi6Q8l3wBH1wEIDfKxw7rcQEuRPyBfbIzjtxJ18= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= @@ -11,8 +9,6 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= -github.com/ardanlabs/conf/v3 v3.1.3 h1:16+Nzfc4PBd/ERtYERUFL/75eVKNyW15Y+vn3W1XZzQ= -github.com/ardanlabs/conf/v3 v3.1.3/go.mod h1:bIacyuGeZjkTdtszdbvOcuq49VhHpV3+IPZ2ewOAK4I= github.com/ardanlabs/conf/v3 v3.1.4 h1:c0jJYbqHJcrR/uYImbGC1q7quH3DYxH49zGCT7WLJH4= github.com/ardanlabs/conf/v3 v3.1.4/go.mod h1:bIacyuGeZjkTdtszdbvOcuq49VhHpV3+IPZ2ewOAK4I= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= diff --git a/backend/internal/core/services/service_items_attachments_test.go b/backend/internal/core/services/service_items_attachments_test.go index 14e822e..f9db0f6 100644 --- a/backend/internal/core/services/service_items_attachments_test.go +++ b/backend/internal/core/services/service_items_attachments_test.go @@ -58,5 +58,4 @@ func TestItemService_AddAttachment(t *testing.T) { bts, err := os.ReadFile(storedPath) assert.NoError(t, err) assert.Equal(t, contents, string(bts)) - } diff --git a/backend/internal/core/services/service_user.go b/backend/internal/core/services/service_user.go index 053087b..bed3adb 100644 --- a/backend/internal/core/services/service_user.go +++ b/backend/internal/core/services/service_user.go @@ -139,7 +139,6 @@ func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data repo. // User Authentication func (svc *UserService) createSessionToken(ctx context.Context, userId uuid.UUID) (UserAuthTokenDetail, error) { - attachmentToken := hasher.GenerateToken() attachmentData := repo.UserAuthTokenCreate{ UserID: userId, @@ -173,7 +172,6 @@ func (svc *UserService) createSessionToken(ctx context.Context, userId uuid.UUID func (svc *UserService) Login(ctx context.Context, username, password string) (UserAuthTokenDetail, error) { usr, err := svc.repos.Users.GetOneEmail(ctx, username) - if err != nil { // SECURITY: Perform hash to ensure response times are the same hasher.CheckPasswordHash("not-a-real-password", "not-a-real-password") @@ -197,7 +195,6 @@ func (svc *UserService) RenewToken(ctx context.Context, token string) (UserAuthT hash := hasher.HashToken(token) dbToken, err := svc.repos.AuthTokens.GetUserFromToken(ctx, hash) - if err != nil { return UserAuthTokenDetail{}, ErrorInvalidToken } diff --git a/backend/internal/data/ent/attachment.go b/backend/internal/data/ent/attachment.go index 897a0a3..25d2df4 100644 --- a/backend/internal/data/ent/attachment.go +++ b/backend/internal/data/ent/attachment.go @@ -189,9 +189,3 @@ func (a *Attachment) String() string { // Attachments is a parsable slice of Attachment. type Attachments []*Attachment - -func (a Attachments) config(cfg config) { - for _i := range a { - a[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/attachment_create.go b/backend/internal/data/ent/attachment_create.go index 2be195e..5ce7ef3 100644 --- a/backend/internal/data/ent/attachment_create.go +++ b/backend/internal/data/ent/attachment_create.go @@ -205,13 +205,7 @@ func (ac *AttachmentCreate) sqlSave(ctx context.Context) (*Attachment, error) { func (ac *AttachmentCreate) createSpec() (*Attachment, *sqlgraph.CreateSpec) { var ( _node = &Attachment{config: ac.config} - _spec = &sqlgraph.CreateSpec{ - Table: attachment.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: attachment.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(attachment.Table, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID)) ) if id, ok := ac.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/attachment_delete.go b/backend/internal/data/ent/attachment_delete.go index 5b45801..8185ac1 100644 --- a/backend/internal/data/ent/attachment_delete.go +++ b/backend/internal/data/ent/attachment_delete.go @@ -40,15 +40,7 @@ func (ad *AttachmentDelete) ExecX(ctx context.Context) int { } func (ad *AttachmentDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: attachment.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: attachment.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(attachment.Table, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID)) if ps := ad.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/attachment_query.go b/backend/internal/data/ent/attachment_query.go index d631f7e..de5821a 100644 --- a/backend/internal/data/ent/attachment_query.go +++ b/backend/internal/data/ent/attachment_query.go @@ -227,10 +227,12 @@ func (aq *AttachmentQuery) AllX(ctx context.Context) []*Attachment { } // IDs executes the query and returns a list of Attachment IDs. -func (aq *AttachmentQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := aq.Select(attachment.FieldID).Scan(ctx, &ids); err != nil { + if err = aq.Select(attachment.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -525,20 +527,12 @@ func (aq *AttachmentQuery) sqlCount(ctx context.Context) (int, error) { } func (aq *AttachmentQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: attachment.Table, - Columns: attachment.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: attachment.FieldID, - }, - }, - From: aq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID)) + _spec.From = aq.sql if unique := aq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if aq.path != nil { + _spec.Unique = true } if fields := aq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/attachment_update.go b/backend/internal/data/ent/attachment_update.go index a54ad5a..e4b747d 100644 --- a/backend/internal/data/ent/attachment_update.go +++ b/backend/internal/data/ent/attachment_update.go @@ -146,16 +146,7 @@ func (au *AttachmentUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := au.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: attachment.Table, - Columns: attachment.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: attachment.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID)) if ps := au.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -318,6 +309,12 @@ func (auo *AttachmentUpdateOne) ClearDocument() *AttachmentUpdateOne { return auo } +// Where appends a list predicates to the AttachmentUpdate builder. +func (auo *AttachmentUpdateOne) Where(ps ...predicate.Attachment) *AttachmentUpdateOne { + auo.mutation.Where(ps...) + return auo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (auo *AttachmentUpdateOne) Select(field string, fields ...string) *AttachmentUpdateOne { @@ -381,16 +378,7 @@ func (auo *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment, if err := auo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: attachment.Table, - Columns: attachment.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: attachment.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(attachment.Table, attachment.Columns, sqlgraph.NewFieldSpec(attachment.FieldID, field.TypeUUID)) id, ok := auo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Attachment.id" for update`)} diff --git a/backend/internal/data/ent/authroles.go b/backend/internal/data/ent/authroles.go index 5e8ed40..4dcd733 100644 --- a/backend/internal/data/ent/authroles.go +++ b/backend/internal/data/ent/authroles.go @@ -133,9 +133,3 @@ func (ar *AuthRoles) String() string { // AuthRolesSlice is a parsable slice of AuthRoles. type AuthRolesSlice []*AuthRoles - -func (ar AuthRolesSlice) config(cfg config) { - for _i := range ar { - ar[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/authroles_create.go b/backend/internal/data/ent/authroles_create.go index 383b8c3..566d107 100644 --- a/backend/internal/data/ent/authroles_create.go +++ b/backend/internal/data/ent/authroles_create.go @@ -129,13 +129,7 @@ func (arc *AuthRolesCreate) sqlSave(ctx context.Context) (*AuthRoles, error) { func (arc *AuthRolesCreate) createSpec() (*AuthRoles, *sqlgraph.CreateSpec) { var ( _node = &AuthRoles{config: arc.config} - _spec = &sqlgraph.CreateSpec{ - Table: authroles.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: authroles.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(authroles.Table, sqlgraph.NewFieldSpec(authroles.FieldID, field.TypeInt)) ) if value, ok := arc.mutation.Role(); ok { _spec.SetField(authroles.FieldRole, field.TypeEnum, value) diff --git a/backend/internal/data/ent/authroles_delete.go b/backend/internal/data/ent/authroles_delete.go index 3cc1faa..13a2518 100644 --- a/backend/internal/data/ent/authroles_delete.go +++ b/backend/internal/data/ent/authroles_delete.go @@ -40,15 +40,7 @@ func (ard *AuthRolesDelete) ExecX(ctx context.Context) int { } func (ard *AuthRolesDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authroles.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: authroles.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(authroles.Table, sqlgraph.NewFieldSpec(authroles.FieldID, field.TypeInt)) if ps := ard.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/authroles_query.go b/backend/internal/data/ent/authroles_query.go index ed44fa9..14042ff 100644 --- a/backend/internal/data/ent/authroles_query.go +++ b/backend/internal/data/ent/authroles_query.go @@ -203,10 +203,12 @@ func (arq *AuthRolesQuery) AllX(ctx context.Context) []*AuthRoles { } // IDs executes the query and returns a list of AuthRoles IDs. -func (arq *AuthRolesQuery) IDs(ctx context.Context) ([]int, error) { - var ids []int +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") - if err := arq.Select(authroles.FieldID).Scan(ctx, &ids); err != nil { + if err = arq.Select(authroles.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -450,20 +452,12 @@ func (arq *AuthRolesQuery) sqlCount(ctx context.Context) (int, error) { } func (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: authroles.Table, - Columns: authroles.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: authroles.FieldID, - }, - }, - From: arq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(authroles.Table, authroles.Columns, sqlgraph.NewFieldSpec(authroles.FieldID, field.TypeInt)) + _spec.From = arq.sql if unique := arq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if arq.path != nil { + _spec.Unique = true } if fields := arq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/authroles_update.go b/backend/internal/data/ent/authroles_update.go index dea7b76..ca222e4 100644 --- a/backend/internal/data/ent/authroles_update.go +++ b/backend/internal/data/ent/authroles_update.go @@ -114,16 +114,7 @@ func (aru *AuthRolesUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := aru.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authroles.Table, - Columns: authroles.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: authroles.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(authroles.Table, authroles.Columns, sqlgraph.NewFieldSpec(authroles.FieldID, field.TypeInt)) if ps := aru.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -233,6 +224,12 @@ func (aruo *AuthRolesUpdateOne) ClearToken() *AuthRolesUpdateOne { return aruo } +// Where appends a list predicates to the AuthRolesUpdate builder. +func (aruo *AuthRolesUpdateOne) Where(ps ...predicate.AuthRoles) *AuthRolesUpdateOne { + aruo.mutation.Where(ps...) + return aruo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (aruo *AuthRolesUpdateOne) Select(field string, fields ...string) *AuthRolesUpdateOne { @@ -281,16 +278,7 @@ func (aruo *AuthRolesUpdateOne) sqlSave(ctx context.Context) (_node *AuthRoles, if err := aruo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authroles.Table, - Columns: authroles.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeInt, - Column: authroles.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(authroles.Table, authroles.Columns, sqlgraph.NewFieldSpec(authroles.FieldID, field.TypeInt)) id, ok := aruo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthRoles.id" for update`)} diff --git a/backend/internal/data/ent/authtokens.go b/backend/internal/data/ent/authtokens.go index 1418838..a2b6589 100644 --- a/backend/internal/data/ent/authtokens.go +++ b/backend/internal/data/ent/authtokens.go @@ -190,9 +190,3 @@ func (at *AuthTokens) String() string { // AuthTokensSlice is a parsable slice of AuthTokens. type AuthTokensSlice []*AuthTokens - -func (at AuthTokensSlice) config(cfg config) { - for _i := range at { - at[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/authtokens_create.go b/backend/internal/data/ent/authtokens_create.go index d6632bb..a8f2971 100644 --- a/backend/internal/data/ent/authtokens_create.go +++ b/backend/internal/data/ent/authtokens_create.go @@ -219,13 +219,7 @@ func (atc *AuthTokensCreate) sqlSave(ctx context.Context) (*AuthTokens, error) { func (atc *AuthTokensCreate) createSpec() (*AuthTokens, *sqlgraph.CreateSpec) { var ( _node = &AuthTokens{config: atc.config} - _spec = &sqlgraph.CreateSpec{ - Table: authtokens.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: authtokens.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(authtokens.Table, sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID)) ) if id, ok := atc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/authtokens_delete.go b/backend/internal/data/ent/authtokens_delete.go index 79c1a0c..1d46fe3 100644 --- a/backend/internal/data/ent/authtokens_delete.go +++ b/backend/internal/data/ent/authtokens_delete.go @@ -40,15 +40,7 @@ func (atd *AuthTokensDelete) ExecX(ctx context.Context) int { } func (atd *AuthTokensDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authtokens.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: authtokens.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(authtokens.Table, sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID)) if ps := atd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/authtokens_query.go b/backend/internal/data/ent/authtokens_query.go index 5695942..5b4302a 100644 --- a/backend/internal/data/ent/authtokens_query.go +++ b/backend/internal/data/ent/authtokens_query.go @@ -228,10 +228,12 @@ func (atq *AuthTokensQuery) AllX(ctx context.Context) []*AuthTokens { } // IDs executes the query and returns a list of AuthTokens IDs. -func (atq *AuthTokensQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := atq.Select(authtokens.FieldID).Scan(ctx, &ids); err != nil { + if err = atq.Select(authtokens.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -522,20 +524,12 @@ func (atq *AuthTokensQuery) sqlCount(ctx context.Context) (int, error) { } func (atq *AuthTokensQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: authtokens.Table, - Columns: authtokens.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: authtokens.FieldID, - }, - }, - From: atq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(authtokens.Table, authtokens.Columns, sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID)) + _spec.From = atq.sql if unique := atq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if atq.path != nil { + _spec.Unique = true } if fields := atq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/authtokens_update.go b/backend/internal/data/ent/authtokens_update.go index c058ee3..11f34db 100644 --- a/backend/internal/data/ent/authtokens_update.go +++ b/backend/internal/data/ent/authtokens_update.go @@ -149,16 +149,7 @@ func (atu *AuthTokensUpdate) defaults() { } func (atu *AuthTokensUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authtokens.Table, - Columns: authtokens.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: authtokens.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(authtokens.Table, authtokens.Columns, sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID)) if ps := atu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -346,6 +337,12 @@ func (atuo *AuthTokensUpdateOne) ClearRoles() *AuthTokensUpdateOne { return atuo } +// Where appends a list predicates to the AuthTokensUpdate builder. +func (atuo *AuthTokensUpdateOne) Where(ps ...predicate.AuthTokens) *AuthTokensUpdateOne { + atuo.mutation.Where(ps...) + return atuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (atuo *AuthTokensUpdateOne) Select(field string, fields ...string) *AuthTokensUpdateOne { @@ -390,16 +387,7 @@ func (atuo *AuthTokensUpdateOne) defaults() { } func (atuo *AuthTokensUpdateOne) sqlSave(ctx context.Context) (_node *AuthTokens, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: authtokens.Table, - Columns: authtokens.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: authtokens.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(authtokens.Table, authtokens.Columns, sqlgraph.NewFieldSpec(authtokens.FieldID, field.TypeUUID)) id, ok := atuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthTokens.id" for update`)} diff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.go index f021598..44755c8 100644 --- a/backend/internal/data/ent/client.go +++ b/backend/internal/data/ent/client.go @@ -266,7 +266,7 @@ func (c *AttachmentClient) Use(hooks ...Hook) { c.hooks.Attachment = append(c.hooks.Attachment, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `attachment.Intercept(f(g(h())))`. func (c *AttachmentClient) Intercept(interceptors ...Interceptor) { c.inters.Attachment = append(c.inters.Attachment, interceptors...) @@ -416,7 +416,7 @@ func (c *AuthRolesClient) Use(hooks ...Hook) { c.hooks.AuthRoles = append(c.hooks.AuthRoles, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `authroles.Intercept(f(g(h())))`. func (c *AuthRolesClient) Intercept(interceptors ...Interceptor) { c.inters.AuthRoles = append(c.inters.AuthRoles, interceptors...) @@ -550,7 +550,7 @@ func (c *AuthTokensClient) Use(hooks ...Hook) { c.hooks.AuthTokens = append(c.hooks.AuthTokens, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `authtokens.Intercept(f(g(h())))`. func (c *AuthTokensClient) Intercept(interceptors ...Interceptor) { c.inters.AuthTokens = append(c.inters.AuthTokens, interceptors...) @@ -700,7 +700,7 @@ func (c *DocumentClient) Use(hooks ...Hook) { c.hooks.Document = append(c.hooks.Document, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `document.Intercept(f(g(h())))`. func (c *DocumentClient) Intercept(interceptors ...Interceptor) { c.inters.Document = append(c.inters.Document, interceptors...) @@ -850,7 +850,7 @@ func (c *GroupClient) Use(hooks ...Hook) { c.hooks.Group = append(c.hooks.Group, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `group.Intercept(f(g(h())))`. func (c *GroupClient) Intercept(interceptors ...Interceptor) { c.inters.Group = append(c.inters.Group, interceptors...) @@ -1064,7 +1064,7 @@ func (c *GroupInvitationTokenClient) Use(hooks ...Hook) { c.hooks.GroupInvitationToken = append(c.hooks.GroupInvitationToken, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `groupinvitationtoken.Intercept(f(g(h())))`. func (c *GroupInvitationTokenClient) Intercept(interceptors ...Interceptor) { c.inters.GroupInvitationToken = append(c.inters.GroupInvitationToken, interceptors...) @@ -1198,7 +1198,7 @@ func (c *ItemClient) Use(hooks ...Hook) { c.hooks.Item = append(c.hooks.Item, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `item.Intercept(f(g(h())))`. func (c *ItemClient) Intercept(interceptors ...Interceptor) { c.inters.Item = append(c.inters.Item, interceptors...) @@ -1444,7 +1444,7 @@ func (c *ItemFieldClient) Use(hooks ...Hook) { c.hooks.ItemField = append(c.hooks.ItemField, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `itemfield.Intercept(f(g(h())))`. func (c *ItemFieldClient) Intercept(interceptors ...Interceptor) { c.inters.ItemField = append(c.inters.ItemField, interceptors...) @@ -1578,7 +1578,7 @@ func (c *LabelClient) Use(hooks ...Hook) { c.hooks.Label = append(c.hooks.Label, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `label.Intercept(f(g(h())))`. func (c *LabelClient) Intercept(interceptors ...Interceptor) { c.inters.Label = append(c.inters.Label, interceptors...) @@ -1728,7 +1728,7 @@ func (c *LocationClient) Use(hooks ...Hook) { c.hooks.Location = append(c.hooks.Location, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `location.Intercept(f(g(h())))`. func (c *LocationClient) Intercept(interceptors ...Interceptor) { c.inters.Location = append(c.inters.Location, interceptors...) @@ -1910,7 +1910,7 @@ func (c *MaintenanceEntryClient) Use(hooks ...Hook) { c.hooks.MaintenanceEntry = append(c.hooks.MaintenanceEntry, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `maintenanceentry.Intercept(f(g(h())))`. func (c *MaintenanceEntryClient) Intercept(interceptors ...Interceptor) { c.inters.MaintenanceEntry = append(c.inters.MaintenanceEntry, interceptors...) @@ -2044,7 +2044,7 @@ func (c *UserClient) Use(hooks ...Hook) { c.hooks.User = append(c.hooks.User, hooks...) } -// Use adds a list of query interceptors to the interceptors stack. +// Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`. func (c *UserClient) Intercept(interceptors ...Interceptor) { c.inters.User = append(c.inters.User, interceptors...) diff --git a/backend/internal/data/ent/document.go b/backend/internal/data/ent/document.go index 661a37e..bcaae9a 100644 --- a/backend/internal/data/ent/document.go +++ b/backend/internal/data/ent/document.go @@ -185,9 +185,3 @@ func (d *Document) String() string { // Documents is a parsable slice of Document. type Documents []*Document - -func (d Documents) config(cfg config) { - for _i := range d { - d[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/document_create.go b/backend/internal/data/ent/document_create.go index 81f5e8c..eabfc0f 100644 --- a/backend/internal/data/ent/document_create.go +++ b/backend/internal/data/ent/document_create.go @@ -208,13 +208,7 @@ func (dc *DocumentCreate) sqlSave(ctx context.Context) (*Document, error) { func (dc *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) { var ( _node = &Document{config: dc.config} - _spec = &sqlgraph.CreateSpec{ - Table: document.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(document.Table, sqlgraph.NewFieldSpec(document.FieldID, field.TypeUUID)) ) if id, ok := dc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/document_delete.go b/backend/internal/data/ent/document_delete.go index 0096d8e..d0481d3 100644 --- a/backend/internal/data/ent/document_delete.go +++ b/backend/internal/data/ent/document_delete.go @@ -40,15 +40,7 @@ func (dd *DocumentDelete) ExecX(ctx context.Context) int { } func (dd *DocumentDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: document.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(document.Table, sqlgraph.NewFieldSpec(document.FieldID, field.TypeUUID)) if ps := dd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/document_query.go b/backend/internal/data/ent/document_query.go index d2bde65..e22abe2 100644 --- a/backend/internal/data/ent/document_query.go +++ b/backend/internal/data/ent/document_query.go @@ -228,10 +228,12 @@ func (dq *DocumentQuery) AllX(ctx context.Context) []*Document { } // IDs executes the query and returns a list of Document IDs. -func (dq *DocumentQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := dq.Select(document.FieldID).Scan(ctx, &ids); err != nil { + if err = dq.Select(document.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -526,20 +528,12 @@ func (dq *DocumentQuery) sqlCount(ctx context.Context) (int, error) { } func (dq *DocumentQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: document.Table, - Columns: document.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - From: dq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeUUID)) + _spec.From = dq.sql if unique := dq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if dq.path != nil { + _spec.Unique = true } if fields := dq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/document_update.go b/backend/internal/data/ent/document_update.go index e685bda..a172e5f 100644 --- a/backend/internal/data/ent/document_update.go +++ b/backend/internal/data/ent/document_update.go @@ -165,16 +165,7 @@ func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := du.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: document.Table, - Columns: document.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeUUID)) if ps := du.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -376,6 +367,12 @@ func (duo *DocumentUpdateOne) RemoveAttachments(a ...*Attachment) *DocumentUpdat return duo.RemoveAttachmentIDs(ids...) } +// Where appends a list predicates to the DocumentUpdate builder. +func (duo *DocumentUpdateOne) Where(ps ...predicate.Document) *DocumentUpdateOne { + duo.mutation.Where(ps...) + return duo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (duo *DocumentUpdateOne) Select(field string, fields ...string) *DocumentUpdateOne { @@ -441,16 +438,7 @@ func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err if err := duo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: document.Table, - Columns: document.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: document.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(document.Table, document.Columns, sqlgraph.NewFieldSpec(document.FieldID, field.TypeUUID)) id, ok := duo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Document.id" for update`)} diff --git a/backend/internal/data/ent/group.go b/backend/internal/data/ent/group.go index 16dc988..25e1ce4 100644 --- a/backend/internal/data/ent/group.go +++ b/backend/internal/data/ent/group.go @@ -234,9 +234,3 @@ func (gr *Group) String() string { // Groups is a parsable slice of Group. type Groups []*Group - -func (gr Groups) config(cfg config) { - for _i := range gr { - gr[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/group_create.go b/backend/internal/data/ent/group_create.go index b13c358..9f0e90a 100644 --- a/backend/internal/data/ent/group_create.go +++ b/backend/internal/data/ent/group_create.go @@ -285,13 +285,7 @@ func (gc *GroupCreate) sqlSave(ctx context.Context) (*Group, error) { func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { var ( _node = &Group{config: gc.config} - _spec = &sqlgraph.CreateSpec{ - Table: group.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID)) ) if id, ok := gc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/group_delete.go b/backend/internal/data/ent/group_delete.go index eae02e2..29e0ffc 100644 --- a/backend/internal/data/ent/group_delete.go +++ b/backend/internal/data/ent/group_delete.go @@ -40,15 +40,7 @@ func (gd *GroupDelete) ExecX(ctx context.Context) int { } func (gd *GroupDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: group.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID)) if ps := gd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/group_query.go b/backend/internal/data/ent/group_query.go index a0f6d61..c9bef5f 100644 --- a/backend/internal/data/ent/group_query.go +++ b/backend/internal/data/ent/group_query.go @@ -323,10 +323,12 @@ func (gq *GroupQuery) AllX(ctx context.Context) []*Group { } // IDs executes the query and returns a list of Group IDs. -func (gq *GroupQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { + if err = gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -820,20 +822,12 @@ func (gq *GroupQuery) sqlCount(ctx context.Context) (int, error) { } func (gq *GroupQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: group.Table, - Columns: group.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, - }, - From: gq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID)) + _spec.From = gq.sql if unique := gq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if gq.path != nil { + _spec.Unique = true } if fields := gq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/group_update.go b/backend/internal/data/ent/group_update.go index e4263bf..1ff9cd6 100644 --- a/backend/internal/data/ent/group_update.go +++ b/backend/internal/data/ent/group_update.go @@ -337,16 +337,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := gu.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: group.Table, - Columns: group.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID)) if ps := gu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -954,6 +945,12 @@ func (guo *GroupUpdateOne) RemoveInvitationTokens(g ...*GroupInvitationToken) *G return guo.RemoveInvitationTokenIDs(ids...) } +// Where appends a list predicates to the GroupUpdate builder. +func (guo *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne { + guo.mutation.Where(ps...) + return guo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne { @@ -1016,16 +1013,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error if err := guo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: group.Table, - Columns: group.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID)) id, ok := guo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Group.id" for update`)} diff --git a/backend/internal/data/ent/groupinvitationtoken.go b/backend/internal/data/ent/groupinvitationtoken.go index 8f145d4..f8c2bb3 100644 --- a/backend/internal/data/ent/groupinvitationtoken.go +++ b/backend/internal/data/ent/groupinvitationtoken.go @@ -182,9 +182,3 @@ func (git *GroupInvitationToken) String() string { // GroupInvitationTokens is a parsable slice of GroupInvitationToken. type GroupInvitationTokens []*GroupInvitationToken - -func (git GroupInvitationTokens) config(cfg config) { - for _i := range git { - git[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/groupinvitationtoken_create.go b/backend/internal/data/ent/groupinvitationtoken_create.go index 01cd1c8..e45fb27 100644 --- a/backend/internal/data/ent/groupinvitationtoken_create.go +++ b/backend/internal/data/ent/groupinvitationtoken_create.go @@ -220,13 +220,7 @@ func (gitc *GroupInvitationTokenCreate) sqlSave(ctx context.Context) (*GroupInvi func (gitc *GroupInvitationTokenCreate) createSpec() (*GroupInvitationToken, *sqlgraph.CreateSpec) { var ( _node = &GroupInvitationToken{config: gitc.config} - _spec = &sqlgraph.CreateSpec{ - Table: groupinvitationtoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupinvitationtoken.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(groupinvitationtoken.Table, sqlgraph.NewFieldSpec(groupinvitationtoken.FieldID, field.TypeUUID)) ) if id, ok := gitc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/groupinvitationtoken_delete.go b/backend/internal/data/ent/groupinvitationtoken_delete.go index 1896841..1720383 100644 --- a/backend/internal/data/ent/groupinvitationtoken_delete.go +++ b/backend/internal/data/ent/groupinvitationtoken_delete.go @@ -40,15 +40,7 @@ func (gitd *GroupInvitationTokenDelete) ExecX(ctx context.Context) int { } func (gitd *GroupInvitationTokenDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: groupinvitationtoken.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupinvitationtoken.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(groupinvitationtoken.Table, sqlgraph.NewFieldSpec(groupinvitationtoken.FieldID, field.TypeUUID)) if ps := gitd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/groupinvitationtoken_query.go b/backend/internal/data/ent/groupinvitationtoken_query.go index ac1fc92..287b509 100644 --- a/backend/internal/data/ent/groupinvitationtoken_query.go +++ b/backend/internal/data/ent/groupinvitationtoken_query.go @@ -203,10 +203,12 @@ func (gitq *GroupInvitationTokenQuery) AllX(ctx context.Context) []*GroupInvitat } // IDs executes the query and returns a list of GroupInvitationToken IDs. -func (gitq *GroupInvitationTokenQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +func (gitq *GroupInvitationTokenQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if gitq.ctx.Unique == nil && gitq.path != nil { + gitq.Unique(true) + } ctx = setContextOp(ctx, gitq.ctx, "IDs") - if err := gitq.Select(groupinvitationtoken.FieldID).Scan(ctx, &ids); err != nil { + if err = gitq.Select(groupinvitationtoken.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -450,20 +452,12 @@ func (gitq *GroupInvitationTokenQuery) sqlCount(ctx context.Context) (int, error } func (gitq *GroupInvitationTokenQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: groupinvitationtoken.Table, - Columns: groupinvitationtoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupinvitationtoken.FieldID, - }, - }, - From: gitq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(groupinvitationtoken.Table, groupinvitationtoken.Columns, sqlgraph.NewFieldSpec(groupinvitationtoken.FieldID, field.TypeUUID)) + _spec.From = gitq.sql if unique := gitq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if gitq.path != nil { + _spec.Unique = true } if fields := gitq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/groupinvitationtoken_update.go b/backend/internal/data/ent/groupinvitationtoken_update.go index ac7cfd2..7a4caaa 100644 --- a/backend/internal/data/ent/groupinvitationtoken_update.go +++ b/backend/internal/data/ent/groupinvitationtoken_update.go @@ -144,16 +144,7 @@ func (gitu *GroupInvitationTokenUpdate) defaults() { } func (gitu *GroupInvitationTokenUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: groupinvitationtoken.Table, - Columns: groupinvitationtoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupinvitationtoken.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(groupinvitationtoken.Table, groupinvitationtoken.Columns, sqlgraph.NewFieldSpec(groupinvitationtoken.FieldID, field.TypeUUID)) if ps := gitu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -308,6 +299,12 @@ func (gituo *GroupInvitationTokenUpdateOne) ClearGroup() *GroupInvitationTokenUp return gituo } +// Where appends a list predicates to the GroupInvitationTokenUpdate builder. +func (gituo *GroupInvitationTokenUpdateOne) Where(ps ...predicate.GroupInvitationToken) *GroupInvitationTokenUpdateOne { + gituo.mutation.Where(ps...) + return gituo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (gituo *GroupInvitationTokenUpdateOne) Select(field string, fields ...string) *GroupInvitationTokenUpdateOne { @@ -352,16 +349,7 @@ func (gituo *GroupInvitationTokenUpdateOne) defaults() { } func (gituo *GroupInvitationTokenUpdateOne) sqlSave(ctx context.Context) (_node *GroupInvitationToken, err error) { - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: groupinvitationtoken.Table, - Columns: groupinvitationtoken.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupinvitationtoken.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(groupinvitationtoken.Table, groupinvitationtoken.Columns, sqlgraph.NewFieldSpec(groupinvitationtoken.FieldID, field.TypeUUID)) id, ok := gituo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GroupInvitationToken.id" for update`)} diff --git a/backend/internal/data/ent/item.go b/backend/internal/data/ent/item.go index 415b8b9..3ad36f3 100644 --- a/backend/internal/data/ent/item.go +++ b/backend/internal/data/ent/item.go @@ -525,9 +525,3 @@ func (i *Item) String() string { // Items is a parsable slice of Item. type Items []*Item - -func (i Items) config(cfg config) { - for _i := range i { - i[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/item_create.go b/backend/internal/data/ent/item_create.go index da36e66..d1a446e 100644 --- a/backend/internal/data/ent/item_create.go +++ b/backend/internal/data/ent/item_create.go @@ -665,13 +665,7 @@ func (ic *ItemCreate) sqlSave(ctx context.Context) (*Item, error) { func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) { var ( _node = &Item{config: ic.config} - _spec = &sqlgraph.CreateSpec{ - Table: item.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(item.Table, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) ) if id, ok := ic.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/item_delete.go b/backend/internal/data/ent/item_delete.go index b6f0d47..c2d00ff 100644 --- a/backend/internal/data/ent/item_delete.go +++ b/backend/internal/data/ent/item_delete.go @@ -40,15 +40,7 @@ func (id *ItemDelete) ExecX(ctx context.Context) int { } func (id *ItemDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: item.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(item.Table, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) if ps := id.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/item_query.go b/backend/internal/data/ent/item_query.go index 045c31f..c6af553 100644 --- a/backend/internal/data/ent/item_query.go +++ b/backend/internal/data/ent/item_query.go @@ -370,10 +370,12 @@ func (iq *ItemQuery) AllX(ctx context.Context) []*Item { } // IDs executes the query and returns a list of Item IDs. -func (iq *ItemQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := iq.Select(item.FieldID).Scan(ctx, &ids); err != nil { + if err = iq.Select(item.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -1000,20 +1002,12 @@ func (iq *ItemQuery) sqlCount(ctx context.Context) (int, error) { } func (iq *ItemQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: item.Table, - Columns: item.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldID, - }, - }, - From: iq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(item.Table, item.Columns, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) + _spec.From = iq.sql if unique := iq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if iq.path != nil { + _spec.Unique = true } if fields := iq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/item_update.go b/backend/internal/data/ent/item_update.go index 1d5ec90..88796e4 100644 --- a/backend/internal/data/ent/item_update.go +++ b/backend/internal/data/ent/item_update.go @@ -753,16 +753,7 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := iu.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: item.Table, - Columns: item.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(item.Table, item.Columns, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) if ps := iu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -1909,6 +1900,12 @@ func (iuo *ItemUpdateOne) RemoveAttachments(a ...*Attachment) *ItemUpdateOne { return iuo.RemoveAttachmentIDs(ids...) } +// Where appends a list predicates to the ItemUpdate builder. +func (iuo *ItemUpdateOne) Where(ps ...predicate.Item) *ItemUpdateOne { + iuo.mutation.Where(ps...) + return iuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (iuo *ItemUpdateOne) Select(field string, fields ...string) *ItemUpdateOne { @@ -2004,16 +2001,7 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) if err := iuo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: item.Table, - Columns: item.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(item.Table, item.Columns, sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID)) id, ok := iuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Item.id" for update`)} diff --git a/backend/internal/data/ent/itemfield.go b/backend/internal/data/ent/itemfield.go index 91b1195..cff6751 100644 --- a/backend/internal/data/ent/itemfield.go +++ b/backend/internal/data/ent/itemfield.go @@ -228,9 +228,3 @@ func (_if *ItemField) String() string { // ItemFields is a parsable slice of ItemField. type ItemFields []*ItemField - -func (_if ItemFields) config(cfg config) { - for _i := range _if { - _if[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/itemfield_create.go b/backend/internal/data/ent/itemfield_create.go index 32c5578..c124c0e 100644 --- a/backend/internal/data/ent/itemfield_create.go +++ b/backend/internal/data/ent/itemfield_create.go @@ -291,13 +291,7 @@ func (ifc *ItemFieldCreate) sqlSave(ctx context.Context) (*ItemField, error) { func (ifc *ItemFieldCreate) createSpec() (*ItemField, *sqlgraph.CreateSpec) { var ( _node = &ItemField{config: ifc.config} - _spec = &sqlgraph.CreateSpec{ - Table: itemfield.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: itemfield.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(itemfield.Table, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) ) if id, ok := ifc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/itemfield_delete.go b/backend/internal/data/ent/itemfield_delete.go index 5b9c139..181b736 100644 --- a/backend/internal/data/ent/itemfield_delete.go +++ b/backend/internal/data/ent/itemfield_delete.go @@ -40,15 +40,7 @@ func (ifd *ItemFieldDelete) ExecX(ctx context.Context) int { } func (ifd *ItemFieldDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: itemfield.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: itemfield.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(itemfield.Table, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) if ps := ifd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/itemfield_query.go b/backend/internal/data/ent/itemfield_query.go index ef8ca94..c00e422 100644 --- a/backend/internal/data/ent/itemfield_query.go +++ b/backend/internal/data/ent/itemfield_query.go @@ -203,10 +203,12 @@ func (ifq *ItemFieldQuery) AllX(ctx context.Context) []*ItemField { } // IDs executes the query and returns a list of ItemField IDs. -func (ifq *ItemFieldQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := ifq.Select(itemfield.FieldID).Scan(ctx, &ids); err != nil { + if err = ifq.Select(itemfield.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -450,20 +452,12 @@ func (ifq *ItemFieldQuery) sqlCount(ctx context.Context) (int, error) { } func (ifq *ItemFieldQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: itemfield.Table, - Columns: itemfield.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: itemfield.FieldID, - }, - }, - From: ifq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) + _spec.From = ifq.sql if unique := ifq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if ifq.path != nil { + _spec.Unique = true } if fields := ifq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/itemfield_update.go b/backend/internal/data/ent/itemfield_update.go index ec93a55..b7ff379 100644 --- a/backend/internal/data/ent/itemfield_update.go +++ b/backend/internal/data/ent/itemfield_update.go @@ -238,16 +238,7 @@ func (ifu *ItemFieldUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := ifu.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: itemfield.Table, - Columns: itemfield.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: itemfield.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) if ps := ifu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -489,6 +480,12 @@ func (ifuo *ItemFieldUpdateOne) ClearItem() *ItemFieldUpdateOne { return ifuo } +// Where appends a list predicates to the ItemFieldUpdate builder. +func (ifuo *ItemFieldUpdateOne) Where(ps ...predicate.ItemField) *ItemFieldUpdateOne { + ifuo.mutation.Where(ps...) + return ifuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (ifuo *ItemFieldUpdateOne) Select(field string, fields ...string) *ItemFieldUpdateOne { @@ -561,16 +558,7 @@ func (ifuo *ItemFieldUpdateOne) sqlSave(ctx context.Context) (_node *ItemField, if err := ifuo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: itemfield.Table, - Columns: itemfield.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: itemfield.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(itemfield.Table, itemfield.Columns, sqlgraph.NewFieldSpec(itemfield.FieldID, field.TypeUUID)) id, ok := ifuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ItemField.id" for update`)} diff --git a/backend/internal/data/ent/label.go b/backend/internal/data/ent/label.go index 22d5370..945b597 100644 --- a/backend/internal/data/ent/label.go +++ b/backend/internal/data/ent/label.go @@ -196,9 +196,3 @@ func (l *Label) String() string { // Labels is a parsable slice of Label. type Labels []*Label - -func (l Labels) config(cfg config) { - for _i := range l { - l[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/label_create.go b/backend/internal/data/ent/label_create.go index a9d8649..8df2903 100644 --- a/backend/internal/data/ent/label_create.go +++ b/backend/internal/data/ent/label_create.go @@ -232,13 +232,7 @@ func (lc *LabelCreate) sqlSave(ctx context.Context) (*Label, error) { func (lc *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) { var ( _node = &Label{config: lc.config} - _spec = &sqlgraph.CreateSpec{ - Table: label.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: label.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(label.Table, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) ) if id, ok := lc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/label_delete.go b/backend/internal/data/ent/label_delete.go index bd869cd..2f6e251 100644 --- a/backend/internal/data/ent/label_delete.go +++ b/backend/internal/data/ent/label_delete.go @@ -40,15 +40,7 @@ func (ld *LabelDelete) ExecX(ctx context.Context) int { } func (ld *LabelDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: label.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: label.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(label.Table, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) if ps := ld.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/label_query.go b/backend/internal/data/ent/label_query.go index ec6165e..925641b 100644 --- a/backend/internal/data/ent/label_query.go +++ b/backend/internal/data/ent/label_query.go @@ -228,10 +228,12 @@ func (lq *LabelQuery) AllX(ctx context.Context) []*Label { } // IDs executes the query and returns a list of Label IDs. -func (lq *LabelQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := lq.Select(label.FieldID).Scan(ctx, &ids); err != nil { + if err = lq.Select(label.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -556,20 +558,12 @@ func (lq *LabelQuery) sqlCount(ctx context.Context) (int, error) { } func (lq *LabelQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: label.Table, - Columns: label.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: label.FieldID, - }, - }, - From: lq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) + _spec.From = lq.sql if unique := lq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if lq.path != nil { + _spec.Unique = true } if fields := lq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/label_update.go b/backend/internal/data/ent/label_update.go index 5b40eb2..57464ff 100644 --- a/backend/internal/data/ent/label_update.go +++ b/backend/internal/data/ent/label_update.go @@ -204,16 +204,7 @@ func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := lu.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: label.Table, - Columns: label.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: label.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) if ps := lu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -458,6 +449,12 @@ func (luo *LabelUpdateOne) RemoveItems(i ...*Item) *LabelUpdateOne { return luo.RemoveItemIDs(ids...) } +// Where appends a list predicates to the LabelUpdate builder. +func (luo *LabelUpdateOne) Where(ps ...predicate.Label) *LabelUpdateOne { + luo.mutation.Where(ps...) + return luo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (luo *LabelUpdateOne) Select(field string, fields ...string) *LabelUpdateOne { @@ -528,16 +525,7 @@ func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error if err := luo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: label.Table, - Columns: label.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: label.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) id, ok := luo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Label.id" for update`)} diff --git a/backend/internal/data/ent/location.go b/backend/internal/data/ent/location.go index 0ac5d00..002cfb2 100644 --- a/backend/internal/data/ent/location.go +++ b/backend/internal/data/ent/location.go @@ -231,9 +231,3 @@ func (l *Location) String() string { // Locations is a parsable slice of Location. type Locations []*Location - -func (l Locations) config(cfg config) { - for _i := range l { - l[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/location_create.go b/backend/internal/data/ent/location_create.go index 72618cf..2fade30 100644 --- a/backend/internal/data/ent/location_create.go +++ b/backend/internal/data/ent/location_create.go @@ -247,13 +247,7 @@ func (lc *LocationCreate) sqlSave(ctx context.Context) (*Location, error) { func (lc *LocationCreate) createSpec() (*Location, *sqlgraph.CreateSpec) { var ( _node = &Location{config: lc.config} - _spec = &sqlgraph.CreateSpec{ - Table: location.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: location.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(location.Table, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) ) if id, ok := lc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/location_delete.go b/backend/internal/data/ent/location_delete.go index 24e0ff5..67a2adc 100644 --- a/backend/internal/data/ent/location_delete.go +++ b/backend/internal/data/ent/location_delete.go @@ -40,15 +40,7 @@ func (ld *LocationDelete) ExecX(ctx context.Context) int { } func (ld *LocationDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: location.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: location.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(location.Table, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) if ps := ld.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/location_query.go b/backend/internal/data/ent/location_query.go index 5b8647d..916215b 100644 --- a/backend/internal/data/ent/location_query.go +++ b/backend/internal/data/ent/location_query.go @@ -274,10 +274,12 @@ func (lq *LocationQuery) AllX(ctx context.Context) []*Location { } // IDs executes the query and returns a list of Location IDs. -func (lq *LocationQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := lq.Select(location.FieldID).Scan(ctx, &ids); err != nil { + if err = lq.Select(location.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -674,20 +676,12 @@ func (lq *LocationQuery) sqlCount(ctx context.Context) (int, error) { } func (lq *LocationQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: location.Table, - Columns: location.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: location.FieldID, - }, - }, - From: lq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) + _spec.From = lq.sql if unique := lq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if lq.path != nil { + _spec.Unique = true } if fields := lq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/location_update.go b/backend/internal/data/ent/location_update.go index 6833208..b67f7e4 100644 --- a/backend/internal/data/ent/location_update.go +++ b/backend/internal/data/ent/location_update.go @@ -240,16 +240,7 @@ func (lu *LocationUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := lu.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: location.Table, - Columns: location.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: location.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) if ps := lu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -618,6 +609,12 @@ func (luo *LocationUpdateOne) RemoveItems(i ...*Item) *LocationUpdateOne { return luo.RemoveItemIDs(ids...) } +// Where appends a list predicates to the LocationUpdate builder. +func (luo *LocationUpdateOne) Where(ps ...predicate.Location) *LocationUpdateOne { + luo.mutation.Where(ps...) + return luo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (luo *LocationUpdateOne) Select(field string, fields ...string) *LocationUpdateOne { @@ -683,16 +680,7 @@ func (luo *LocationUpdateOne) sqlSave(ctx context.Context) (_node *Location, err if err := luo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: location.Table, - Columns: location.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: location.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(location.Table, location.Columns, sqlgraph.NewFieldSpec(location.FieldID, field.TypeUUID)) id, ok := luo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Location.id" for update`)} diff --git a/backend/internal/data/ent/maintenanceentry.go b/backend/internal/data/ent/maintenanceentry.go index c0f6a4e..b571bce 100644 --- a/backend/internal/data/ent/maintenanceentry.go +++ b/backend/internal/data/ent/maintenanceentry.go @@ -194,9 +194,3 @@ func (me *MaintenanceEntry) String() string { // MaintenanceEntries is a parsable slice of MaintenanceEntry. type MaintenanceEntries []*MaintenanceEntry - -func (me MaintenanceEntries) config(cfg config) { - for _i := range me { - me[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/maintenanceentry_create.go b/backend/internal/data/ent/maintenanceentry_create.go index a7a6a94..ef5602b 100644 --- a/backend/internal/data/ent/maintenanceentry_create.go +++ b/backend/internal/data/ent/maintenanceentry_create.go @@ -242,13 +242,7 @@ func (mec *MaintenanceEntryCreate) sqlSave(ctx context.Context) (*MaintenanceEnt func (mec *MaintenanceEntryCreate) createSpec() (*MaintenanceEntry, *sqlgraph.CreateSpec) { var ( _node = &MaintenanceEntry{config: mec.config} - _spec = &sqlgraph.CreateSpec{ - Table: maintenanceentry.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: maintenanceentry.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(maintenanceentry.Table, sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID)) ) if id, ok := mec.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/maintenanceentry_delete.go b/backend/internal/data/ent/maintenanceentry_delete.go index cdfe480..d65ed8b 100644 --- a/backend/internal/data/ent/maintenanceentry_delete.go +++ b/backend/internal/data/ent/maintenanceentry_delete.go @@ -40,15 +40,7 @@ func (med *MaintenanceEntryDelete) ExecX(ctx context.Context) int { } func (med *MaintenanceEntryDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: maintenanceentry.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: maintenanceentry.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(maintenanceentry.Table, sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID)) if ps := med.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/maintenanceentry_query.go b/backend/internal/data/ent/maintenanceentry_query.go index 114f8d9..52c8504 100644 --- a/backend/internal/data/ent/maintenanceentry_query.go +++ b/backend/internal/data/ent/maintenanceentry_query.go @@ -202,10 +202,12 @@ func (meq *MaintenanceEntryQuery) AllX(ctx context.Context) []*MaintenanceEntry } // IDs executes the query and returns a list of MaintenanceEntry IDs. -func (meq *MaintenanceEntryQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +func (meq *MaintenanceEntryQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if meq.ctx.Unique == nil && meq.path != nil { + meq.Unique(true) + } ctx = setContextOp(ctx, meq.ctx, "IDs") - if err := meq.Select(maintenanceentry.FieldID).Scan(ctx, &ids); err != nil { + if err = meq.Select(maintenanceentry.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -439,20 +441,12 @@ func (meq *MaintenanceEntryQuery) sqlCount(ctx context.Context) (int, error) { } func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: maintenanceentry.Table, - Columns: maintenanceentry.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: maintenanceentry.FieldID, - }, - }, - From: meq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(maintenanceentry.Table, maintenanceentry.Columns, sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID)) + _spec.From = meq.sql if unique := meq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if meq.path != nil { + _spec.Unique = true } if fields := meq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/maintenanceentry_update.go b/backend/internal/data/ent/maintenanceentry_update.go index d4c3ee3..cade06b 100644 --- a/backend/internal/data/ent/maintenanceentry_update.go +++ b/backend/internal/data/ent/maintenanceentry_update.go @@ -177,16 +177,7 @@ func (meu *MaintenanceEntryUpdate) sqlSave(ctx context.Context) (n int, err erro if err := meu.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: maintenanceentry.Table, - Columns: maintenanceentry.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: maintenanceentry.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(maintenanceentry.Table, maintenanceentry.Columns, sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID)) if ps := meu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -359,6 +350,12 @@ func (meuo *MaintenanceEntryUpdateOne) ClearItem() *MaintenanceEntryUpdateOne { return meuo } +// Where appends a list predicates to the MaintenanceEntryUpdate builder. +func (meuo *MaintenanceEntryUpdateOne) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryUpdateOne { + meuo.mutation.Where(ps...) + return meuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (meuo *MaintenanceEntryUpdateOne) Select(field string, fields ...string) *MaintenanceEntryUpdateOne { @@ -424,16 +421,7 @@ func (meuo *MaintenanceEntryUpdateOne) sqlSave(ctx context.Context) (_node *Main if err := meuo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: maintenanceentry.Table, - Columns: maintenanceentry.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: maintenanceentry.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(maintenanceentry.Table, maintenanceentry.Columns, sqlgraph.NewFieldSpec(maintenanceentry.FieldID, field.TypeUUID)) id, ok := meuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MaintenanceEntry.id" for update`)} diff --git a/backend/internal/data/ent/runtime/runtime.go b/backend/internal/data/ent/runtime/runtime.go index 84a815f..f6cb4c1 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/hay-kot/homebox/backend/internal/data/ent/runtime.go const ( - Version = "v0.11.7" // Version of ent codegen. - Sum = "h1:V+wKFh0jhAbY/FoU+PPbdMOf2Ma5vh07R/IdF+N/nFg=" // Sum of ent codegen. + Version = "v0.11.8" // Version of ent codegen. + Sum = "h1:M/M0QL1CYCUSdqGRXUrXhFYSDRJPsOOrr+RLEej/gyQ=" // Sum of ent codegen. ) diff --git a/backend/internal/data/ent/user.go b/backend/internal/data/ent/user.go index cd4709b..97a9279 100644 --- a/backend/internal/data/ent/user.go +++ b/backend/internal/data/ent/user.go @@ -241,9 +241,3 @@ func (u *User) String() string { // Users is a parsable slice of User. type Users []*User - -func (u Users) config(cfg config) { - for _i := range u { - u[_i].config = cfg - } -} diff --git a/backend/internal/data/ent/user_create.go b/backend/internal/data/ent/user_create.go index 367ff07..3dc703d 100644 --- a/backend/internal/data/ent/user_create.go +++ b/backend/internal/data/ent/user_create.go @@ -304,13 +304,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) { func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { var ( _node = &User{config: uc.config} - _spec = &sqlgraph.CreateSpec{ - Table: user.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, - } + _spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID)) ) if id, ok := uc.mutation.ID(); ok { _node.ID = id diff --git a/backend/internal/data/ent/user_delete.go b/backend/internal/data/ent/user_delete.go index 0f2d066..4e38aab 100644 --- a/backend/internal/data/ent/user_delete.go +++ b/backend/internal/data/ent/user_delete.go @@ -40,15 +40,7 @@ func (ud *UserDelete) ExecX(ctx context.Context) int { } func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) { - _spec := &sqlgraph.DeleteSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, - }, - } + _spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID)) if ps := ud.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/backend/internal/data/ent/user_query.go b/backend/internal/data/ent/user_query.go index 151b5cb..a722f2e 100644 --- a/backend/internal/data/ent/user_query.go +++ b/backend/internal/data/ent/user_query.go @@ -228,10 +228,12 @@ func (uq *UserQuery) AllX(ctx context.Context) []*User { } // IDs executes the query and returns a list of User IDs. -func (uq *UserQuery) IDs(ctx context.Context) ([]uuid.UUID, error) { - var ids []uuid.UUID +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") - if err := uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { + if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil @@ -526,20 +528,12 @@ func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) { } func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec { - _spec := &sqlgraph.QuerySpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, - }, - From: uq.sql, - Unique: true, - } + _spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID)) + _spec.From = uq.sql if unique := uq.ctx.Unique; unique != nil { _spec.Unique = *unique + } else if uq.path != nil { + _spec.Unique = true } if fields := uq.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) diff --git a/backend/internal/data/ent/user_update.go b/backend/internal/data/ent/user_update.go index f453d37..4bb0296 100644 --- a/backend/internal/data/ent/user_update.go +++ b/backend/internal/data/ent/user_update.go @@ -243,16 +243,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { if err := uu.check(); err != nil { return n, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID)) if ps := uu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -540,6 +531,12 @@ func (uuo *UserUpdateOne) RemoveAuthTokens(a ...*AuthTokens) *UserUpdateOne { return uuo.RemoveAuthTokenIDs(ids...) } +// Where appends a list predicates to the UserUpdate builder. +func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne { + uuo.mutation.Where(ps...) + return uuo +} + // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne { @@ -615,16 +612,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) if err := uuo.check(); err != nil { return _node, err } - _spec := &sqlgraph.UpdateSpec{ - Node: &sqlgraph.NodeSpec{ - Table: user.Table, - Columns: user.Columns, - ID: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, - }, - } + _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID)) id, ok := uuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)} diff --git a/backend/internal/data/migrations/migrations.go b/backend/internal/data/migrations/migrations.go index fba84c5..d477df9 100644 --- a/backend/internal/data/migrations/migrations.go +++ b/backend/internal/data/migrations/migrations.go @@ -13,7 +13,7 @@ var Files embed.FS // It returns an error and a cleanup function. The cleanup function // should be called when the migrations are no longer needed. func Write(temp string) error { - err := os.MkdirAll(temp, 0755) + err := os.MkdirAll(temp, 0o755) if err != nil { return err } @@ -33,7 +33,7 @@ func Write(temp string) error { return err } - err = os.WriteFile(filepath.Join(temp, f.Name()), b, 0644) + err = os.WriteFile(filepath.Join(temp, f.Name()), b, 0o644) if err != nil { return err } diff --git a/backend/internal/data/repo/repo_documents.go b/backend/internal/data/repo/repo_documents.go index abe340d..587a4f1 100644 --- a/backend/internal/data/repo/repo_documents.go +++ b/backend/internal/data/repo/repo_documents.go @@ -14,9 +14,7 @@ import ( "github.com/hay-kot/homebox/backend/pkgs/pathlib" ) -var ( - ErrInvalidDocExtension = errors.New("invalid document extension") -) +var ErrInvalidDocExtension = errors.New("invalid document extension") type DocumentRepository struct { db *ent.Client @@ -74,7 +72,7 @@ func (r *DocumentRepository) Create(ctx context.Context, gid uuid.UUID, doc Docu path := r.path(gid, ext) parent := filepath.Dir(path) - err := os.MkdirAll(parent, 0755) + err := os.MkdirAll(parent, 0o755) if err != nil { return DocumentOut{}, err } diff --git a/backend/internal/data/repo/repo_documents_test.go b/backend/internal/data/repo/repo_documents_test.go index b58b3bb..2a22fac 100644 --- a/backend/internal/data/repo/repo_documents_test.go +++ b/backend/internal/data/repo/repo_documents_test.go @@ -34,7 +34,6 @@ func useDocs(t *testing.T, num int) []DocumentOut { t.Cleanup(func() { for _, id := range ids { err := tRepos.Docs.Delete(context.Background(), id) - if err != nil { assert.True(t, ent.IsNotFound(err)) } diff --git a/backend/internal/data/repo/repo_group.go b/backend/internal/data/repo/repo_group.go index 8e5ea14..678130c 100644 --- a/backend/internal/data/repo/repo_group.go +++ b/backend/internal/data/repo/repo_group.go @@ -76,9 +76,7 @@ type ( } ) -var ( - mapToGroupErr = mapTErrFunc(mapToGroup) -) +var mapToGroupErr = mapTErrFunc(mapToGroup) func mapToGroup(g *ent.Group) Group { return Group{ @@ -90,9 +88,7 @@ func mapToGroup(g *ent.Group) Group { } } -var ( - mapToGroupInvitationErr = mapTErrFunc(mapToGroupInvitation) -) +var mapToGroupInvitationErr = mapTErrFunc(mapToGroupInvitation) func mapToGroupInvitation(g *ent.GroupInvitationToken) GroupInvitation { return GroupInvitation{ @@ -118,7 +114,6 @@ func (r *GroupRepository) StatsLocationsByPurchasePrice(ctx context.Context, GID return sql.As(sql.Sum(t.C(item.FieldPurchasePrice)), "total") }). Scan(ctx, &v) - if err != nil { return nil, err } @@ -145,7 +140,6 @@ func (r *GroupRepository) StatsLabelsByPurchasePrice(ctx context.Context, GID uu return sql.As(sql.Sum(itemTable.C(item.FieldPurchasePrice)), "total") }). Scan(ctx, &v) - if err != nil { return nil, err } @@ -283,7 +277,6 @@ func (r *GroupRepository) InvitationCreate(ctx context.Context, groupID uuid.UUI SetExpiresAt(invite.ExpiresAt). SetUses(invite.Uses). Save(ctx) - if err != nil { return GroupInvitation{}, err } diff --git a/backend/internal/data/repo/repo_item_attachments.go b/backend/internal/data/repo/repo_item_attachments.go index 1e2ef7b..a034369 100644 --- a/backend/internal/data/repo/repo_item_attachments.go +++ b/backend/internal/data/repo/repo_item_attachments.go @@ -68,7 +68,6 @@ func (r *AttachmentRepo) Update(ctx context.Context, itemId uuid.UUID, typ attac itm, err := r.db.Attachment.UpdateOneID(itemId). SetType(typ). Save(ctx) - if err != nil { return nil, err } diff --git a/backend/internal/data/repo/repo_item_attachments_test.go b/backend/internal/data/repo/repo_item_attachments_test.go index 15f70c8..4c9d77d 100644 --- a/backend/internal/data/repo/repo_item_attachments_test.go +++ b/backend/internal/data/repo/repo_item_attachments_test.go @@ -58,7 +58,6 @@ func TestAttachmentRepo_Create(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := tRepos.Attachments.Create(tt.args.ctx, tt.args.itemId, tt.args.docId, tt.args.typ) if (err != nil) != tt.wantErr { t.Errorf("AttachmentRepo.Create() error = %v, wantErr %v", err, tt.wantErr) @@ -119,7 +118,6 @@ func TestAttachmentRepo_Update(t *testing.T) { assert.Equal(t, typ, updated.Type) }) } - } func TestAttachmentRepo_Delete(t *testing.T) { diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 4b67b97..5e73565 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -45,7 +45,7 @@ type ( TextValue string `json:"textValue"` NumberValue int `json:"numberValue"` BooleanValue bool `json:"booleanValue"` - TimeValue time.Time `json:"timeValue,omitempty"` + // TimeValue time.Time `json:"timeValue,omitempty"` } ItemCreate struct { @@ -150,9 +150,7 @@ type ( } ) -var ( - mapItemsSummaryErr = mapTEachErrFunc(mapItemSummary) -) +var mapItemsSummaryErr = mapTEachErrFunc(mapItemSummary) func mapItemSummary(item *ent.Item) ItemSummary { var location *LocationSummary @@ -200,7 +198,7 @@ func mapFields(fields []*ent.ItemField) []ItemField { TextValue: f.TextValue, NumberValue: f.NumberValue, BooleanValue: f.BooleanValue, - TimeValue: f.TimeValue, + // TimeValue: f.TimeValue, } } return result @@ -371,7 +369,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite } count, err := qb.Count(ctx) - if err != nil { return PaginationResult[ItemSummary]{}, err } @@ -387,7 +384,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite } items, err := mapItemsSummaryErr(qb.All(ctx)) - if err != nil { return PaginationResult[ItemSummary]{}, err } @@ -398,7 +394,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite Total: count, Items: items, }, nil - } // QueryByAssetID returns items by asset ID. If the item does not exist, an error is returned. @@ -422,7 +417,6 @@ func (e *ItemsRepository) QueryByAssetID(ctx context.Context, gid uuid.UUID, ass WithLocation(). All(ctx), ) - if err != nil { return PaginationResult[ItemSummary]{}, err } @@ -441,6 +435,7 @@ func (e *ItemsRepository) GetAll(ctx context.Context, gid uuid.UUID) ([]ItemOut, Where(item.HasGroupWith(group.ID(gid))). WithLabel(). WithLocation(). + WithFields(). All(ctx)) } @@ -590,7 +585,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data SetTextValue(f.TextValue). SetNumberValue(f.NumberValue). SetBooleanValue(f.BooleanValue). - SetTimeValue(f.TimeValue). + // SetTimeValue(f.TimeValue). Save(ctx) if err != nil { return ItemOut{}, err @@ -606,8 +601,8 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data SetName(f.Name). SetTextValue(f.TextValue). SetNumberValue(f.NumberValue). - SetBooleanValue(f.BooleanValue). - SetTimeValue(f.TimeValue) + SetBooleanValue(f.BooleanValue) + // SetTimeValue(f.TimeValue) _, err = opt.Save(ctx) if err != nil { @@ -651,7 +646,6 @@ func (e *ItemsRepository) GetAllCustomFieldValues(ctx context.Context, GID uuid. Unique(true). Select(itemfield.FieldTextValue). Scan(ctx, &values) - if err != nil { return nil, fmt.Errorf("failed to get field values: %w", err) } @@ -679,7 +673,6 @@ func (e *ItemsRepository) GetAllCustomFieldNames(ctx context.Context, GID uuid.U Unique(true). Select(itemfield.FieldName). Scan(ctx, &fields) - if err != nil { return nil, fmt.Errorf("failed to get custom fields: %w", err) } diff --git a/backend/internal/data/repo/repo_items_test.go b/backend/internal/data/repo/repo_items_test.go index 3236537..ac2814d 100644 --- a/backend/internal/data/repo/repo_items_test.go +++ b/backend/internal/data/repo/repo_items_test.go @@ -125,7 +125,6 @@ func TestItemsRepository_Create(t *testing.T) { // Cleanup - Also deletes item err = tRepos.Locations.Delete(context.Background(), location.ID) assert.NoError(t, err) - } func TestItemsRepository_Create_Location(t *testing.T) { @@ -222,7 +221,6 @@ func TestItemsRepository_Update_Labels(t *testing.T) { } }) } - } func TestItemsRepository_Update(t *testing.T) { diff --git a/backend/internal/data/repo/repo_labels.go b/backend/internal/data/repo/repo_labels.go index 9d5b11a..a761ef8 100644 --- a/backend/internal/data/repo/repo_labels.go +++ b/backend/internal/data/repo/repo_labels.go @@ -100,7 +100,6 @@ func (r *LabelRepository) Create(ctx context.Context, groupdId uuid.UUID, data L SetColor(data.Color). SetGroupID(groupdId). Save(ctx) - if err != nil { return LabelOut{}, err } diff --git a/backend/internal/data/repo/repo_locations.go b/backend/internal/data/repo/repo_locations.go index 4e72008..2d3ea56 100644 --- a/backend/internal/data/repo/repo_locations.go +++ b/backend/internal/data/repo/repo_locations.go @@ -62,9 +62,7 @@ func mapLocationSummary(location *ent.Location) LocationSummary { } } -var ( - mapLocationOutErr = mapTErrFunc(mapLocationOut) -) +var mapLocationOutErr = mapTErrFunc(mapLocationOut) func mapLocationOut(location *ent.Location) LocationOut { var parent *LocationSummary @@ -181,7 +179,6 @@ func (r *LocationRepository) Create(ctx context.Context, GID uuid.UUID, data Loc } location, err := q.Save(ctx) - if err != nil { return LocationOut{}, err } @@ -322,7 +319,7 @@ func (lr *LocationRepository) Tree(ctx context.Context, GID uuid.UUID, tq TreeQu } func ConvertLocationsToTree(locations []FlatTreeItem) []TreeItem { - var locationMap = make(map[uuid.UUID]*TreeItem, len(locations)) + locationMap := make(map[uuid.UUID]*TreeItem, len(locations)) var rootIds []uuid.UUID diff --git a/backend/internal/data/repo/repo_locations_test.go b/backend/internal/data/repo/repo_locations_test.go index 1ef2295..0334a42 100644 --- a/backend/internal/data/repo/repo_locations_test.go +++ b/backend/internal/data/repo/repo_locations_test.go @@ -31,7 +31,6 @@ func useLocations(t *testing.T, len int) []LocationOut { t.Cleanup(func() { for _, loc := range out { err := tRepos.Locations.Delete(context.Background(), loc.ID) - if err != nil { assert.True(t, ent.IsNotFound(err)) } @@ -74,7 +73,6 @@ func TestLocationRepositoryGetAllWithCount(t *testing.T) { assert.Equal(t, 1, loc.ItemCount) } } - } func TestLocationRepository_Create(t *testing.T) { diff --git a/backend/internal/data/repo/repo_maintenance_entry.go b/backend/internal/data/repo/repo_maintenance_entry.go index 175bd7e..5f95e50 100644 --- a/backend/internal/data/repo/repo_maintenance_entry.go +++ b/backend/internal/data/repo/repo_maintenance_entry.go @@ -93,7 +93,6 @@ func (r *MaintenanceEntryRepository) GetLog(ctx context.Context, itemID uuid.UUI Where(maintenanceentry.ItemID(itemID)). Order(ent.Desc(maintenanceentry.FieldDate)). All(ctx) - if err != nil { return MaintenanceLog{}, err } diff --git a/backend/internal/data/repo/repo_maintenance_entry_test.go b/backend/internal/data/repo/repo_maintenance_entry_test.go index e3df3d0..bc9f6af 100644 --- a/backend/internal/data/repo/repo_maintenance_entry_test.go +++ b/backend/internal/data/repo/repo_maintenance_entry_test.go @@ -61,7 +61,6 @@ func TestMaintenanceEntryRepository_GetLog(t *testing.T) { // Get the log for the item log, err := tRepos.MaintEntry.GetLog(context.Background(), item.ID) - if err != nil { t.Fatalf("failed to get maintenance log: %v", err) } diff --git a/backend/internal/data/repo/repo_tokens.go b/backend/internal/data/repo/repo_tokens.go index 5820227..7ba982e 100644 --- a/backend/internal/data/repo/repo_tokens.go +++ b/backend/internal/data/repo/repo_tokens.go @@ -42,7 +42,6 @@ func (r *TokenRepository) GetUserFromToken(ctx context.Context, token []byte) (U QueryUser(). WithGroup(). Only(ctx) - if err != nil { return UserOut{}, err } @@ -59,7 +58,6 @@ func (r *TokenRepository) GetRoles(ctx context.Context, token string) (*set.Set[ authtokens.Token(tokenHash), )). All(ctx) - if err != nil { return nil, err } @@ -80,7 +78,6 @@ func (r *TokenRepository) CreateToken(ctx context.Context, createToken UserAuthT SetUserID(createToken.UserID). SetExpiresAt(createToken.ExpiresAt). Save(ctx) - if err != nil { return UserAuthToken{}, err } @@ -90,7 +87,6 @@ func (r *TokenRepository) CreateToken(ctx context.Context, createToken UserAuthT SetRole(role). SetToken(dbToken). Save(ctx) - if err != nil { return UserAuthToken{}, err } @@ -115,7 +111,6 @@ func (r *TokenRepository) DeleteToken(ctx context.Context, token []byte) error { // PurgeExpiredTokens removes all expired tokens from the database func (r *TokenRepository) PurgeExpiredTokens(ctx context.Context) (int, error) { tokensDeleted, err := r.db.AuthTokens.Delete().Where(authtokens.ExpiresAtLTE(time.Now())).Exec(ctx) - if err != nil { return 0, err } diff --git a/backend/internal/data/repo/repo_users.go b/backend/internal/data/repo/repo_users.go index 28407f1..03850d6 100644 --- a/backend/internal/data/repo/repo_users.go +++ b/backend/internal/data/repo/repo_users.go @@ -123,7 +123,6 @@ func (e *UserRepository) DeleteAll(ctx context.Context) error { func (e *UserRepository) GetSuperusers(ctx context.Context) ([]*ent.User, error) { users, err := e.db.User.Query().Where(user.IsSuperuser(true)).All(ctx) - if err != nil { return nil, err } diff --git a/backend/internal/data/repo/repo_users_test.go b/backend/internal/data/repo/repo_users_test.go index 882de1c..31d2737 100644 --- a/backend/internal/data/repo/repo_users_test.go +++ b/backend/internal/data/repo/repo_users_test.go @@ -139,7 +139,6 @@ func TestUserRepo_Delete(t *testing.T) { allUsers, _ = tRepos.Users.GetAll(ctx) assert.Equal(t, len(allUsers), 0) - } func TestUserRepo_GetSuperusers(t *testing.T) { diff --git a/backend/internal/data/types/date.go b/backend/internal/data/types/date.go index 6aff82f..0dc09db 100644 --- a/backend/internal/data/types/date.go +++ b/backend/internal/data/types/date.go @@ -1,6 +1,11 @@ package types -import "time" +import ( + "errors" + "fmt" + "strings" + "time" +) // Date is a custom type that implements the MarshalJSON interface // that applies date only formatting to the time.Time fields in order @@ -34,17 +39,20 @@ func DateFromString(s string) Date { return Date{} } - t, err := time.Parse("2006-01-02", s) - if err != nil { - // TODO: Remove - used by legacy importer - t, err = time.Parse("01/02/2006", s) + try := [...]string{ + "2006-01-02", + "01/02/2006", + time.RFC3339, + } - if err != nil { - return Date{} + for _, format := range try { + t, err := time.Parse(format, s) + if err == nil { + return DateFromTime(t) } } - return DateFromTime(t) + return Date{} } func (d Date) String() string { @@ -63,24 +71,37 @@ func (d Date) MarshalJSON() ([]byte, error) { return []byte(`"` + d.String() + `"`), nil } -func (d *Date) UnmarshalJSON(data []byte) error { - str := string(data) - if str == `""` { +func (d *Date) UnmarshalJSON(data []byte) (err error) { + // unescape the string if necessary `\"` -> `"` + str := strings.Trim(string(data), "\"") + fmt.Printf("str: %q\n", str) + if str == "" || str == "null" || str == `""` { + println("empty date") *d = Date{} return nil } - // Try YYYY-MM-DD format + try := [...]string{ + "2006-01-02", + "01/02/2006", + time.RFC3339, + } + + set := false var t time.Time - t, err := time.Parse("2006-01-02", str) - if err != nil { - // Try default interface - err = t.UnmarshalJSON(data) - if err != nil { - return err + + for _, format := range try { + t, err = time.Parse(format, str) + if err == nil { + set = true + break } } + if !set { + return errors.New("invalid date format") + } + // strip the time and timezone information *d = DateFromTime(t) diff --git a/backend/internal/sys/config/conf.go b/backend/internal/sys/config/conf.go index a7a17f0..c1655c2 100644 --- a/backend/internal/sys/config/conf.go +++ b/backend/internal/sys/config/conf.go @@ -4,10 +4,9 @@ import ( "encoding/json" "errors" "fmt" + "os" "github.com/ardanlabs/conf/v3" - - "os" ) const ( @@ -55,7 +54,6 @@ func New() (*Config, error) { const prefix = "HBOX" help, err := conf.Parse(prefix, &cfg) - if err != nil { if errors.Is(err, conf.ErrHelpWanted) { fmt.Println(help) @@ -71,11 +69,9 @@ func New() (*Config, error) { // This is useful for debugging. If the marshaller errors out, it will panic. func (c *Config) Print() { res, err := json.MarshalIndent(c, "", " ") - if err != nil { panic(err) } fmt.Println(string(res)) - } diff --git a/backend/internal/sys/config/conf_mailer_test.go b/backend/internal/sys/config/conf_mailer_test.go index 8656755..6bf7c74 100644 --- a/backend/internal/sys/config/conf_mailer_test.go +++ b/backend/internal/sys/config/conf_mailer_test.go @@ -36,5 +36,4 @@ func Test_MailerReady_Failure(t *testing.T) { mc.From = "from" assert.True(t, mc.Ready()) - } diff --git a/backend/internal/sys/validate/errors.go b/backend/internal/sys/validate/errors.go index d08a448..b5c101a 100644 --- a/backend/internal/sys/validate/errors.go +++ b/backend/internal/sys/validate/errors.go @@ -5,8 +5,7 @@ import ( "errors" ) -type UnauthorizedError struct { -} +type UnauthorizedError struct{} func (err *UnauthorizedError) Error() string { return "unauthorized" diff --git a/backend/internal/sys/validate/validate.go b/backend/internal/sys/validate/validate.go index ed22c0f..4a4b7a9 100644 --- a/backend/internal/sys/validate/validate.go +++ b/backend/internal/sys/validate/validate.go @@ -14,7 +14,6 @@ func init() { // FieldErrors array and returned. func Check(val any) error { err := validate.Struct(val) - if err != nil { verrors, ok := err.(validator.ValidationErrors) if !ok { diff --git a/backend/internal/web/mid/errors.go b/backend/internal/web/mid/errors.go index 7aa659c..dc716c9 100644 --- a/backend/internal/web/mid/errors.go +++ b/backend/internal/web/mid/errors.go @@ -13,7 +13,6 @@ func Errors(log zerolog.Logger) server.Middleware { return func(h server.Handler) server.Handler { return server.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { err := h.ServeHTTP(w, r) - if err != nil { var resp server.ErrorResponse var code int diff --git a/backend/internal/web/mid/logger.go b/backend/internal/web/mid/logger.go index 86b8cdb..fb39c67 100644 --- a/backend/internal/web/mid/logger.go +++ b/backend/internal/web/mid/logger.go @@ -76,7 +76,6 @@ func SugarLogger(log zerolog.Logger) server.Middleware { return func(next server.Handler) server.Handler { return server.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error { - record := &statusRecorder{ResponseWriter: w, Status: http.StatusOK} err := next.ServeHTTP(record, r) // Blocks until the next handler returns. diff --git a/backend/pkgs/faker/random.go b/backend/pkgs/faker/random.go index 67c7114..e7b51b9 100644 --- a/backend/pkgs/faker/random.go +++ b/backend/pkgs/faker/random.go @@ -7,8 +7,7 @@ import ( var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") -type Faker struct { -} +type Faker struct{} func NewFaker() *Faker { rand.Seed(time.Now().UnixNano()) @@ -20,7 +19,6 @@ func (f *Faker) Time() time.Time { } func (f *Faker) Str(length int) string { - b := make([]rune, length) for i := range b { b[i] = letters[rand.Intn(len(letters))] diff --git a/backend/pkgs/faker/randoms_test.go b/backend/pkgs/faker/randoms_test.go index 0773205..c03c564 100644 --- a/backend/pkgs/faker/randoms_test.go +++ b/backend/pkgs/faker/randoms_test.go @@ -20,7 +20,7 @@ func ValidateUnique(values []string) bool { func Test_GetRandomString(t *testing.T) { t.Parallel() // Test that the function returns a string of the correct length - var generated = make([]string, Loops) + generated := make([]string, Loops) faker := NewFaker() @@ -36,7 +36,7 @@ func Test_GetRandomString(t *testing.T) { func Test_GetRandomEmail(t *testing.T) { t.Parallel() // Test that the function returns a string of the correct length - var generated = make([]string, Loops) + generated := make([]string, Loops) faker := NewFaker() @@ -52,8 +52,8 @@ func Test_GetRandomEmail(t *testing.T) { func Test_GetRandomBool(t *testing.T) { t.Parallel() - var trues = 0 - var falses = 0 + trues := 0 + falses := 0 faker := NewFaker() @@ -91,5 +91,4 @@ func Test_RandomNumber(t *testing.T) { t.Errorf("RandomNumber() failed to generate a number between %v and %v", MIN, MAX) } } - } diff --git a/backend/pkgs/mailer/mailer_test.go b/backend/pkgs/mailer/mailer_test.go index 87a0b60..3e67a68 100644 --- a/backend/pkgs/mailer/mailer_test.go +++ b/backend/pkgs/mailer/mailer_test.go @@ -30,14 +30,12 @@ func GetTestMailer() (*Mailer, error) { } return mailer, nil - } func Test_Mailer(t *testing.T) { t.Parallel() mailer, err := GetTestMailer() - if err != nil { t.Skip("Error Reading Test Mailer Config - Skipping") } @@ -47,7 +45,6 @@ func Test_Mailer(t *testing.T) { } message, err := RenderWelcome() - if err != nil { t.Error(err) } diff --git a/backend/pkgs/mailer/templates.go b/backend/pkgs/mailer/templates.go index b7984c0..cc5049f 100644 --- a/backend/pkgs/mailer/templates.go +++ b/backend/pkgs/mailer/templates.go @@ -41,7 +41,6 @@ func DefaultTemplateData() TemplateProps { func render(tpl string, data TemplateProps) (string, error) { tmpl, err := template.New("name").Parse(tpl) - if err != nil { return "", err } diff --git a/backend/pkgs/server/middleware.go b/backend/pkgs/server/middleware.go index f24f06b..8e3bb23 100644 --- a/backend/pkgs/server/middleware.go +++ b/backend/pkgs/server/middleware.go @@ -11,7 +11,6 @@ type Middleware func(Handler) Handler // handler. The middlewares' Handlers will be executed by requests in the order // they are provided. func wrapMiddleware(mw []Middleware, handler Handler) Handler { - // Loop backwards through the middleware invoking each one. Replace the // handler with the new wrapped handler. Looping backwards ensures that the // first middleware of the slice is the first to be executed by requests. diff --git a/backend/pkgs/server/mux.go b/backend/pkgs/server/mux.go index 9e77e32..7f62ab7 100644 --- a/backend/pkgs/server/mux.go +++ b/backend/pkgs/server/mux.go @@ -40,7 +40,6 @@ func (s *Server) toHttpHandler(handler Handler, mw ...Middleware) http.HandlerFu }) err := handler.ServeHTTP(w, r.WithContext(ctx)) - if err != nil { if IsShutdownError(err) { _ = s.Shutdown("SIGTERM") diff --git a/backend/pkgs/server/response_test.go b/backend/pkgs/server/response_test.go index ef23d60..14e7a37 100644 --- a/backend/pkgs/server/response_test.go +++ b/backend/pkgs/server/response_test.go @@ -37,5 +37,4 @@ func Test_Respond_JSON(t *testing.T) { assert.Equal(t, http.StatusCreated, recorder.Code) assert.JSONEq(t, recorder.Body.String(), `{"name":"dummy"}`) assert.Equal(t, "application/json", recorder.Header().Get("Content-Type")) - } diff --git a/backend/pkgs/server/server.go b/backend/pkgs/server/server.go index 921c576..d021b31 100644 --- a/backend/pkgs/server/server.go +++ b/backend/pkgs/server/server.go @@ -79,7 +79,6 @@ func (s *Server) Shutdown(sig string) error { s.wg.Wait() return nil - } func (s *Server) Start() error { diff --git a/backend/pkgs/server/server_test.go b/backend/pkgs/server/server_test.go index 95a93fe..a5cb218 100644 --- a/backend/pkgs/server/server_test.go +++ b/backend/pkgs/server/server_test.go @@ -72,7 +72,6 @@ func Test_GracefulServerShutdownWithWorkers(t *testing.T) { assert.NoError(t, err) assert.True(t, isFinished) - } func Test_GracefulServerShutdownWithRequests(t *testing.T) { diff --git a/backend/pkgs/server/worker.go b/backend/pkgs/server/worker.go index acd6e25..9cf1cc7 100644 --- a/backend/pkgs/server/worker.go +++ b/backend/pkgs/server/worker.go @@ -10,8 +10,7 @@ type Worker interface { // the Worker interface and runs all tasks in a go routine without // a pool or que or limits. It's useful for simple or small applications // with minimal/short background tasks -type SimpleWorker struct { -} +type SimpleWorker struct{} func NewSimpleWorker() *SimpleWorker { return &SimpleWorker{} diff --git a/backend/pkgs/set/funcs.go b/backend/pkgs/set/funcs.go index 0d9a261..d13cdcd 100644 --- a/backend/pkgs/set/funcs.go +++ b/backend/pkgs/set/funcs.go @@ -97,5 +97,4 @@ func Disjoint[T key](a, b Set[T]) bool { } } return true - } diff --git a/backend/pkgs/set/funcs_test.go b/backend/pkgs/set/funcs_test.go index ab3aa0e..cd49ef7 100644 --- a/backend/pkgs/set/funcs_test.go +++ b/backend/pkgs/set/funcs_test.go @@ -28,7 +28,6 @@ var ( ) func TestDiff(t *testing.T) { - tests := []struct { name string args args diff --git a/frontend/components/Form/Autocomplete.vue b/frontend/components/Form/Autocomplete.vue index b2e2d44..9d7c8bb 100644 --- a/frontend/components/Form/Autocomplete.vue +++ b/frontend/components/Form/Autocomplete.vue @@ -28,7 +28,7 @@