diff --git a/.github/scripts/upgrade-test/README.md b/.github/scripts/upgrade-test/README.md index bb4519c8..a36af6bb 100644 --- a/.github/scripts/upgrade-test/README.md +++ b/.github/scripts/upgrade-test/README.md @@ -7,7 +7,7 @@ This document describes the automated upgrade testing workflow for HomeBox. The upgrade test workflow is designed to ensure data integrity and functionality when upgrading HomeBox from one version to another. It automatically: 1. Deploys a stable version of HomeBox -2. Creates test data (users, items, locations, labels, notifiers, attachments) +2. Creates test data (users, items, locations, tags, notifiers, attachments) 3. Upgrades to the latest version from the main branch 4. Verifies all data and functionality remain intact @@ -42,7 +42,7 @@ The workflow creates comprehensive test data using the `create-test-data.sh` scr - **Group 1**: Living Room, Garage - **Group 2**: Home Office -#### Labels +#### Tags - **Group 1**: Electronics, Important - **Group 2**: Work Equipment @@ -68,7 +68,7 @@ The workflow creates comprehensive test data using the `create-test-data.sh` scr The Playwright test suite (`upgrade-verification.spec.ts`) verifies: - ✅ **User Authentication**: All 7 users can log in with their credentials -- ✅ **Data Persistence**: All items, locations, and labels are present +- ✅ **Data Persistence**: All items, locations, and tags are present - ✅ **Attachments**: File attachments are correctly associated with items - ✅ **Notifiers**: The "TESTING" notifier is still configured - ✅ **UI Functionality**: Version display, theme switching work correctly @@ -93,7 +93,7 @@ The setup script generates a JSON file at `/tmp/test-users.json` containing: "group1": ["location-id-1", "location-id-2"], "group2": ["location-id-3"] }, - "labels": {...}, + "tags": {...}, "items": {...}, "notifiers": {...} } diff --git a/.github/scripts/upgrade-test/create-test-data.sh b/.github/scripts/upgrade-test/create-test-data.sh index 07bc7a8e..e04a4276 100755 --- a/.github/scripts/upgrade-test/create-test-data.sh +++ b/.github/scripts/upgrade-test/create-test-data.sh @@ -1,7 +1,7 @@ #!/bin/bash # Script to create test data in HomeBox for upgrade testing -# This script creates users, items, attachments, notifiers, locations, and labels +# This script creates users, items, attachments, notifiers, locations, and tags set -e @@ -128,19 +128,19 @@ create_location() { echo "$response" } -# Function to create a label -create_label() { +# Function to create a tag +create_tag() { local token=$1 local name=$2 local description=$3 - echo "Creating label: $name" >&2 + echo "Creating tag: $name" >&2 local response=$(curl -s -X POST \ -H "Authorization: Bearer $token" \ -H "Content-Type: application/json" \ -d "{\"name\":\"$name\",\"description\":\"$description\"}" \ - "$API_URL/labels") + "$API_URL/tags") echo "$response" } @@ -297,27 +297,27 @@ jq --arg loc1 "$location1_id" \ '.locations = {"group1":[$loc1,$loc2],"group2":[$loc3]}' \ "$TEST_DATA_FILE" > "$TEST_DATA_FILE.tmp" && mv "$TEST_DATA_FILE.tmp" "$TEST_DATA_FILE" -echo "=== Step 4: Create labels for each group ===" +echo "=== Step 4: Create tags for each group ===" -# Create labels for group 1 -label1=$(create_label "$user1_token" "Electronics" "Electronic devices") -label1_id=$(echo "$label1" | jq -r '.id // empty') -echo "Created label: Electronics (ID: $label1_id)" +# Create tags for group 1 +tag1=$(create_tag "$user1_token" "Electronics" "Electronic devices") +tag1_id=$(echo "$tag1" | jq -r '.id // empty') +echo "Created tag: Electronics (ID: $tag1_id)" -label2=$(create_label "$user1_token" "Important" "High priority items") -label2_id=$(echo "$label2" | jq -r '.id // empty') -echo "Created label: Important (ID: $label2_id)" +tag2=$(create_tag "$user1_token" "Important" "High priority items") +tag2_id=$(echo "$tag2" | jq -r '.id // empty') +echo "Created tag: Important (ID: $tag2_id)" -# Create label for group 2 -label3=$(create_label "$user6_token" "Work Equipment" "Items for work") -label3_id=$(echo "$label3" | jq -r '.id // empty') -echo "Created label: Work Equipment (ID: $label3_id)" +# Create tag for group 2 +tag3=$(create_tag "$user6_token" "Work Equipment" "Items for work") +tag3_id=$(echo "$tag3" | jq -r '.id // empty') +echo "Created tag: Work Equipment (ID: $tag3_id)" -# Store labels -jq --arg lab1 "$label1_id" \ - --arg lab2 "$label2_id" \ - --arg lab3 "$label3_id" \ - '.labels = {"group1":[$lab1,$lab2],"group2":[$lab3]}' \ +# Store tags +jq --arg tag1 "$tag1_id" \ + --arg tag2 "$tag2_id" \ + --arg tag3 "$tag3_id" \ + '.tags = {"group1":[$tag1,$tag2],"group2":[$tag3]}' \ "$TEST_DATA_FILE" > "$TEST_DATA_FILE.tmp" && mv "$TEST_DATA_FILE.tmp" "$TEST_DATA_FILE" echo "=== Step 5: Create test notifier ===" @@ -400,7 +400,7 @@ echo "Test data file saved to: $TEST_DATA_FILE" echo "Summary:" echo " - Users created: 7 (5 in group 1, 2 in group 2)" echo " - Locations created: 3" -echo " - Labels created: 3" +echo " - Tags created: 3" echo " - Notifiers created: 1" echo " - Items created: 7" echo " - Attachments created: 7" diff --git a/backend/app/api/demo.go b/backend/app/api/demo.go index 54b04f07..5e2c2462 100644 --- a/backend/app/api/demo.go +++ b/backend/app/api/demo.go @@ -11,7 +11,7 @@ import ( ) func (a *app) SetupDemo() error { - csvText := `HB.import_ref,HB.location,HB.labels,HB.quantity,HB.name,HB.description,HB.insured,HB.serial_number,HB.model_number,HB.manufacturer,HB.notes,HB.purchase_from,HB.purchase_price,HB.purchase_time,HB.lifetime_warranty,HB.warranty_expires,HB.warranty_details,HB.sold_to,HB.sold_price,HB.sold_time,HB.sold_notes + csvText := `HB.import_ref,HB.location,HB.tags,HB.quantity,HB.name,HB.description,HB.insured,HB.serial_number,HB.model_number,HB.manufacturer,HB.notes,HB.purchase_from,HB.purchase_price,HB.purchase_time,HB.lifetime_warranty,HB.warranty_expires,HB.warranty_details,HB.sold_to,HB.sold_price,HB.sold_time,HB.sold_notes ,Garage,IOT;Home Assistant; Z-Wave,1,Zooz Universal Relay ZEN17,"Zooz 700 Series Z-Wave Universal Relay ZEN17 for Awnings, Garage Doors, Sprinklers, and More | 2 NO-C-NC Relays (20A, 10A) | Signal Repeater | Hub Required (Compatible with SmartThings and Hubitat)",,,ZEN17,Zooz,,Amazon,39.95,10/13/2021,,,,,,, ,Living Room,IOT;Home Assistant; Z-Wave,1,Zooz Motion Sensor,"Zooz Z-Wave Plus S2 Motion Sensor ZSE18 with Magnetic Mount, Works with Vera and SmartThings",,,ZSE18,Zooz,,Amazon,29.95,10/15/2021,,,,,,, ,Office,IOT;Home Assistant; Z-Wave,1,Zooz 110v Power Switch,"Zooz Z-Wave Plus Power Switch ZEN15 for 110V AC Units, Sump Pumps, Humidifiers, and More",,,ZEN15,Zooz,,Amazon,39.95,10/13/2021,,,,,,, diff --git a/backend/app/api/handlers/v1/controller.go b/backend/app/api/handlers/v1/controller.go index 844ed8e4..5b154d24 100644 --- a/backend/app/api/handlers/v1/controller.go +++ b/backend/app/api/handlers/v1/controller.go @@ -222,7 +222,7 @@ func (ctrl *V1Controller) HandleCacheWS() errchain.HandlerFunc { } } - ctrl.bus.Subscribe(eventbus.EventLabelMutation, factory("label.mutation")) + ctrl.bus.Subscribe(eventbus.EventTagMutation, factory("tag.mutation")) ctrl.bus.Subscribe(eventbus.EventLocationMutation, factory("location.mutation")) ctrl.bus.Subscribe(eventbus.EventItemMutation, factory("item.mutation")) diff --git a/backend/app/api/handlers/v1/v1_ctrl_item_templates.go b/backend/app/api/handlers/v1/v1_ctrl_item_templates.go index deb4c261..562063e3 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_item_templates.go +++ b/backend/app/api/handlers/v1/v1_ctrl_item_templates.go @@ -106,7 +106,7 @@ type ItemTemplateCreateItemRequest struct { Name string `json:"name" validate:"required,min=1,max=255"` Description string `json:"description" validate:"max=1000"` LocationID uuid.UUID `json:"locationId" validate:"required"` - LabelIDs []uuid.UUID `json:"labelIds"` + TagIDs []uuid.UUID `json:"tagIds"` Quantity *int `json:"quantity"` } @@ -150,7 +150,7 @@ func (ctrl *V1Controller) HandleItemTemplatesCreateItem() errchain.HandlerFunc { Description: body.Description, Quantity: quantity, LocationID: body.LocationID, - LabelIDs: body.LabelIDs, + TagIDs: body.TagIDs, Insured: template.DefaultInsured, Manufacturer: template.DefaultManufacturer, ModelNumber: template.DefaultModelNumber, diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index 5b38bda7..07bbbcd8 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -28,7 +28,7 @@ import ( // @Param q query string false "search string" // @Param page query int false "page number" // @Param pageSize query int false "items per page" -// @Param labels query []string false "label Ids" collectionFormat(multi) +// @Param tags query []string false "tags Ids" collectionFormat(multi) // @Param locations query []string false "location Ids" collectionFormat(multi) // @Param parentIds query []string false "parent Ids" collectionFormat(multi) // @Success 200 {object} repo.PaginationResult[repo.ItemSummary]{} @@ -59,8 +59,8 @@ func (ctrl *V1Controller) HandleItemsGetAll() errchain.HandlerFunc { PageSize: queryIntOrNegativeOne(params.Get("pageSize")), Search: params.Get("q"), LocationIDs: queryUUIDList(params, "locations"), - LabelIDs: queryUUIDList(params, "labels"), - NegateLabels: queryBool(params.Get("negateLabels")), + TagIDs: queryUUIDList(params, "tags"), + NegateTags: queryBool(params.Get("negateTags")), OnlyWithoutPhoto: queryBool(params.Get("onlyWithoutPhoto")), OnlyWithPhoto: queryBool(params.Get("onlyWithPhoto")), ParentItemIDs: queryUUIDList(params, "parentIds"), diff --git a/backend/app/api/handlers/v1/v1_ctrl_labels.go b/backend/app/api/handlers/v1/v1_ctrl_labels.go deleted file mode 100644 index 1c23adbe..00000000 --- a/backend/app/api/handlers/v1/v1_ctrl_labels.go +++ /dev/null @@ -1,102 +0,0 @@ -package v1 - -import ( - "net/http" - - "github.com/google/uuid" - "github.com/hay-kot/httpkit/errchain" - "github.com/sysadminsmedia/homebox/backend/internal/core/services" - "github.com/sysadminsmedia/homebox/backend/internal/data/repo" - "github.com/sysadminsmedia/homebox/backend/internal/web/adapters" -) - -// HandleLabelsGetAll godoc -// -// @Summary Get All Labels -// @Tags Labels -// @Produce json -// @Success 200 {object} []repo.LabelOut -// @Router /v1/labels [GET] -// @Security Bearer -func (ctrl *V1Controller) HandleLabelsGetAll() errchain.HandlerFunc { - fn := func(r *http.Request) ([]repo.LabelSummary, error) { - auth := services.NewContext(r.Context()) - return ctrl.repo.Labels.GetAll(auth, auth.GID) - } - - return adapters.Command(fn, http.StatusOK) -} - -// HandleLabelsCreate godoc -// -// @Summary Create Label -// @Tags Labels -// @Produce json -// @Param payload body repo.LabelCreate true "Label Data" -// @Success 200 {object} repo.LabelSummary -// @Router /v1/labels [POST] -// @Security Bearer -func (ctrl *V1Controller) HandleLabelsCreate() errchain.HandlerFunc { - fn := func(r *http.Request, data repo.LabelCreate) (repo.LabelOut, error) { - auth := services.NewContext(r.Context()) - return ctrl.repo.Labels.Create(auth, auth.GID, data) - } - - return adapters.Action(fn, http.StatusCreated) -} - -// HandleLabelDelete godocs -// -// @Summary Delete Label -// @Tags Labels -// @Produce json -// @Param id path string true "Label ID" -// @Success 204 -// @Router /v1/labels/{id} [DELETE] -// @Security Bearer -func (ctrl *V1Controller) HandleLabelDelete() errchain.HandlerFunc { - fn := func(r *http.Request, ID uuid.UUID) (any, error) { - auth := services.NewContext(r.Context()) - err := ctrl.repo.Labels.DeleteByGroup(auth, auth.GID, ID) - return nil, err - } - - return adapters.CommandID("id", fn, http.StatusNoContent) -} - -// HandleLabelGet godocs -// -// @Summary Get Label -// @Tags Labels -// @Produce json -// @Param id path string true "Label ID" -// @Success 200 {object} repo.LabelOut -// @Router /v1/labels/{id} [GET] -// @Security Bearer -func (ctrl *V1Controller) HandleLabelGet() errchain.HandlerFunc { - fn := func(r *http.Request, ID uuid.UUID) (repo.LabelOut, error) { - auth := services.NewContext(r.Context()) - return ctrl.repo.Labels.GetOneByGroup(auth, auth.GID, ID) - } - - return adapters.CommandID("id", fn, http.StatusOK) -} - -// HandleLabelUpdate godocs -// -// @Summary Update Label -// @Tags Labels -// @Produce json -// @Param id path string true "Label ID" -// @Success 200 {object} repo.LabelOut -// @Router /v1/labels/{id} [PUT] -// @Security Bearer -func (ctrl *V1Controller) HandleLabelUpdate() errchain.HandlerFunc { - fn := func(r *http.Request, ID uuid.UUID, data repo.LabelUpdate) (repo.LabelOut, error) { - auth := services.NewContext(r.Context()) - data.ID = ID - return ctrl.repo.Labels.UpdateByGroup(auth, auth.GID, data) - } - - return adapters.ActionID("id", fn, http.StatusOK) -} diff --git a/backend/app/api/handlers/v1/v1_ctrl_statistics.go b/backend/app/api/handlers/v1/v1_ctrl_statistics.go index 980f44b0..bb406ca6 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_statistics.go +++ b/backend/app/api/handlers/v1/v1_ctrl_statistics.go @@ -29,18 +29,18 @@ func (ctrl *V1Controller) HandleGroupStatisticsLocations() errchain.HandlerFunc return adapters.Command(fn, http.StatusOK) } -// HandleGroupStatisticsLabels godoc +// HandleGroupStatisticsTags godoc // -// @Summary Get Label Statistics +// @Summary Get Tags Statistics // @Tags Statistics // @Produce json // @Success 200 {object} []repo.TotalsByOrganizer -// @Router /v1/groups/statistics/labels [GET] +// @Router /v1/groups/statistics/tags [GET] // @Security Bearer -func (ctrl *V1Controller) HandleGroupStatisticsLabels() errchain.HandlerFunc { +func (ctrl *V1Controller) HandleGroupStatisticsTags() errchain.HandlerFunc { fn := func(r *http.Request) ([]repo.TotalsByOrganizer, error) { auth := services.NewContext(r.Context()) - return ctrl.repo.Groups.StatsLabelsByPurchasePrice(auth, auth.GID) + return ctrl.repo.Groups.StatsTagsByPurchasePrice(auth, auth.GID) } return adapters.Command(fn, http.StatusOK) diff --git a/backend/app/api/handlers/v1/v1_ctrl_tags.go b/backend/app/api/handlers/v1/v1_ctrl_tags.go new file mode 100644 index 00000000..b8d46b83 --- /dev/null +++ b/backend/app/api/handlers/v1/v1_ctrl_tags.go @@ -0,0 +1,102 @@ +package v1 + +import ( + "net/http" + + "github.com/google/uuid" + "github.com/hay-kot/httpkit/errchain" + "github.com/sysadminsmedia/homebox/backend/internal/core/services" + "github.com/sysadminsmedia/homebox/backend/internal/data/repo" + "github.com/sysadminsmedia/homebox/backend/internal/web/adapters" +) + +// HandleTagsGetAll godoc +// +// @Summary Get All Tags +// @Tags Tags +// @Produce json +// @Success 200 {object} []repo.TagOut +// @Router /v1/tags [GET] +// @Security Bearer +func (ctrl *V1Controller) HandleTagsGetAll() errchain.HandlerFunc { + fn := func(r *http.Request) ([]repo.TagSummary, error) { + auth := services.NewContext(r.Context()) + return ctrl.repo.Tags.GetAll(auth, auth.GID) + } + + return adapters.Command(fn, http.StatusOK) +} + +// HandleTagsCreate godoc +// +// @Summary Create Tag +// @Tags Tags +// @Produce json +// @Param payload body repo.TagCreate true "Tag Data" +// @Success 200 {object} repo.TagSummary +// @Router /v1/tags [POST] +// @Security Bearer +func (ctrl *V1Controller) HandleTagsCreate() errchain.HandlerFunc { + fn := func(r *http.Request, data repo.TagCreate) (repo.TagOut, error) { + auth := services.NewContext(r.Context()) + return ctrl.repo.Tags.Create(auth, auth.GID, data) + } + + return adapters.Action(fn, http.StatusCreated) +} + +// HandleTagDelete godocs +// +// @Summary Delete Tag +// @Tags Tags +// @Produce json +// @Param id path string true "Tag ID" +// @Success 204 +// @Router /v1/tags/{id} [DELETE] +// @Security Bearer +func (ctrl *V1Controller) HandleTagDelete() errchain.HandlerFunc { + fn := func(r *http.Request, ID uuid.UUID) (any, error) { + auth := services.NewContext(r.Context()) + err := ctrl.repo.Tags.DeleteByGroup(auth, auth.GID, ID) + return nil, err + } + + return adapters.CommandID("id", fn, http.StatusNoContent) +} + +// HandleTagGet godocs +// +// @Summary Get Tag +// @Tags Tags +// @Produce json +// @Param id path string true "Tag ID" +// @Success 200 {object} repo.TagOut +// @Router /v1/tags/{id} [GET] +// @Security Bearer +func (ctrl *V1Controller) HandleTagGet() errchain.HandlerFunc { + fn := func(r *http.Request, ID uuid.UUID) (repo.TagOut, error) { + auth := services.NewContext(r.Context()) + return ctrl.repo.Tags.GetOneByGroup(auth, auth.GID, ID) + } + + return adapters.CommandID("id", fn, http.StatusOK) +} + +// HandleTagUpdate godocs +// +// @Summary Update Tag +// @Tags Tags +// @Produce json +// @Param id path string true "Tag ID" +// @Success 200 {object} repo.TagOut +// @Router /v1/tags/{id} [PUT] +// @Security Bearer +func (ctrl *V1Controller) HandleTagUpdate() errchain.HandlerFunc { + fn := func(r *http.Request, ID uuid.UUID, data repo.TagUpdate) (repo.TagOut, error) { + auth := services.NewContext(r.Context()) + data.ID = ID + return ctrl.repo.Tags.UpdateByGroup(auth, auth.GID, data) + } + + return adapters.ActionID("id", fn, http.StatusOK) +} diff --git a/backend/app/api/routes.go b/backend/app/api/routes.go index f655a543..5216a6ee 100644 --- a/backend/app/api/routes.go +++ b/backend/app/api/routes.go @@ -97,7 +97,7 @@ func (a *app) mountRoutes(r *chi.Mux, chain *errchain.ErrChain, repos *repo.AllR r.Get("/groups/statistics", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatistics(), userMW...)) r.Get("/groups/statistics/purchase-price", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatisticsPriceOverTime(), userMW...)) r.Get("/groups/statistics/locations", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatisticsLocations(), userMW...)) - r.Get("/groups/statistics/labels", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatisticsLabels(), userMW...)) + r.Get("/groups/statistics/tags", chain.ToHandlerFunc(v1Ctrl.HandleGroupStatisticsTags(), userMW...)) // TODO: I don't like /groups being the URL for users r.Get("/groups", chain.ToHandlerFunc(v1Ctrl.HandleGroupGet(), userMW...)) @@ -117,11 +117,11 @@ func (a *app) mountRoutes(r *chi.Mux, chain *errchain.ErrChain, repos *repo.AllR r.Put("/locations/{id}", chain.ToHandlerFunc(v1Ctrl.HandleLocationUpdate(), userMW...)) r.Delete("/locations/{id}", chain.ToHandlerFunc(v1Ctrl.HandleLocationDelete(), userMW...)) - r.Get("/labels", chain.ToHandlerFunc(v1Ctrl.HandleLabelsGetAll(), userMW...)) - r.Post("/labels", chain.ToHandlerFunc(v1Ctrl.HandleLabelsCreate(), userMW...)) - r.Get("/labels/{id}", chain.ToHandlerFunc(v1Ctrl.HandleLabelGet(), userMW...)) - r.Put("/labels/{id}", chain.ToHandlerFunc(v1Ctrl.HandleLabelUpdate(), userMW...)) - r.Delete("/labels/{id}", chain.ToHandlerFunc(v1Ctrl.HandleLabelDelete(), userMW...)) + r.Get("/tags", chain.ToHandlerFunc(v1Ctrl.HandleTagsGetAll(), userMW...)) + r.Post("/tags", chain.ToHandlerFunc(v1Ctrl.HandleTagsCreate(), userMW...)) + r.Get("/tags/{id}", chain.ToHandlerFunc(v1Ctrl.HandleTagGet(), userMW...)) + r.Put("/tags/{id}", chain.ToHandlerFunc(v1Ctrl.HandleTagUpdate(), userMW...)) + r.Delete("/tags/{id}", chain.ToHandlerFunc(v1Ctrl.HandleTagDelete(), userMW...)) r.Get("/items", chain.ToHandlerFunc(v1Ctrl.HandleItemsGetAll(), userMW...)) r.Post("/items", chain.ToHandlerFunc(v1Ctrl.HandleItemsCreate(), userMW...)) diff --git a/backend/go.sum b/backend/go.sum index 6f11d8f1..0d766402 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -325,6 +325,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs= github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY= @@ -347,6 +349,8 @@ github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOF github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/olahol/melody v1.4.0 h1:Pa5SdeZL/zXPi1tJuMAPDbl4n3gQOThSL6G1p4qZ4SI= github.com/olahol/melody v1.4.0/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo/v2 v2.9.2 h1:BA2GMJOtfGAfagzYtrAlufIP0lq6QERkFmHLMLPwFSU= github.com/onsi/ginkgo/v2 v2.9.2/go.mod h1:WHcJJG2dIlcCqVfBAwUCrJxSPFb6v4azBwgxeMeDuts= github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= @@ -389,6 +393,10 @@ github.com/shirou/gopsutil/v4 v4.25.11 h1:X53gB7muL9Gnwwo2evPSE+SfOrltMoR6V3xJAX github.com/shirou/gopsutil/v4 v4.25.11/go.mod h1:EivAfP5x2EhLp2ovdpKSozecVXn1TmuG7SMzs/Wh4PU= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo= github.com/spiffe/go-spiffe/v2 v2.6.0/go.mod h1:gm2SeUoMZEtpnzPNs2Csc0D/gX33k1xIx7lEzqblHEs= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/backend/internal/core/services/reporting/.testdata/import/types.csv b/backend/internal/core/services/reporting/.testdata/import/types.csv index 96ff236c..0bc104f5 100644 --- a/backend/internal/core/services/reporting/.testdata/import/types.csv +++ b/backend/internal/core/services/reporting/.testdata/import/types.csv @@ -1,4 +1,4 @@ -HB.name,HB.asset_id,HB.location,HB.labels +HB.name,HB.asset_id,HB.location,HB.tags Item 1,1,Path / To / Location 1,L1 ; L2 ; L3 Item 2,000-002,Path /To/ Location 2,L1;L2;L3 Item 3,1000-003,Path / To /Location 3 , L1;L2; L3 \ No newline at end of file diff --git a/backend/internal/core/services/reporting/eventbus/eventbus.go b/backend/internal/core/services/reporting/eventbus/eventbus.go index 581bc38b..7fc4bfac 100644 --- a/backend/internal/core/services/reporting/eventbus/eventbus.go +++ b/backend/internal/core/services/reporting/eventbus/eventbus.go @@ -11,7 +11,7 @@ import ( type Event string const ( - EventLabelMutation Event = "label.mutation" + EventTagMutation Event = "tags.mutation" EventLocationMutation Event = "location.mutation" EventItemMutation Event = "item.mutation" ) @@ -37,7 +37,7 @@ func New() *EventBus { return &EventBus{ ch: make(chan eventData, 100), subscribers: map[Event][]func(any){ - EventLabelMutation: {}, + EventTagMutation: {}, EventLocationMutation: {}, EventItemMutation: {}, }, diff --git a/backend/internal/core/services/reporting/io_row.go b/backend/internal/core/services/reporting/io_row.go index 1e3415b4..3ebb2aa5 100644 --- a/backend/internal/core/services/reporting/io_row.go +++ b/backend/internal/core/services/reporting/io_row.go @@ -15,7 +15,7 @@ type ExportItemFields struct { type ExportCSVRow struct { ImportRef string `csv:"HB.import_ref"` Location LocationString `csv:"HB.location"` - LabelStr LabelString `csv:"HB.labels"` + TagStr TagString `csv:"HB.tags"` AssetID repo.AssetID `csv:"HB.asset_id"` Archived bool `csv:"HB.archived"` URL string `csv:"HB.url"` @@ -48,20 +48,20 @@ type ExportCSVRow struct { // ============================================================================ -// LabelString is a string slice that is used to represent a list of labels. +// TagString is a string slice that is used to represent a list of tags. // -// For example, a list of labels "Important; Work" would be represented as a -// LabelString with the following values: +// For example, a list of tags "Important; Work" would be represented as a +// TagString with the following values: // -// LabelString{"Important", "Work"} -type LabelString []string +// TagString{"Important", "Work"} +type TagString []string -func parseLabelString(s string) LabelString { +func parseTagString(s string) TagString { v, _ := parseSeparatedString(s, ";") return v } -func (ls LabelString) String() string { +func (ls TagString) String() string { return strings.Join(ls, "; ") } diff --git a/backend/internal/core/services/reporting/io_sheet.go b/backend/internal/core/services/reporting/io_sheet.go index 1db37bc6..8549a175 100644 --- a/backend/internal/core/services/reporting/io_sheet.go +++ b/backend/internal/core/services/reporting/io_sheet.go @@ -114,8 +114,8 @@ func (s *IOSheet) Read(data io.Reader) error { v, _ = repo.ParseAssetID(val) case reflect.TypeOf(LocationString{}): v = parseLocationString(val) - case reflect.TypeOf(LabelString{}): - v = parseLabelString(val) + case reflect.TypeOf(TagString{}): + v = parseTagString(val) } log.Debug(). @@ -172,10 +172,10 @@ func (s *IOSheet) ReadItems(ctx context.Context, items []repo.ItemOut, gid uuid. locString := fromPathSlice(locPaths) - labelString := make([]string, len(item.Labels)) + tagString := make([]string, len(item.Tags)) - for i, l := range item.Labels { - labelString[i] = l.Name + for i, l := range item.Tags { + tagString[i] = l.Name } url := generateItemURL(item, hbURL) @@ -194,7 +194,7 @@ func (s *IOSheet) ReadItems(ctx context.Context, items []repo.ItemOut, gid uuid. s.Rows[i] = ExportCSVRow{ // fill struct Location: locString, - LabelStr: labelString, + TagStr: tagString, ImportRef: item.ImportRef, AssetID: item.AssetID, @@ -311,8 +311,8 @@ func (s *IOSheet) CSV() ([][]string, error) { v = val.Interface().(repo.AssetID).String() case reflect.TypeOf(LocationString{}): v = val.Interface().(LocationString).String() - case reflect.TypeOf(LabelString{}): - v = val.Interface().(LabelString).String() + case reflect.TypeOf(TagString{}): + v = val.Interface().(TagString).String() default: log.Debug().Str("type", field.Type.String()).Msg("unknown type") } diff --git a/backend/internal/core/services/reporting/io_sheet_test.go b/backend/internal/core/services/reporting/io_sheet_test.go index a489d2f8..cd614a84 100644 --- a/backend/internal/core/services/reporting/io_sheet_test.go +++ b/backend/internal/core/services/reporting/io_sheet_test.go @@ -77,19 +77,19 @@ func TestSheet_Read(t *testing.T) { Name: "Item 1", AssetID: repo.AssetID(1), Location: LocationString{"Path", "To", "Location 1"}, - LabelStr: LabelString{"L1", "L2", "L3"}, + TagStr: TagString{"L1", "L2", "L3"}, }, { Name: "Item 2", AssetID: repo.AssetID(2), Location: LocationString{"Path", "To", "Location 2"}, - LabelStr: LabelString{"L1", "L2", "L3"}, + TagStr: TagString{"L1", "L2", "L3"}, }, { Name: "Item 3", AssetID: repo.AssetID(1000003), Location: LocationString{"Path", "To", "Location 3"}, - LabelStr: LabelString{"L1", "L2", "L3"}, + TagStr: TagString{"L1", "L2", "L3"}, }, }, }, diff --git a/backend/internal/core/services/service_items.go b/backend/internal/core/services/service_items.go index 95bb0fb7..251a0e59 100644 --- a/backend/internal/core/services/service_items.go +++ b/backend/internal/core/services/service_items.go @@ -99,7 +99,7 @@ func serializeLocation[T ~[]string](location T) string { // // 1. If the item does not exist, it is created. // 2. If the item has a ImportRef and it exists it is skipped -// 3. Locations and Labels are created if they do not exist. +// 3. Locations and Tags are created if they do not exist. func (svc *ItemService) CsvImport(ctx context.Context, gid uuid.UUID, data io.Reader) (int, error) { sheet := reporting.IOSheet{} @@ -109,17 +109,17 @@ func (svc *ItemService) CsvImport(ctx context.Context, gid uuid.UUID, data io.Re } // ======================================== - // Labels + // Tags - labelMap := make(map[string]uuid.UUID) + tagMap := make(map[string]uuid.UUID) { - labels, err := svc.repo.Labels.GetAll(ctx, gid) + tags, err := svc.repo.Tags.GetAll(ctx, gid) if err != nil { return 0, err } - for _, label := range labels { - labelMap[label.Name] = label.ID + for _, tag := range tags { + tagMap[tag.Name] = tag.ID } } @@ -184,23 +184,23 @@ func (svc *ItemService) CsvImport(ctx context.Context, gid uuid.UUID, data io.Re } // ======================================== - // Pre-Create Labels as necessary - labelIds := make([]uuid.UUID, len(row.LabelStr)) + // Pre-Create tags as necessary + tagIds := make([]uuid.UUID, len(row.TagStr)) - for j := range row.LabelStr { - label := row.LabelStr[j] + for j := range row.TagStr { + tag := row.TagStr[j] - id, ok := labelMap[label] + id, ok := tagMap[tag] if !ok { - newLabel, err := svc.repo.Labels.Create(ctx, gid, repo.LabelCreate{Name: label}) + newTag, err := svc.repo.Tags.Create(ctx, gid, repo.TagCreate{Name: tag}) if err != nil { return 0, err } - id = newLabel.ID + id = newTag.ID } - labelIds[j] = id - labelMap[label] = id + tagIds[j] = id + tagMap[tag] = id } // ======================================== @@ -262,7 +262,7 @@ func (svc *ItemService) CsvImport(ctx context.Context, gid uuid.UUID, data io.Re Description: row.Description, AssetID: effAID, LocationID: locationID, - LabelIDs: labelIds, + TagIDs: tagIds, } item, err = svc.repo.Items.Create(ctx, gid, newItem) @@ -291,7 +291,7 @@ func (svc *ItemService) CsvImport(ctx context.Context, gid uuid.UUID, data io.Re updateItem := repo.ItemUpdate{ ID: item.ID, - LabelIDs: labelIds, + TagIDs: tagIds, LocationID: locationID, Name: row.Name, diff --git a/backend/internal/core/services/service_user.go b/backend/internal/core/services/service_user.go index 8b13a653..ff2d02ed 100644 --- a/backend/internal/core/services/service_user.go +++ b/backend/internal/core/services/service_user.go @@ -43,7 +43,7 @@ type ( ) // RegisterUser creates a new user and group in the data with the provided data. It also bootstraps the user's group -// with default Labels and Locations. +// with default Tags and Locations. func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration) (repo.UserOut, error) { log.Debug(). Str("name", data.Name). @@ -95,11 +95,11 @@ func (svc *UserService) RegisterUser(ctx context.Context, data UserRegistration) } log.Debug().Msg("user created") - // Create the default labels and locations for the group. + // Create the default tags and locations for the group. if creatingGroup { - log.Debug().Msg("creating default labels") - for _, label := range defaultLabels() { - _, err := svc.repos.Labels.Create(ctx, usr.GroupID, label) + log.Debug().Msg("creating default tags") + for _, tag := range defaultTags() { + _, err := svc.repos.Tags.Create(ctx, usr.GroupID, tag) if err != nil { return repo.UserOut{}, err } @@ -300,11 +300,11 @@ func (svc *UserService) registerOIDCUser(ctx context.Context, issuer, subject, e return repo.UserOut{}, err } - log.Debug().Str("issuer", issuer).Str("subject", subject).Msg("creating default labels for OIDC user") - for _, label := range defaultLabels() { - _, err := svc.repos.Labels.Create(ctx, group.ID, label) + log.Debug().Str("issuer", issuer).Str("subject", subject).Msg("creating default tags for OIDC user") + for _, tag := range defaultTags() { + _, err := svc.repos.Tags.Create(ctx, group.ID, tag) if err != nil { - log.Err(err).Msg("Failed to create default label") + log.Err(err).Msg("Failed to create default tag") } } diff --git a/backend/internal/core/services/service_user_defaults.go b/backend/internal/core/services/service_user_defaults.go index 62a429dc..e3ca2026 100644 --- a/backend/internal/core/services/service_user_defaults.go +++ b/backend/internal/core/services/service_user_defaults.go @@ -33,8 +33,8 @@ func defaultLocations() []repo.LocationCreate { } } -func defaultLabels() []repo.LabelCreate { - return []repo.LabelCreate{ +func defaultTags() []repo.TagCreate { + return []repo.TagCreate{ { Name: "Appliances", }, diff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.go index 7cd5830c..91f59e1f 100644 --- a/backend/internal/data/ent/client.go +++ b/backend/internal/data/ent/client.go @@ -24,10 +24,10 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -53,14 +53,14 @@ type Client struct { ItemField *ItemFieldClient // ItemTemplate is the client for interacting with the ItemTemplate builders. ItemTemplate *ItemTemplateClient - // Label is the client for interacting with the Label builders. - Label *LabelClient // Location is the client for interacting with the Location builders. Location *LocationClient // MaintenanceEntry is the client for interacting with the MaintenanceEntry builders. MaintenanceEntry *MaintenanceEntryClient // Notifier is the client for interacting with the Notifier builders. Notifier *NotifierClient + // Tag is the client for interacting with the Tag builders. + Tag *TagClient // TemplateField is the client for interacting with the TemplateField builders. TemplateField *TemplateFieldClient // User is the client for interacting with the User builders. @@ -84,10 +84,10 @@ func (c *Client) init() { c.Item = NewItemClient(c.config) c.ItemField = NewItemFieldClient(c.config) c.ItemTemplate = NewItemTemplateClient(c.config) - c.Label = NewLabelClient(c.config) c.Location = NewLocationClient(c.config) c.MaintenanceEntry = NewMaintenanceEntryClient(c.config) c.Notifier = NewNotifierClient(c.config) + c.Tag = NewTagClient(c.config) c.TemplateField = NewTemplateFieldClient(c.config) c.User = NewUserClient(c.config) } @@ -190,10 +190,10 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { Item: NewItemClient(cfg), ItemField: NewItemFieldClient(cfg), ItemTemplate: NewItemTemplateClient(cfg), - Label: NewLabelClient(cfg), Location: NewLocationClient(cfg), MaintenanceEntry: NewMaintenanceEntryClient(cfg), Notifier: NewNotifierClient(cfg), + Tag: NewTagClient(cfg), TemplateField: NewTemplateFieldClient(cfg), User: NewUserClient(cfg), }, nil @@ -223,10 +223,10 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) Item: NewItemClient(cfg), ItemField: NewItemFieldClient(cfg), ItemTemplate: NewItemTemplateClient(cfg), - Label: NewLabelClient(cfg), Location: NewLocationClient(cfg), MaintenanceEntry: NewMaintenanceEntryClient(cfg), Notifier: NewNotifierClient(cfg), + Tag: NewTagClient(cfg), TemplateField: NewTemplateFieldClient(cfg), User: NewUserClient(cfg), }, nil @@ -259,8 +259,8 @@ func (c *Client) Close() error { func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ c.Attachment, c.AuthRoles, c.AuthTokens, c.Group, c.GroupInvitationToken, - c.Item, c.ItemField, c.ItemTemplate, c.Label, c.Location, c.MaintenanceEntry, - c.Notifier, c.TemplateField, c.User, + c.Item, c.ItemField, c.ItemTemplate, c.Location, c.MaintenanceEntry, + c.Notifier, c.Tag, c.TemplateField, c.User, } { n.Use(hooks...) } @@ -271,8 +271,8 @@ func (c *Client) Use(hooks ...Hook) { func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.Attachment, c.AuthRoles, c.AuthTokens, c.Group, c.GroupInvitationToken, - c.Item, c.ItemField, c.ItemTemplate, c.Label, c.Location, c.MaintenanceEntry, - c.Notifier, c.TemplateField, c.User, + c.Item, c.ItemField, c.ItemTemplate, c.Location, c.MaintenanceEntry, + c.Notifier, c.Tag, c.TemplateField, c.User, } { n.Intercept(interceptors...) } @@ -297,14 +297,14 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.ItemField.mutate(ctx, m) case *ItemTemplateMutation: return c.ItemTemplate.mutate(ctx, m) - case *LabelMutation: - return c.Label.mutate(ctx, m) case *LocationMutation: return c.Location.mutate(ctx, m) case *MaintenanceEntryMutation: return c.MaintenanceEntry.mutate(ctx, m) case *NotifierMutation: return c.Notifier.mutate(ctx, m) + case *TagMutation: + return c.Tag.mutate(ctx, m) case *TemplateFieldMutation: return c.TemplateField.mutate(ctx, m) case *UserMutation: @@ -949,15 +949,15 @@ func (c *GroupClient) QueryItems(_m *Group) *ItemQuery { return query } -// QueryLabels queries the labels edge of a Group. -func (c *GroupClient) QueryLabels(_m *Group) *LabelQuery { - query := (&LabelClient{config: c.config}).Query() +// QueryTags queries the tags edge of a Group. +func (c *GroupClient) QueryTags(_m *Group) *TagQuery { + query := (&TagClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := _m.ID step := sqlgraph.NewStep( sqlgraph.From(group.Table, group.FieldID, id), - sqlgraph.To(label.Table, label.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, group.LabelsTable, group.LabelsColumn), + sqlgraph.To(tag.Table, tag.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, group.TagsTable, group.TagsColumn), ) fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) return fromV, nil @@ -1343,15 +1343,15 @@ func (c *ItemClient) QueryChildren(_m *Item) *ItemQuery { return query } -// QueryLabel queries the label edge of a Item. -func (c *ItemClient) QueryLabel(_m *Item) *LabelQuery { - query := (&LabelClient{config: c.config}).Query() +// QueryTag queries the tag edge of a Item. +func (c *ItemClient) QueryTag(_m *Item) *TagQuery { + query := (&TagClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := _m.ID step := sqlgraph.NewStep( sqlgraph.From(item.Table, item.FieldID, id), - sqlgraph.To(label.Table, label.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, item.LabelTable, item.LabelPrimaryKey...), + sqlgraph.To(tag.Table, tag.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, item.TagTable, item.TagPrimaryKey...), ) fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) return fromV, nil @@ -1778,171 +1778,6 @@ func (c *ItemTemplateClient) mutate(ctx context.Context, m *ItemTemplateMutation } } -// LabelClient is a client for the Label schema. -type LabelClient struct { - config -} - -// NewLabelClient returns a client for the Label from the given config. -func NewLabelClient(c config) *LabelClient { - return &LabelClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `label.Hooks(f(g(h())))`. -func (c *LabelClient) Use(hooks ...Hook) { - c.hooks.Label = append(c.hooks.Label, hooks...) -} - -// 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...) -} - -// Create returns a builder for creating a Label entity. -func (c *LabelClient) Create() *LabelCreate { - mutation := newLabelMutation(c.config, OpCreate) - return &LabelCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Label entities. -func (c *LabelClient) CreateBulk(builders ...*LabelCreate) *LabelCreateBulk { - return &LabelCreateBulk{config: c.config, builders: builders} -} - -// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates -// a builder and applies setFunc on it. -func (c *LabelClient) MapCreateBulk(slice any, setFunc func(*LabelCreate, int)) *LabelCreateBulk { - rv := reflect.ValueOf(slice) - if rv.Kind() != reflect.Slice { - return &LabelCreateBulk{err: fmt.Errorf("calling to LabelClient.MapCreateBulk with wrong type %T, need slice", slice)} - } - builders := make([]*LabelCreate, rv.Len()) - for i := 0; i < rv.Len(); i++ { - builders[i] = c.Create() - setFunc(builders[i], i) - } - return &LabelCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Label. -func (c *LabelClient) Update() *LabelUpdate { - mutation := newLabelMutation(c.config, OpUpdate) - return &LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *LabelClient) UpdateOne(_m *Label) *LabelUpdateOne { - mutation := newLabelMutation(c.config, OpUpdateOne, withLabel(_m)) - return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *LabelClient) UpdateOneID(id uuid.UUID) *LabelUpdateOne { - mutation := newLabelMutation(c.config, OpUpdateOne, withLabelID(id)) - return &LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Label. -func (c *LabelClient) Delete() *LabelDelete { - mutation := newLabelMutation(c.config, OpDelete) - return &LabelDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *LabelClient) DeleteOne(_m *Label) *LabelDeleteOne { - return c.DeleteOneID(_m.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *LabelClient) DeleteOneID(id uuid.UUID) *LabelDeleteOne { - builder := c.Delete().Where(label.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &LabelDeleteOne{builder} -} - -// Query returns a query builder for Label. -func (c *LabelClient) Query() *LabelQuery { - return &LabelQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeLabel}, - inters: c.Interceptors(), - } -} - -// Get returns a Label entity by its id. -func (c *LabelClient) Get(ctx context.Context, id uuid.UUID) (*Label, error) { - return c.Query().Where(label.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *LabelClient) GetX(ctx context.Context, id uuid.UUID) *Label { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryGroup queries the group edge of a Label. -func (c *LabelClient) QueryGroup(_m *Label) *GroupQuery { - query := (&GroupClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := _m.ID - step := sqlgraph.NewStep( - sqlgraph.From(label.Table, label.FieldID, id), - sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, label.GroupTable, label.GroupColumn), - ) - fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// QueryItems queries the items edge of a Label. -func (c *LabelClient) QueryItems(_m *Label) *ItemQuery { - query := (&ItemClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := _m.ID - step := sqlgraph.NewStep( - sqlgraph.From(label.Table, label.FieldID, id), - sqlgraph.To(item.Table, item.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, label.ItemsTable, label.ItemsPrimaryKey...), - ) - fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *LabelClient) Hooks() []Hook { - return c.hooks.Label -} - -// Interceptors returns the client interceptors. -func (c *LabelClient) Interceptors() []Interceptor { - return c.inters.Label -} - -func (c *LabelClient) mutate(ctx context.Context, m *LabelMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&LabelCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&LabelUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&LabelUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&LabelDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown Label mutation op: %q", m.Op()) - } -} - // LocationClient is a client for the Location schema. type LocationClient struct { config @@ -2454,6 +2289,171 @@ func (c *NotifierClient) mutate(ctx context.Context, m *NotifierMutation) (Value } } +// TagClient is a client for the Tag schema. +type TagClient struct { + config +} + +// NewTagClient returns a client for the Tag from the given config. +func NewTagClient(c config) *TagClient { + return &TagClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `tag.Hooks(f(g(h())))`. +func (c *TagClient) Use(hooks ...Hook) { + c.hooks.Tag = append(c.hooks.Tag, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `tag.Intercept(f(g(h())))`. +func (c *TagClient) Intercept(interceptors ...Interceptor) { + c.inters.Tag = append(c.inters.Tag, interceptors...) +} + +// Create returns a builder for creating a Tag entity. +func (c *TagClient) Create() *TagCreate { + mutation := newTagMutation(c.config, OpCreate) + return &TagCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Tag entities. +func (c *TagClient) CreateBulk(builders ...*TagCreate) *TagCreateBulk { + return &TagCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TagClient) MapCreateBulk(slice any, setFunc func(*TagCreate, int)) *TagCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TagCreateBulk{err: fmt.Errorf("calling to TagClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TagCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TagCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Tag. +func (c *TagClient) Update() *TagUpdate { + mutation := newTagMutation(c.config, OpUpdate) + return &TagUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *TagClient) UpdateOne(_m *Tag) *TagUpdateOne { + mutation := newTagMutation(c.config, OpUpdateOne, withTag(_m)) + return &TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *TagClient) UpdateOneID(id uuid.UUID) *TagUpdateOne { + mutation := newTagMutation(c.config, OpUpdateOne, withTagID(id)) + return &TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Tag. +func (c *TagClient) Delete() *TagDelete { + mutation := newTagMutation(c.config, OpDelete) + return &TagDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *TagClient) DeleteOne(_m *Tag) *TagDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *TagClient) DeleteOneID(id uuid.UUID) *TagDeleteOne { + builder := c.Delete().Where(tag.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &TagDeleteOne{builder} +} + +// Query returns a query builder for Tag. +func (c *TagClient) Query() *TagQuery { + return &TagQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeTag}, + inters: c.Interceptors(), + } +} + +// Get returns a Tag entity by its id. +func (c *TagClient) Get(ctx context.Context, id uuid.UUID) (*Tag, error) { + return c.Query().Where(tag.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *TagClient) GetX(ctx context.Context, id uuid.UUID) *Tag { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryGroup queries the group edge of a Tag. +func (c *TagClient) QueryGroup(_m *Tag) *GroupQuery { + query := (&GroupClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(tag.Table, tag.FieldID, id), + sqlgraph.To(group.Table, group.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, tag.GroupTable, tag.GroupColumn), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryItems queries the items edge of a Tag. +func (c *TagClient) QueryItems(_m *Tag) *ItemQuery { + query := (&ItemClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := _m.ID + step := sqlgraph.NewStep( + sqlgraph.From(tag.Table, tag.FieldID, id), + sqlgraph.To(item.Table, item.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, tag.ItemsTable, tag.ItemsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *TagClient) Hooks() []Hook { + return c.hooks.Tag +} + +// Interceptors returns the client interceptors. +func (c *TagClient) Interceptors() []Interceptor { + return c.inters.Tag +} + +func (c *TagClient) mutate(ctx context.Context, m *TagMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TagCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TagUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TagDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Tag mutation op: %q", m.Op()) + } +} + // TemplateFieldClient is a client for the TemplateField schema. type TemplateFieldClient struct { config @@ -2788,12 +2788,12 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) type ( hooks struct { Attachment, AuthRoles, AuthTokens, Group, GroupInvitationToken, Item, ItemField, - ItemTemplate, Label, Location, MaintenanceEntry, Notifier, TemplateField, + ItemTemplate, Location, MaintenanceEntry, Notifier, Tag, TemplateField, User []ent.Hook } inters struct { Attachment, AuthRoles, AuthTokens, Group, GroupInvitationToken, Item, ItemField, - ItemTemplate, Label, Location, MaintenanceEntry, Notifier, TemplateField, + ItemTemplate, Location, MaintenanceEntry, Notifier, Tag, TemplateField, User []ent.Interceptor } ) diff --git a/backend/internal/data/ent/ent.go b/backend/internal/data/ent/ent.go index ee3abfa7..8ec73e0b 100644 --- a/backend/internal/data/ent/ent.go +++ b/backend/internal/data/ent/ent.go @@ -20,10 +20,10 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -94,10 +94,10 @@ func checkColumn(t, c string) error { item.Table: item.ValidColumn, itemfield.Table: itemfield.ValidColumn, itemtemplate.Table: itemtemplate.ValidColumn, - label.Table: label.ValidColumn, location.Table: location.ValidColumn, maintenanceentry.Table: maintenanceentry.ValidColumn, notifier.Table: notifier.ValidColumn, + tag.Table: tag.ValidColumn, templatefield.Table: templatefield.ValidColumn, user.Table: user.ValidColumn, }) diff --git a/backend/internal/data/ent/group.go b/backend/internal/data/ent/group.go index d20782b9..85e0b35d 100644 --- a/backend/internal/data/ent/group.go +++ b/backend/internal/data/ent/group.go @@ -40,8 +40,8 @@ type GroupEdges struct { Locations []*Location `json:"locations,omitempty"` // Items holds the value of the items edge. Items []*Item `json:"items,omitempty"` - // Labels holds the value of the labels edge. - Labels []*Label `json:"labels,omitempty"` + // Tags holds the value of the tags edge. + Tags []*Tag `json:"tags,omitempty"` // InvitationTokens holds the value of the invitation_tokens edge. InvitationTokens []*GroupInvitationToken `json:"invitation_tokens,omitempty"` // Notifiers holds the value of the notifiers edge. @@ -80,13 +80,13 @@ func (e GroupEdges) ItemsOrErr() ([]*Item, error) { return nil, &NotLoadedError{edge: "items"} } -// LabelsOrErr returns the Labels value or an error if the edge +// TagsOrErr returns the Tags value or an error if the edge // was not loaded in eager-loading. -func (e GroupEdges) LabelsOrErr() ([]*Label, error) { +func (e GroupEdges) TagsOrErr() ([]*Tag, error) { if e.loadedTypes[3] { - return e.Labels, nil + return e.Tags, nil } - return nil, &NotLoadedError{edge: "labels"} + return nil, &NotLoadedError{edge: "tags"} } // InvitationTokensOrErr returns the InvitationTokens value or an error if the edge @@ -200,9 +200,9 @@ func (_m *Group) QueryItems() *ItemQuery { return NewGroupClient(_m.config).QueryItems(_m) } -// QueryLabels queries the "labels" edge of the Group entity. -func (_m *Group) QueryLabels() *LabelQuery { - return NewGroupClient(_m.config).QueryLabels(_m) +// QueryTags queries the "tags" edge of the Group entity. +func (_m *Group) QueryTags() *TagQuery { + return NewGroupClient(_m.config).QueryTags(_m) } // QueryInvitationTokens queries the "invitation_tokens" edge of the Group entity. diff --git a/backend/internal/data/ent/group/group.go b/backend/internal/data/ent/group/group.go index 80dc3398..012703c6 100644 --- a/backend/internal/data/ent/group/group.go +++ b/backend/internal/data/ent/group/group.go @@ -29,8 +29,8 @@ const ( EdgeLocations = "locations" // EdgeItems holds the string denoting the items edge name in mutations. EdgeItems = "items" - // EdgeLabels holds the string denoting the labels edge name in mutations. - EdgeLabels = "labels" + // EdgeTags holds the string denoting the tags edge name in mutations. + EdgeTags = "tags" // EdgeInvitationTokens holds the string denoting the invitation_tokens edge name in mutations. EdgeInvitationTokens = "invitation_tokens" // EdgeNotifiers holds the string denoting the notifiers edge name in mutations. @@ -60,13 +60,13 @@ const ( ItemsInverseTable = "items" // ItemsColumn is the table column denoting the items relation/edge. ItemsColumn = "group_items" - // LabelsTable is the table that holds the labels relation/edge. - LabelsTable = "labels" - // LabelsInverseTable is the table name for the Label entity. - // It exists in this package in order to avoid circular dependency with the "label" package. - LabelsInverseTable = "labels" - // LabelsColumn is the table column denoting the labels relation/edge. - LabelsColumn = "group_labels" + // TagsTable is the table that holds the tags relation/edge. + TagsTable = "tags" + // TagsInverseTable is the table name for the Tag entity. + // It exists in this package in order to avoid circular dependency with the "tag" package. + TagsInverseTable = "tags" + // TagsColumn is the table column denoting the tags relation/edge. + TagsColumn = "group_tags" // InvitationTokensTable is the table that holds the invitation_tokens relation/edge. InvitationTokensTable = "group_invitation_tokens" // InvitationTokensInverseTable is the table name for the GroupInvitationToken entity. @@ -194,17 +194,17 @@ func ByItems(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } -// ByLabelsCount orders the results by labels count. -func ByLabelsCount(opts ...sql.OrderTermOption) OrderOption { +// ByTagsCount orders the results by tags count. +func ByTagsCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newLabelsStep(), opts...) + sqlgraph.OrderByNeighborsCount(s, newTagsStep(), opts...) } } -// ByLabels orders the results by labels terms. -func ByLabels(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { +// ByTags orders the results by tags terms. +func ByTags(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newLabelsStep(), append([]sql.OrderTerm{term}, terms...)...) + sqlgraph.OrderByNeighborTerms(s, newTagsStep(), append([]sql.OrderTerm{term}, terms...)...) } } @@ -270,11 +270,11 @@ func newItemsStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, ItemsTable, ItemsColumn), ) } -func newLabelsStep() *sqlgraph.Step { +func newTagsStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(LabelsInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, LabelsTable, LabelsColumn), + sqlgraph.To(TagsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, TagsTable, TagsColumn), ) } func newInvitationTokensStep() *sqlgraph.Step { diff --git a/backend/internal/data/ent/group/where.go b/backend/internal/data/ent/group/where.go index fec4b27c..3453a362 100644 --- a/backend/internal/data/ent/group/where.go +++ b/backend/internal/data/ent/group/where.go @@ -355,21 +355,21 @@ func HasItemsWith(preds ...predicate.Item) predicate.Group { }) } -// HasLabels applies the HasEdge predicate on the "labels" edge. -func HasLabels() predicate.Group { +// HasTags applies the HasEdge predicate on the "tags" edge. +func HasTags() predicate.Group { return predicate.Group(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, LabelsTable, LabelsColumn), + sqlgraph.Edge(sqlgraph.O2M, false, TagsTable, TagsColumn), ) sqlgraph.HasNeighbors(s, step) }) } -// HasLabelsWith applies the HasEdge predicate on the "labels" edge with a given conditions (other predicates). -func HasLabelsWith(preds ...predicate.Label) predicate.Group { +// HasTagsWith applies the HasEdge predicate on the "tags" edge with a given conditions (other predicates). +func HasTagsWith(preds ...predicate.Tag) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := newLabelsStep() + step := newTagsStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) diff --git a/backend/internal/data/ent/group_create.go b/backend/internal/data/ent/group_create.go index 9eb4bac1..b78c0cf0 100644 --- a/backend/internal/data/ent/group_create.go +++ b/backend/internal/data/ent/group_create.go @@ -15,9 +15,9 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -135,19 +135,19 @@ func (_c *GroupCreate) AddItems(v ...*Item) *GroupCreate { return _c.AddItemIDs(ids...) } -// AddLabelIDs adds the "labels" edge to the Label entity by IDs. -func (_c *GroupCreate) AddLabelIDs(ids ...uuid.UUID) *GroupCreate { - _c.mutation.AddLabelIDs(ids...) +// AddTagIDs adds the "tags" edge to the Tag entity by IDs. +func (_c *GroupCreate) AddTagIDs(ids ...uuid.UUID) *GroupCreate { + _c.mutation.AddTagIDs(ids...) return _c } -// AddLabels adds the "labels" edges to the Label entity. -func (_c *GroupCreate) AddLabels(v ...*Label) *GroupCreate { +// AddTags adds the "tags" edges to the Tag entity. +func (_c *GroupCreate) AddTags(v ...*Tag) *GroupCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _c.AddLabelIDs(ids...) + return _c.AddTagIDs(ids...) } // AddInvitationTokenIDs adds the "invitation_tokens" edge to the GroupInvitationToken entity by IDs. @@ -366,15 +366,15 @@ func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } - if nodes := _c.mutation.LabelsIDs(); len(nodes) > 0 { + if nodes := _c.mutation.TagsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: group.LabelsTable, - Columns: []string{group.LabelsColumn}, + Table: group.TagsTable, + Columns: []string{group.TagsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/backend/internal/data/ent/group_query.go b/backend/internal/data/ent/group_query.go index 20124988..75ab91d9 100644 --- a/backend/internal/data/ent/group_query.go +++ b/backend/internal/data/ent/group_query.go @@ -17,10 +17,10 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -34,7 +34,7 @@ type GroupQuery struct { withUsers *UserQuery withLocations *LocationQuery withItems *ItemQuery - withLabels *LabelQuery + withTags *TagQuery withInvitationTokens *GroupInvitationTokenQuery withNotifiers *NotifierQuery withItemTemplates *ItemTemplateQuery @@ -140,9 +140,9 @@ func (_q *GroupQuery) QueryItems() *ItemQuery { return query } -// QueryLabels chains the current query on the "labels" edge. -func (_q *GroupQuery) QueryLabels() *LabelQuery { - query := (&LabelClient{config: _q.config}).Query() +// QueryTags chains the current query on the "tags" edge. +func (_q *GroupQuery) QueryTags() *TagQuery { + query := (&TagClient{config: _q.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := _q.prepareQuery(ctx); err != nil { return nil, err @@ -153,8 +153,8 @@ func (_q *GroupQuery) QueryLabels() *LabelQuery { } step := sqlgraph.NewStep( sqlgraph.From(group.Table, group.FieldID, selector), - sqlgraph.To(label.Table, label.FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, group.LabelsTable, group.LabelsColumn), + sqlgraph.To(tag.Table, tag.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, group.TagsTable, group.TagsColumn), ) fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) return fromU, nil @@ -423,7 +423,7 @@ func (_q *GroupQuery) Clone() *GroupQuery { withUsers: _q.withUsers.Clone(), withLocations: _q.withLocations.Clone(), withItems: _q.withItems.Clone(), - withLabels: _q.withLabels.Clone(), + withTags: _q.withTags.Clone(), withInvitationTokens: _q.withInvitationTokens.Clone(), withNotifiers: _q.withNotifiers.Clone(), withItemTemplates: _q.withItemTemplates.Clone(), @@ -466,14 +466,14 @@ func (_q *GroupQuery) WithItems(opts ...func(*ItemQuery)) *GroupQuery { return _q } -// WithLabels tells the query-builder to eager-load the nodes that are connected to -// the "labels" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *GroupQuery) WithLabels(opts ...func(*LabelQuery)) *GroupQuery { - query := (&LabelClient{config: _q.config}).Query() +// WithTags tells the query-builder to eager-load the nodes that are connected to +// the "tags" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *GroupQuery) WithTags(opts ...func(*TagQuery)) *GroupQuery { + query := (&TagClient{config: _q.config}).Query() for _, opt := range opts { opt(query) } - _q.withLabels = query + _q.withTags = query return _q } @@ -592,7 +592,7 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group, _q.withUsers != nil, _q.withLocations != nil, _q.withItems != nil, - _q.withLabels != nil, + _q.withTags != nil, _q.withInvitationTokens != nil, _q.withNotifiers != nil, _q.withItemTemplates != nil, @@ -637,10 +637,10 @@ func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group, return nil, err } } - if query := _q.withLabels; query != nil { - if err := _q.loadLabels(ctx, query, nodes, - func(n *Group) { n.Edges.Labels = []*Label{} }, - func(n *Group, e *Label) { n.Edges.Labels = append(n.Edges.Labels, e) }); err != nil { + if query := _q.withTags; query != nil { + if err := _q.loadTags(ctx, query, nodes, + func(n *Group) { n.Edges.Tags = []*Tag{} }, + func(n *Group, e *Tag) { n.Edges.Tags = append(n.Edges.Tags, e) }); err != nil { return nil, err } } @@ -763,7 +763,7 @@ func (_q *GroupQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []* } return nil } -func (_q *GroupQuery) loadLabels(ctx context.Context, query *LabelQuery, nodes []*Group, init func(*Group), assign func(*Group, *Label)) error { +func (_q *GroupQuery) loadTags(ctx context.Context, query *TagQuery, nodes []*Group, init func(*Group), assign func(*Group, *Tag)) error { fks := make([]driver.Value, 0, len(nodes)) nodeids := make(map[uuid.UUID]*Group) for i := range nodes { @@ -774,21 +774,21 @@ func (_q *GroupQuery) loadLabels(ctx context.Context, query *LabelQuery, nodes [ } } query.withFKs = true - query.Where(predicate.Label(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(group.LabelsColumn), fks...)) + query.Where(predicate.Tag(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(group.TagsColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { return err } for _, n := range neighbors { - fk := n.group_labels + fk := n.group_tags if fk == nil { - return fmt.Errorf(`foreign-key "group_labels" is nil for node %v`, n.ID) + return fmt.Errorf(`foreign-key "group_tags" is nil for node %v`, n.ID) } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "group_labels" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "group_tags" returned %v for node %v`, *fk, n.ID) } assign(node, n) } diff --git a/backend/internal/data/ent/group_update.go b/backend/internal/data/ent/group_update.go index d0190d49..fd42d974 100644 --- a/backend/internal/data/ent/group_update.go +++ b/backend/internal/data/ent/group_update.go @@ -16,10 +16,10 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -115,19 +115,19 @@ func (_u *GroupUpdate) AddItems(v ...*Item) *GroupUpdate { return _u.AddItemIDs(ids...) } -// AddLabelIDs adds the "labels" edge to the Label entity by IDs. -func (_u *GroupUpdate) AddLabelIDs(ids ...uuid.UUID) *GroupUpdate { - _u.mutation.AddLabelIDs(ids...) +// AddTagIDs adds the "tags" edge to the Tag entity by IDs. +func (_u *GroupUpdate) AddTagIDs(ids ...uuid.UUID) *GroupUpdate { + _u.mutation.AddTagIDs(ids...) return _u } -// AddLabels adds the "labels" edges to the Label entity. -func (_u *GroupUpdate) AddLabels(v ...*Label) *GroupUpdate { +// AddTags adds the "tags" edges to the Tag entity. +func (_u *GroupUpdate) AddTags(v ...*Tag) *GroupUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.AddLabelIDs(ids...) + return _u.AddTagIDs(ids...) } // AddInvitationTokenIDs adds the "invitation_tokens" edge to the GroupInvitationToken entity by IDs. @@ -243,25 +243,25 @@ func (_u *GroupUpdate) RemoveItems(v ...*Item) *GroupUpdate { return _u.RemoveItemIDs(ids...) } -// ClearLabels clears all "labels" edges to the Label entity. -func (_u *GroupUpdate) ClearLabels() *GroupUpdate { - _u.mutation.ClearLabels() +// ClearTags clears all "tags" edges to the Tag entity. +func (_u *GroupUpdate) ClearTags() *GroupUpdate { + _u.mutation.ClearTags() return _u } -// RemoveLabelIDs removes the "labels" edge to Label entities by IDs. -func (_u *GroupUpdate) RemoveLabelIDs(ids ...uuid.UUID) *GroupUpdate { - _u.mutation.RemoveLabelIDs(ids...) +// RemoveTagIDs removes the "tags" edge to Tag entities by IDs. +func (_u *GroupUpdate) RemoveTagIDs(ids ...uuid.UUID) *GroupUpdate { + _u.mutation.RemoveTagIDs(ids...) return _u } -// RemoveLabels removes "labels" edges to Label entities. -func (_u *GroupUpdate) RemoveLabels(v ...*Label) *GroupUpdate { +// RemoveTags removes "tags" edges to Tag entities. +func (_u *GroupUpdate) RemoveTags(v ...*Tag) *GroupUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.RemoveLabelIDs(ids...) + return _u.RemoveTagIDs(ids...) } // ClearInvitationTokens clears all "invitation_tokens" edges to the GroupInvitationToken entity. @@ -529,28 +529,28 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if _u.mutation.LabelsCleared() { + if _u.mutation.TagsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: group.LabelsTable, - Columns: []string{group.LabelsColumn}, + Table: group.TagsTable, + Columns: []string{group.TagsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.RemovedLabelsIDs(); len(nodes) > 0 && !_u.mutation.LabelsCleared() { + if nodes := _u.mutation.RemovedTagsIDs(); len(nodes) > 0 && !_u.mutation.TagsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: group.LabelsTable, - Columns: []string{group.LabelsColumn}, + Table: group.TagsTable, + Columns: []string{group.TagsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -558,15 +558,15 @@ func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.LabelsIDs(); len(nodes) > 0 { + if nodes := _u.mutation.TagsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: group.LabelsTable, - Columns: []string{group.LabelsColumn}, + Table: group.TagsTable, + Columns: []string{group.TagsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -808,19 +808,19 @@ func (_u *GroupUpdateOne) AddItems(v ...*Item) *GroupUpdateOne { return _u.AddItemIDs(ids...) } -// AddLabelIDs adds the "labels" edge to the Label entity by IDs. -func (_u *GroupUpdateOne) AddLabelIDs(ids ...uuid.UUID) *GroupUpdateOne { - _u.mutation.AddLabelIDs(ids...) +// AddTagIDs adds the "tags" edge to the Tag entity by IDs. +func (_u *GroupUpdateOne) AddTagIDs(ids ...uuid.UUID) *GroupUpdateOne { + _u.mutation.AddTagIDs(ids...) return _u } -// AddLabels adds the "labels" edges to the Label entity. -func (_u *GroupUpdateOne) AddLabels(v ...*Label) *GroupUpdateOne { +// AddTags adds the "tags" edges to the Tag entity. +func (_u *GroupUpdateOne) AddTags(v ...*Tag) *GroupUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.AddLabelIDs(ids...) + return _u.AddTagIDs(ids...) } // AddInvitationTokenIDs adds the "invitation_tokens" edge to the GroupInvitationToken entity by IDs. @@ -936,25 +936,25 @@ func (_u *GroupUpdateOne) RemoveItems(v ...*Item) *GroupUpdateOne { return _u.RemoveItemIDs(ids...) } -// ClearLabels clears all "labels" edges to the Label entity. -func (_u *GroupUpdateOne) ClearLabels() *GroupUpdateOne { - _u.mutation.ClearLabels() +// ClearTags clears all "tags" edges to the Tag entity. +func (_u *GroupUpdateOne) ClearTags() *GroupUpdateOne { + _u.mutation.ClearTags() return _u } -// RemoveLabelIDs removes the "labels" edge to Label entities by IDs. -func (_u *GroupUpdateOne) RemoveLabelIDs(ids ...uuid.UUID) *GroupUpdateOne { - _u.mutation.RemoveLabelIDs(ids...) +// RemoveTagIDs removes the "tags" edge to Tag entities by IDs. +func (_u *GroupUpdateOne) RemoveTagIDs(ids ...uuid.UUID) *GroupUpdateOne { + _u.mutation.RemoveTagIDs(ids...) return _u } -// RemoveLabels removes "labels" edges to Label entities. -func (_u *GroupUpdateOne) RemoveLabels(v ...*Label) *GroupUpdateOne { +// RemoveTags removes "tags" edges to Tag entities. +func (_u *GroupUpdateOne) RemoveTags(v ...*Tag) *GroupUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.RemoveLabelIDs(ids...) + return _u.RemoveTagIDs(ids...) } // ClearInvitationTokens clears all "invitation_tokens" edges to the GroupInvitationToken entity. @@ -1252,28 +1252,28 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if _u.mutation.LabelsCleared() { + if _u.mutation.TagsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: group.LabelsTable, - Columns: []string{group.LabelsColumn}, + Table: group.TagsTable, + Columns: []string{group.TagsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.RemovedLabelsIDs(); len(nodes) > 0 && !_u.mutation.LabelsCleared() { + if nodes := _u.mutation.RemovedTagsIDs(); len(nodes) > 0 && !_u.mutation.TagsCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: group.LabelsTable, - Columns: []string{group.LabelsColumn}, + Table: group.TagsTable, + Columns: []string{group.TagsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1281,15 +1281,15 @@ func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.LabelsIDs(); len(nodes) > 0 { + if nodes := _u.mutation.TagsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: false, - Table: group.LabelsTable, - Columns: []string{group.LabelsColumn}, + Table: group.TagsTable, + Columns: []string{group.TagsColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/backend/internal/data/ent/has_id.go b/backend/internal/data/ent/has_id.go index faf28d4e..ad3c89eb 100644 --- a/backend/internal/data/ent/has_id.go +++ b/backend/internal/data/ent/has_id.go @@ -36,10 +36,6 @@ func (_m *ItemTemplate) GetID() uuid.UUID { return _m.ID } -func (_m *Label) GetID() uuid.UUID { - return _m.ID -} - func (_m *Location) GetID() uuid.UUID { return _m.ID } @@ -52,6 +48,10 @@ func (_m *Notifier) GetID() uuid.UUID { return _m.ID } +func (_m *Tag) GetID() uuid.UUID { + return _m.ID +} + func (_m *TemplateField) GetID() uuid.UUID { return _m.ID } diff --git a/backend/internal/data/ent/hook/hook.go b/backend/internal/data/ent/hook/hook.go index 6859da52..c303dd41 100644 --- a/backend/internal/data/ent/hook/hook.go +++ b/backend/internal/data/ent/hook/hook.go @@ -105,18 +105,6 @@ func (f ItemTemplateFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ItemTemplateMutation", m) } -// The LabelFunc type is an adapter to allow the use of ordinary -// function as Label mutator. -type LabelFunc func(context.Context, *ent.LabelMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f LabelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.LabelMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelMutation", m) -} - // The LocationFunc type is an adapter to allow the use of ordinary // function as Location mutator. type LocationFunc func(context.Context, *ent.LocationMutation) (ent.Value, error) @@ -153,6 +141,18 @@ func (f NotifierFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.NotifierMutation", m) } +// The TagFunc type is an adapter to allow the use of ordinary +// function as Tag mutator. +type TagFunc func(context.Context, *ent.TagMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f TagFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.TagMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TagMutation", m) +} + // The TemplateFieldFunc type is an adapter to allow the use of ordinary // function as TemplateField mutator. type TemplateFieldFunc func(context.Context, *ent.TemplateFieldMutation) (ent.Value, error) diff --git a/backend/internal/data/ent/item.go b/backend/internal/data/ent/item.go index 27c4f38d..f937937f 100644 --- a/backend/internal/data/ent/item.go +++ b/backend/internal/data/ent/item.go @@ -85,8 +85,8 @@ type ItemEdges struct { Parent *Item `json:"parent,omitempty"` // Children holds the value of the children edge. Children []*Item `json:"children,omitempty"` - // Label holds the value of the label edge. - Label []*Label `json:"label,omitempty"` + // Tag holds the value of the tag edge. + Tag []*Tag `json:"tag,omitempty"` // Location holds the value of the location edge. Location *Location `json:"location,omitempty"` // Fields holds the value of the fields edge. @@ -131,13 +131,13 @@ func (e ItemEdges) ChildrenOrErr() ([]*Item, error) { return nil, &NotLoadedError{edge: "children"} } -// LabelOrErr returns the Label value or an error if the edge +// TagOrErr returns the Tag value or an error if the edge // was not loaded in eager-loading. -func (e ItemEdges) LabelOrErr() ([]*Label, error) { +func (e ItemEdges) TagOrErr() ([]*Tag, error) { if e.loadedTypes[3] { - return e.Label, nil + return e.Tag, nil } - return nil, &NotLoadedError{edge: "label"} + return nil, &NotLoadedError{edge: "tag"} } // LocationOrErr returns the Location value or an error if the edge @@ -415,9 +415,9 @@ func (_m *Item) QueryChildren() *ItemQuery { return NewItemClient(_m.config).QueryChildren(_m) } -// QueryLabel queries the "label" edge of the Item entity. -func (_m *Item) QueryLabel() *LabelQuery { - return NewItemClient(_m.config).QueryLabel(_m) +// QueryTag queries the "tag" edge of the Item entity. +func (_m *Item) QueryTag() *TagQuery { + return NewItemClient(_m.config).QueryTag(_m) } // QueryLocation queries the "location" edge of the Item entity. diff --git a/backend/internal/data/ent/item/item.go b/backend/internal/data/ent/item/item.go index d3601c64..4c4c27db 100644 --- a/backend/internal/data/ent/item/item.go +++ b/backend/internal/data/ent/item/item.go @@ -69,8 +69,8 @@ const ( EdgeParent = "parent" // EdgeChildren holds the string denoting the children edge name in mutations. EdgeChildren = "children" - // EdgeLabel holds the string denoting the label edge name in mutations. - EdgeLabel = "label" + // EdgeTag holds the string denoting the tag edge name in mutations. + EdgeTag = "tag" // EdgeLocation holds the string denoting the location edge name in mutations. EdgeLocation = "location" // EdgeFields holds the string denoting the fields edge name in mutations. @@ -96,11 +96,11 @@ const ( ChildrenTable = "items" // ChildrenColumn is the table column denoting the children relation/edge. ChildrenColumn = "item_children" - // LabelTable is the table that holds the label relation/edge. The primary key declared below. - LabelTable = "label_items" - // LabelInverseTable is the table name for the Label entity. - // It exists in this package in order to avoid circular dependency with the "label" package. - LabelInverseTable = "labels" + // TagTable is the table that holds the tag relation/edge. The primary key declared below. + TagTable = "tag_items" + // TagInverseTable is the table name for the Tag entity. + // It exists in this package in order to avoid circular dependency with the "tag" package. + TagInverseTable = "tags" // LocationTable is the table that holds the location relation/edge. LocationTable = "items" // LocationInverseTable is the table name for the Location entity. @@ -169,9 +169,9 @@ var ForeignKeys = []string{ } var ( - // LabelPrimaryKey and LabelColumn2 are the table columns denoting the - // primary key for the label relation (M2M). - LabelPrimaryKey = []string{"label_id", "item_id"} + // TagPrimaryKey and TagColumn2 are the table columns denoting the + // primary key for the tag relation (M2M). + TagPrimaryKey = []string{"tag_id", "item_id"} ) // ValidColumn reports if the column name is valid (part of the table columns). @@ -390,17 +390,17 @@ func ByChildren(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { } } -// ByLabelCount orders the results by label count. -func ByLabelCount(opts ...sql.OrderTermOption) OrderOption { +// ByTagCount orders the results by tag count. +func ByTagCount(opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newLabelStep(), opts...) + sqlgraph.OrderByNeighborsCount(s, newTagStep(), opts...) } } -// ByLabel orders the results by label terms. -func ByLabel(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { +// ByTag orders the results by tag terms. +func ByTag(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newLabelStep(), append([]sql.OrderTerm{term}, terms...)...) + sqlgraph.OrderByNeighborTerms(s, newTagStep(), append([]sql.OrderTerm{term}, terms...)...) } } @@ -473,11 +473,11 @@ func newChildrenStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.O2M, false, ChildrenTable, ChildrenColumn), ) } -func newLabelStep() *sqlgraph.Step { +func newTagStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(LabelInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, LabelTable, LabelPrimaryKey...), + sqlgraph.To(TagInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, TagTable, TagPrimaryKey...), ) } func newLocationStep() *sqlgraph.Step { diff --git a/backend/internal/data/ent/item/where.go b/backend/internal/data/ent/item/where.go index 5166fa54..65a76a7e 100644 --- a/backend/internal/data/ent/item/where.go +++ b/backend/internal/data/ent/item/where.go @@ -1490,21 +1490,21 @@ func HasChildrenWith(preds ...predicate.Item) predicate.Item { }) } -// HasLabel applies the HasEdge predicate on the "label" edge. -func HasLabel() predicate.Item { +// HasTag applies the HasEdge predicate on the "tag" edge. +func HasTag() predicate.Item { return predicate.Item(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, LabelTable, LabelPrimaryKey...), + sqlgraph.Edge(sqlgraph.M2M, true, TagTable, TagPrimaryKey...), ) sqlgraph.HasNeighbors(s, step) }) } -// HasLabelWith applies the HasEdge predicate on the "label" edge with a given conditions (other predicates). -func HasLabelWith(preds ...predicate.Label) predicate.Item { +// HasTagWith applies the HasEdge predicate on the "tag" edge with a given conditions (other predicates). +func HasTagWith(preds ...predicate.Tag) predicate.Item { return predicate.Item(func(s *sql.Selector) { - step := newLabelStep() + step := newTagStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) diff --git a/backend/internal/data/ent/item_create.go b/backend/internal/data/ent/item_create.go index 48a77a8e..98f74fe1 100644 --- a/backend/internal/data/ent/item_create.go +++ b/backend/internal/data/ent/item_create.go @@ -15,9 +15,9 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) // ItemCreate is the builder for creating a Item entity. @@ -414,19 +414,19 @@ func (_c *ItemCreate) AddChildren(v ...*Item) *ItemCreate { return _c.AddChildIDs(ids...) } -// AddLabelIDs adds the "label" edge to the Label entity by IDs. -func (_c *ItemCreate) AddLabelIDs(ids ...uuid.UUID) *ItemCreate { - _c.mutation.AddLabelIDs(ids...) +// AddTagIDs adds the "tag" edge to the Tag entity by IDs. +func (_c *ItemCreate) AddTagIDs(ids ...uuid.UUID) *ItemCreate { + _c.mutation.AddTagIDs(ids...) return _c } -// AddLabel adds the "label" edges to the Label entity. -func (_c *ItemCreate) AddLabel(v ...*Label) *ItemCreate { +// AddTag adds the "tag" edges to the Tag entity. +func (_c *ItemCreate) AddTag(v ...*Tag) *ItemCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _c.AddLabelIDs(ids...) + return _c.AddTagIDs(ids...) } // SetLocationID sets the "location" edge to the Location entity by ID. @@ -838,15 +838,15 @@ func (_c *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) { } _spec.Edges = append(_spec.Edges, edge) } - if nodes := _c.mutation.LabelIDs(); len(nodes) > 0 { + if nodes := _c.mutation.TagIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, + Table: item.TagTable, + Columns: item.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/backend/internal/data/ent/item_query.go b/backend/internal/data/ent/item_query.go index 8cb32410..15658a78 100644 --- a/backend/internal/data/ent/item_query.go +++ b/backend/internal/data/ent/item_query.go @@ -17,10 +17,10 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) // ItemQuery is the builder for querying Item entities. @@ -33,7 +33,7 @@ type ItemQuery struct { withGroup *GroupQuery withParent *ItemQuery withChildren *ItemQuery - withLabel *LabelQuery + withTag *TagQuery withLocation *LocationQuery withFields *ItemFieldQuery withMaintenanceEntries *MaintenanceEntryQuery @@ -141,9 +141,9 @@ func (_q *ItemQuery) QueryChildren() *ItemQuery { return query } -// QueryLabel chains the current query on the "label" edge. -func (_q *ItemQuery) QueryLabel() *LabelQuery { - query := (&LabelClient{config: _q.config}).Query() +// QueryTag chains the current query on the "tag" edge. +func (_q *ItemQuery) QueryTag() *TagQuery { + query := (&TagClient{config: _q.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := _q.prepareQuery(ctx); err != nil { return nil, err @@ -154,8 +154,8 @@ func (_q *ItemQuery) QueryLabel() *LabelQuery { } step := sqlgraph.NewStep( sqlgraph.From(item.Table, item.FieldID, selector), - sqlgraph.To(label.Table, label.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, item.LabelTable, item.LabelPrimaryKey...), + sqlgraph.To(tag.Table, tag.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, item.TagTable, item.TagPrimaryKey...), ) fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) return fromU, nil @@ -446,7 +446,7 @@ func (_q *ItemQuery) Clone() *ItemQuery { withGroup: _q.withGroup.Clone(), withParent: _q.withParent.Clone(), withChildren: _q.withChildren.Clone(), - withLabel: _q.withLabel.Clone(), + withTag: _q.withTag.Clone(), withLocation: _q.withLocation.Clone(), withFields: _q.withFields.Clone(), withMaintenanceEntries: _q.withMaintenanceEntries.Clone(), @@ -490,14 +490,14 @@ func (_q *ItemQuery) WithChildren(opts ...func(*ItemQuery)) *ItemQuery { return _q } -// WithLabel tells the query-builder to eager-load the nodes that are connected to -// the "label" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *ItemQuery) WithLabel(opts ...func(*LabelQuery)) *ItemQuery { - query := (&LabelClient{config: _q.config}).Query() +// WithTag tells the query-builder to eager-load the nodes that are connected to +// the "tag" edge. The optional arguments are used to configure the query builder of the edge. +func (_q *ItemQuery) WithTag(opts ...func(*TagQuery)) *ItemQuery { + query := (&TagClient{config: _q.config}).Query() for _, opt := range opts { opt(query) } - _q.withLabel = query + _q.withTag = query return _q } @@ -628,7 +628,7 @@ func (_q *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e _q.withGroup != nil, _q.withParent != nil, _q.withChildren != nil, - _q.withLabel != nil, + _q.withTag != nil, _q.withLocation != nil, _q.withFields != nil, _q.withMaintenanceEntries != nil, @@ -678,10 +678,10 @@ func (_q *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e return nil, err } } - if query := _q.withLabel; query != nil { - if err := _q.loadLabel(ctx, query, nodes, - func(n *Item) { n.Edges.Label = []*Label{} }, - func(n *Item, e *Label) { n.Edges.Label = append(n.Edges.Label, e) }); err != nil { + if query := _q.withTag; query != nil { + if err := _q.loadTag(ctx, query, nodes, + func(n *Item) { n.Edges.Tag = []*Tag{} }, + func(n *Item, e *Tag) { n.Edges.Tag = append(n.Edges.Tag, e) }); err != nil { return nil, err } } @@ -810,7 +810,7 @@ func (_q *ItemQuery) loadChildren(ctx context.Context, query *ItemQuery, nodes [ } return nil } -func (_q *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []*Item, init func(*Item), assign func(*Item, *Label)) error { +func (_q *ItemQuery) loadTag(ctx context.Context, query *TagQuery, nodes []*Item, init func(*Item), assign func(*Item, *Tag)) error { edgeIDs := make([]driver.Value, len(nodes)) byID := make(map[uuid.UUID]*Item) nids := make(map[uuid.UUID]map[*Item]struct{}) @@ -822,11 +822,11 @@ func (_q *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []* } } query.Where(func(s *sql.Selector) { - joinT := sql.Table(item.LabelTable) - s.Join(joinT).On(s.C(label.FieldID), joinT.C(item.LabelPrimaryKey[0])) - s.Where(sql.InValues(joinT.C(item.LabelPrimaryKey[1]), edgeIDs...)) + joinT := sql.Table(item.TagTable) + s.Join(joinT).On(s.C(tag.FieldID), joinT.C(item.TagPrimaryKey[0])) + s.Where(sql.InValues(joinT.C(item.TagPrimaryKey[1]), edgeIDs...)) columns := s.SelectedColumns() - s.Select(joinT.C(item.LabelPrimaryKey[1])) + s.Select(joinT.C(item.TagPrimaryKey[1])) s.AppendSelect(columns...) s.SetDistinct(false) }) @@ -856,14 +856,14 @@ func (_q *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []* } }) }) - neighbors, err := withInterceptors[[]*Label](ctx, query, qr, query.inters) + neighbors, err := withInterceptors[[]*Tag](ctx, query, qr, query.inters) if err != nil { return err } for _, n := range neighbors { nodes, ok := nids[n.ID] if !ok { - return fmt.Errorf(`unexpected "label" node returned %v`, n.ID) + return fmt.Errorf(`unexpected "tag" node returned %v`, n.ID) } for kn := range nodes { assign(kn, n) diff --git a/backend/internal/data/ent/item_update.go b/backend/internal/data/ent/item_update.go index 1ff6c01b..b730651e 100644 --- a/backend/internal/data/ent/item_update.go +++ b/backend/internal/data/ent/item_update.go @@ -16,10 +16,10 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) // ItemUpdate is the builder for updating Item entities. @@ -500,19 +500,19 @@ func (_u *ItemUpdate) AddChildren(v ...*Item) *ItemUpdate { return _u.AddChildIDs(ids...) } -// AddLabelIDs adds the "label" edge to the Label entity by IDs. -func (_u *ItemUpdate) AddLabelIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.AddLabelIDs(ids...) +// AddTagIDs adds the "tag" edge to the Tag entity by IDs. +func (_u *ItemUpdate) AddTagIDs(ids ...uuid.UUID) *ItemUpdate { + _u.mutation.AddTagIDs(ids...) return _u } -// AddLabel adds the "label" edges to the Label entity. -func (_u *ItemUpdate) AddLabel(v ...*Label) *ItemUpdate { +// AddTag adds the "tag" edges to the Tag entity. +func (_u *ItemUpdate) AddTag(v ...*Tag) *ItemUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.AddLabelIDs(ids...) + return _u.AddTagIDs(ids...) } // SetLocationID sets the "location" edge to the Location entity by ID. @@ -617,25 +617,25 @@ func (_u *ItemUpdate) RemoveChildren(v ...*Item) *ItemUpdate { return _u.RemoveChildIDs(ids...) } -// ClearLabel clears all "label" edges to the Label entity. -func (_u *ItemUpdate) ClearLabel() *ItemUpdate { - _u.mutation.ClearLabel() +// ClearTag clears all "tag" edges to the Tag entity. +func (_u *ItemUpdate) ClearTag() *ItemUpdate { + _u.mutation.ClearTag() return _u } -// RemoveLabelIDs removes the "label" edge to Label entities by IDs. -func (_u *ItemUpdate) RemoveLabelIDs(ids ...uuid.UUID) *ItemUpdate { - _u.mutation.RemoveLabelIDs(ids...) +// RemoveTagIDs removes the "tag" edge to Tag entities by IDs. +func (_u *ItemUpdate) RemoveTagIDs(ids ...uuid.UUID) *ItemUpdate { + _u.mutation.RemoveTagIDs(ids...) return _u } -// RemoveLabel removes "label" edges to Label entities. -func (_u *ItemUpdate) RemoveLabel(v ...*Label) *ItemUpdate { +// RemoveTag removes "tag" edges to Tag entities. +func (_u *ItemUpdate) RemoveTag(v ...*Tag) *ItemUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.RemoveLabelIDs(ids...) + return _u.RemoveTagIDs(ids...) } // ClearLocation clears the "location" edge to the Location entity. @@ -1031,28 +1031,28 @@ func (_u *ItemUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if _u.mutation.LabelCleared() { + if _u.mutation.TagCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, + Table: item.TagTable, + Columns: item.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.RemovedLabelIDs(); len(nodes) > 0 && !_u.mutation.LabelCleared() { + if nodes := _u.mutation.RemovedTagIDs(); len(nodes) > 0 && !_u.mutation.TagCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, + Table: item.TagTable, + Columns: item.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1060,15 +1060,15 @@ func (_u *ItemUpdate) sqlSave(ctx context.Context) (_node int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.LabelIDs(); len(nodes) > 0 { + if nodes := _u.mutation.TagIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, + Table: item.TagTable, + Columns: item.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1725,19 +1725,19 @@ func (_u *ItemUpdateOne) AddChildren(v ...*Item) *ItemUpdateOne { return _u.AddChildIDs(ids...) } -// AddLabelIDs adds the "label" edge to the Label entity by IDs. -func (_u *ItemUpdateOne) AddLabelIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.AddLabelIDs(ids...) +// AddTagIDs adds the "tag" edge to the Tag entity by IDs. +func (_u *ItemUpdateOne) AddTagIDs(ids ...uuid.UUID) *ItemUpdateOne { + _u.mutation.AddTagIDs(ids...) return _u } -// AddLabel adds the "label" edges to the Label entity. -func (_u *ItemUpdateOne) AddLabel(v ...*Label) *ItemUpdateOne { +// AddTag adds the "tag" edges to the Tag entity. +func (_u *ItemUpdateOne) AddTag(v ...*Tag) *ItemUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.AddLabelIDs(ids...) + return _u.AddTagIDs(ids...) } // SetLocationID sets the "location" edge to the Location entity by ID. @@ -1842,25 +1842,25 @@ func (_u *ItemUpdateOne) RemoveChildren(v ...*Item) *ItemUpdateOne { return _u.RemoveChildIDs(ids...) } -// ClearLabel clears all "label" edges to the Label entity. -func (_u *ItemUpdateOne) ClearLabel() *ItemUpdateOne { - _u.mutation.ClearLabel() +// ClearTag clears all "tag" edges to the Tag entity. +func (_u *ItemUpdateOne) ClearTag() *ItemUpdateOne { + _u.mutation.ClearTag() return _u } -// RemoveLabelIDs removes the "label" edge to Label entities by IDs. -func (_u *ItemUpdateOne) RemoveLabelIDs(ids ...uuid.UUID) *ItemUpdateOne { - _u.mutation.RemoveLabelIDs(ids...) +// RemoveTagIDs removes the "tag" edge to Tag entities by IDs. +func (_u *ItemUpdateOne) RemoveTagIDs(ids ...uuid.UUID) *ItemUpdateOne { + _u.mutation.RemoveTagIDs(ids...) return _u } -// RemoveLabel removes "label" edges to Label entities. -func (_u *ItemUpdateOne) RemoveLabel(v ...*Label) *ItemUpdateOne { +// RemoveTag removes "tag" edges to Tag entities. +func (_u *ItemUpdateOne) RemoveTag(v ...*Tag) *ItemUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID } - return _u.RemoveLabelIDs(ids...) + return _u.RemoveTagIDs(ids...) } // ClearLocation clears the "location" edge to the Location entity. @@ -2286,28 +2286,28 @@ func (_u *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) { } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if _u.mutation.LabelCleared() { + if _u.mutation.TagCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, + Table: item.TagTable, + Columns: item.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.RemovedLabelIDs(); len(nodes) > 0 && !_u.mutation.LabelCleared() { + if nodes := _u.mutation.RemovedTagIDs(); len(nodes) > 0 && !_u.mutation.TagCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, + Table: item.TagTable, + Columns: item.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -2315,15 +2315,15 @@ func (_u *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := _u.mutation.LabelIDs(); len(nodes) > 0 { + if nodes := _u.mutation.TagIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: true, - Table: item.LabelTable, - Columns: item.LabelPrimaryKey, + Table: item.TagTable, + Columns: item.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID), + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/backend/internal/data/ent/itemtemplate.go b/backend/internal/data/ent/itemtemplate.go index 0d9f1f2f..6d498b93 100644 --- a/backend/internal/data/ent/itemtemplate.go +++ b/backend/internal/data/ent/itemtemplate.go @@ -53,8 +53,8 @@ type ItemTemplate struct { IncludePurchaseFields bool `json:"include_purchase_fields,omitempty"` // Whether to include sold fields in items created from this template IncludeSoldFields bool `json:"include_sold_fields,omitempty"` - // Default label IDs for items created from this template - DefaultLabelIds []uuid.UUID `json:"default_label_ids,omitempty"` + // Default tag IDs for items created from this template + DefaultTagIds []uuid.UUID `json:"default_tag_ids,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the ItemTemplateQuery when eager-loading is set. Edges ItemTemplateEdges `json:"edges"` @@ -112,7 +112,7 @@ func (*ItemTemplate) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case itemtemplate.FieldDefaultLabelIds: + case itemtemplate.FieldDefaultTagIds: values[i] = new([]byte) case itemtemplate.FieldDefaultInsured, itemtemplate.FieldDefaultLifetimeWarranty, itemtemplate.FieldIncludeWarrantyFields, itemtemplate.FieldIncludePurchaseFields, itemtemplate.FieldIncludeSoldFields: values[i] = new(sql.NullBool) @@ -245,12 +245,12 @@ func (_m *ItemTemplate) assignValues(columns []string, values []any) error { } else if value.Valid { _m.IncludeSoldFields = value.Bool } - case itemtemplate.FieldDefaultLabelIds: + case itemtemplate.FieldDefaultTagIds: if value, ok := values[i].(*[]byte); !ok { - return fmt.Errorf("unexpected type %T for field default_label_ids", values[i]) + return fmt.Errorf("unexpected type %T for field default_tag_ids", values[i]) } else if value != nil && len(*value) > 0 { - if err := json.Unmarshal(*value, &_m.DefaultLabelIds); err != nil { - return fmt.Errorf("unmarshal field default_label_ids: %w", err) + if err := json.Unmarshal(*value, &_m.DefaultTagIds); err != nil { + return fmt.Errorf("unmarshal field default_tag_ids: %w", err) } } case itemtemplate.ForeignKeys[0]: @@ -366,8 +366,8 @@ func (_m *ItemTemplate) String() string { builder.WriteString("include_sold_fields=") builder.WriteString(fmt.Sprintf("%v", _m.IncludeSoldFields)) builder.WriteString(", ") - builder.WriteString("default_label_ids=") - builder.WriteString(fmt.Sprintf("%v", _m.DefaultLabelIds)) + builder.WriteString("default_tag_ids=") + builder.WriteString(fmt.Sprintf("%v", _m.DefaultTagIds)) builder.WriteByte(')') return builder.String() } diff --git a/backend/internal/data/ent/itemtemplate/itemtemplate.go b/backend/internal/data/ent/itemtemplate/itemtemplate.go index ac308b9d..5f1e8c0b 100644 --- a/backend/internal/data/ent/itemtemplate/itemtemplate.go +++ b/backend/internal/data/ent/itemtemplate/itemtemplate.go @@ -47,8 +47,8 @@ const ( FieldIncludePurchaseFields = "include_purchase_fields" // FieldIncludeSoldFields holds the string denoting the include_sold_fields field in the database. FieldIncludeSoldFields = "include_sold_fields" - // FieldDefaultLabelIds holds the string denoting the default_label_ids field in the database. - FieldDefaultLabelIds = "default_label_ids" + // FieldDefaultTagIds holds the string denoting the default_tag_ids field in the database. + FieldDefaultTagIds = "default_tag_ids" // EdgeGroup holds the string denoting the group edge name in mutations. EdgeGroup = "group" // EdgeFields holds the string denoting the fields edge name in mutations. @@ -99,7 +99,7 @@ var Columns = []string{ FieldIncludeWarrantyFields, FieldIncludePurchaseFields, FieldIncludeSoldFields, - FieldDefaultLabelIds, + FieldDefaultTagIds, } // ForeignKeys holds the SQL foreign-keys that are owned by the "item_templates" diff --git a/backend/internal/data/ent/itemtemplate/where.go b/backend/internal/data/ent/itemtemplate/where.go index 1ade7376..e5a4910a 100644 --- a/backend/internal/data/ent/itemtemplate/where.go +++ b/backend/internal/data/ent/itemtemplate/where.go @@ -896,14 +896,14 @@ func IncludeSoldFieldsNEQ(v bool) predicate.ItemTemplate { return predicate.ItemTemplate(sql.FieldNEQ(FieldIncludeSoldFields, v)) } -// DefaultLabelIdsIsNil applies the IsNil predicate on the "default_label_ids" field. -func DefaultLabelIdsIsNil() predicate.ItemTemplate { - return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultLabelIds)) +// DefaultTagIdsIsNil applies the IsNil predicate on the "default_tag_ids" field. +func DefaultTagIdsIsNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldIsNull(FieldDefaultTagIds)) } -// DefaultLabelIdsNotNil applies the NotNil predicate on the "default_label_ids" field. -func DefaultLabelIdsNotNil() predicate.ItemTemplate { - return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultLabelIds)) +// DefaultTagIdsNotNil applies the NotNil predicate on the "default_tag_ids" field. +func DefaultTagIdsNotNil() predicate.ItemTemplate { + return predicate.ItemTemplate(sql.FieldNotNull(FieldDefaultTagIds)) } // HasGroup applies the HasEdge predicate on the "group" edge. diff --git a/backend/internal/data/ent/itemtemplate_create.go b/backend/internal/data/ent/itemtemplate_create.go index 30abd074..8a0f818e 100644 --- a/backend/internal/data/ent/itemtemplate_create.go +++ b/backend/internal/data/ent/itemtemplate_create.go @@ -240,9 +240,9 @@ func (_c *ItemTemplateCreate) SetNillableIncludeSoldFields(v *bool) *ItemTemplat return _c } -// SetDefaultLabelIds sets the "default_label_ids" field. -func (_c *ItemTemplateCreate) SetDefaultLabelIds(v []uuid.UUID) *ItemTemplateCreate { - _c.mutation.SetDefaultLabelIds(v) +// SetDefaultTagIds sets the "default_tag_ids" field. +func (_c *ItemTemplateCreate) SetDefaultTagIds(v []uuid.UUID) *ItemTemplateCreate { + _c.mutation.SetDefaultTagIds(v) return _c } @@ -549,9 +549,9 @@ func (_c *ItemTemplateCreate) createSpec() (*ItemTemplate, *sqlgraph.CreateSpec) _spec.SetField(itemtemplate.FieldIncludeSoldFields, field.TypeBool, value) _node.IncludeSoldFields = value } - if value, ok := _c.mutation.DefaultLabelIds(); ok { - _spec.SetField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON, value) - _node.DefaultLabelIds = value + if value, ok := _c.mutation.DefaultTagIds(); ok { + _spec.SetField(itemtemplate.FieldDefaultTagIds, field.TypeJSON, value) + _node.DefaultTagIds = value } if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ diff --git a/backend/internal/data/ent/itemtemplate_update.go b/backend/internal/data/ent/itemtemplate_update.go index 768505ba..b0368255 100644 --- a/backend/internal/data/ent/itemtemplate_update.go +++ b/backend/internal/data/ent/itemtemplate_update.go @@ -284,21 +284,21 @@ func (_u *ItemTemplateUpdate) SetNillableIncludeSoldFields(v *bool) *ItemTemplat return _u } -// SetDefaultLabelIds sets the "default_label_ids" field. -func (_u *ItemTemplateUpdate) SetDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdate { - _u.mutation.SetDefaultLabelIds(v) +// SetDefaultTagIds sets the "default_tag_ids" field. +func (_u *ItemTemplateUpdate) SetDefaultTagIds(v []uuid.UUID) *ItemTemplateUpdate { + _u.mutation.SetDefaultTagIds(v) return _u } -// AppendDefaultLabelIds appends value to the "default_label_ids" field. -func (_u *ItemTemplateUpdate) AppendDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdate { - _u.mutation.AppendDefaultLabelIds(v) +// AppendDefaultTagIds appends value to the "default_tag_ids" field. +func (_u *ItemTemplateUpdate) AppendDefaultTagIds(v []uuid.UUID) *ItemTemplateUpdate { + _u.mutation.AppendDefaultTagIds(v) return _u } -// ClearDefaultLabelIds clears the value of the "default_label_ids" field. -func (_u *ItemTemplateUpdate) ClearDefaultLabelIds() *ItemTemplateUpdate { - _u.mutation.ClearDefaultLabelIds() +// ClearDefaultTagIds clears the value of the "default_tag_ids" field. +func (_u *ItemTemplateUpdate) ClearDefaultTagIds() *ItemTemplateUpdate { + _u.mutation.ClearDefaultTagIds() return _u } @@ -550,16 +550,16 @@ func (_u *ItemTemplateUpdate) sqlSave(ctx context.Context) (_node int, err error if value, ok := _u.mutation.IncludeSoldFields(); ok { _spec.SetField(itemtemplate.FieldIncludeSoldFields, field.TypeBool, value) } - if value, ok := _u.mutation.DefaultLabelIds(); ok { - _spec.SetField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON, value) + if value, ok := _u.mutation.DefaultTagIds(); ok { + _spec.SetField(itemtemplate.FieldDefaultTagIds, field.TypeJSON, value) } - if value, ok := _u.mutation.AppendedDefaultLabelIds(); ok { + if value, ok := _u.mutation.AppendedDefaultTagIds(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { - sqljson.Append(u, itemtemplate.FieldDefaultLabelIds, value) + sqljson.Append(u, itemtemplate.FieldDefaultTagIds, value) }) } - if _u.mutation.DefaultLabelIdsCleared() { - _spec.ClearField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON) + if _u.mutation.DefaultTagIdsCleared() { + _spec.ClearField(itemtemplate.FieldDefaultTagIds, field.TypeJSON) } if _u.mutation.GroupCleared() { edge := &sqlgraph.EdgeSpec{ @@ -935,21 +935,21 @@ func (_u *ItemTemplateUpdateOne) SetNillableIncludeSoldFields(v *bool) *ItemTemp return _u } -// SetDefaultLabelIds sets the "default_label_ids" field. -func (_u *ItemTemplateUpdateOne) SetDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdateOne { - _u.mutation.SetDefaultLabelIds(v) +// SetDefaultTagIds sets the "default_tag_ids" field. +func (_u *ItemTemplateUpdateOne) SetDefaultTagIds(v []uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.SetDefaultTagIds(v) return _u } -// AppendDefaultLabelIds appends value to the "default_label_ids" field. -func (_u *ItemTemplateUpdateOne) AppendDefaultLabelIds(v []uuid.UUID) *ItemTemplateUpdateOne { - _u.mutation.AppendDefaultLabelIds(v) +// AppendDefaultTagIds appends value to the "default_tag_ids" field. +func (_u *ItemTemplateUpdateOne) AppendDefaultTagIds(v []uuid.UUID) *ItemTemplateUpdateOne { + _u.mutation.AppendDefaultTagIds(v) return _u } -// ClearDefaultLabelIds clears the value of the "default_label_ids" field. -func (_u *ItemTemplateUpdateOne) ClearDefaultLabelIds() *ItemTemplateUpdateOne { - _u.mutation.ClearDefaultLabelIds() +// ClearDefaultTagIds clears the value of the "default_tag_ids" field. +func (_u *ItemTemplateUpdateOne) ClearDefaultTagIds() *ItemTemplateUpdateOne { + _u.mutation.ClearDefaultTagIds() return _u } @@ -1231,16 +1231,16 @@ func (_u *ItemTemplateUpdateOne) sqlSave(ctx context.Context) (_node *ItemTempla if value, ok := _u.mutation.IncludeSoldFields(); ok { _spec.SetField(itemtemplate.FieldIncludeSoldFields, field.TypeBool, value) } - if value, ok := _u.mutation.DefaultLabelIds(); ok { - _spec.SetField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON, value) + if value, ok := _u.mutation.DefaultTagIds(); ok { + _spec.SetField(itemtemplate.FieldDefaultTagIds, field.TypeJSON, value) } - if value, ok := _u.mutation.AppendedDefaultLabelIds(); ok { + if value, ok := _u.mutation.AppendedDefaultTagIds(); ok { _spec.AddModifier(func(u *sql.UpdateBuilder) { - sqljson.Append(u, itemtemplate.FieldDefaultLabelIds, value) + sqljson.Append(u, itemtemplate.FieldDefaultTagIds, value) }) } - if _u.mutation.DefaultLabelIdsCleared() { - _spec.ClearField(itemtemplate.FieldDefaultLabelIds, field.TypeJSON) + if _u.mutation.DefaultTagIdsCleared() { + _spec.ClearField(itemtemplate.FieldDefaultTagIds, field.TypeJSON) } if _u.mutation.GroupCleared() { edge := &sqlgraph.EdgeSpec{ diff --git a/backend/internal/data/ent/label/where.go b/backend/internal/data/ent/label/where.go deleted file mode 100644 index 7a2f2403..00000000 --- a/backend/internal/data/ent/label/where.go +++ /dev/null @@ -1,438 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package label - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "github.com/google/uuid" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id uuid.UUID) predicate.Label { - return predicate.Label(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldCreatedAt, v)) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// Name applies equality check predicate on the "name" field. It's identical to NameEQ. -func Name(v string) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldName, v)) -} - -// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. -func Description(v string) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldDescription, v)) -} - -// Color applies equality check predicate on the "color" field. It's identical to ColorEQ. -func Color(v string) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldColor, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Label { - return predicate.Label(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Label { - return predicate.Label(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Label { - return predicate.Label(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Label { - return predicate.Label(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Label { - return predicate.Label(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Label { - return predicate.Label(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Label { - return predicate.Label(sql.FieldLTE(FieldCreatedAt, v)) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Label { - return predicate.Label(sql.FieldNEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Label { - return predicate.Label(sql.FieldIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Label { - return predicate.Label(sql.FieldNotIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Label { - return predicate.Label(sql.FieldGT(FieldUpdatedAt, v)) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Label { - return predicate.Label(sql.FieldGTE(FieldUpdatedAt, v)) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Label { - return predicate.Label(sql.FieldLT(FieldUpdatedAt, v)) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Label { - return predicate.Label(sql.FieldLTE(FieldUpdatedAt, v)) -} - -// NameEQ applies the EQ predicate on the "name" field. -func NameEQ(v string) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldName, v)) -} - -// NameNEQ applies the NEQ predicate on the "name" field. -func NameNEQ(v string) predicate.Label { - return predicate.Label(sql.FieldNEQ(FieldName, v)) -} - -// NameIn applies the In predicate on the "name" field. -func NameIn(vs ...string) predicate.Label { - return predicate.Label(sql.FieldIn(FieldName, vs...)) -} - -// NameNotIn applies the NotIn predicate on the "name" field. -func NameNotIn(vs ...string) predicate.Label { - return predicate.Label(sql.FieldNotIn(FieldName, vs...)) -} - -// NameGT applies the GT predicate on the "name" field. -func NameGT(v string) predicate.Label { - return predicate.Label(sql.FieldGT(FieldName, v)) -} - -// NameGTE applies the GTE predicate on the "name" field. -func NameGTE(v string) predicate.Label { - return predicate.Label(sql.FieldGTE(FieldName, v)) -} - -// NameLT applies the LT predicate on the "name" field. -func NameLT(v string) predicate.Label { - return predicate.Label(sql.FieldLT(FieldName, v)) -} - -// NameLTE applies the LTE predicate on the "name" field. -func NameLTE(v string) predicate.Label { - return predicate.Label(sql.FieldLTE(FieldName, v)) -} - -// NameContains applies the Contains predicate on the "name" field. -func NameContains(v string) predicate.Label { - return predicate.Label(sql.FieldContains(FieldName, v)) -} - -// NameHasPrefix applies the HasPrefix predicate on the "name" field. -func NameHasPrefix(v string) predicate.Label { - return predicate.Label(sql.FieldHasPrefix(FieldName, v)) -} - -// NameHasSuffix applies the HasSuffix predicate on the "name" field. -func NameHasSuffix(v string) predicate.Label { - return predicate.Label(sql.FieldHasSuffix(FieldName, v)) -} - -// NameEqualFold applies the EqualFold predicate on the "name" field. -func NameEqualFold(v string) predicate.Label { - return predicate.Label(sql.FieldEqualFold(FieldName, v)) -} - -// NameContainsFold applies the ContainsFold predicate on the "name" field. -func NameContainsFold(v string) predicate.Label { - return predicate.Label(sql.FieldContainsFold(FieldName, v)) -} - -// DescriptionEQ applies the EQ predicate on the "description" field. -func DescriptionEQ(v string) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldDescription, v)) -} - -// DescriptionNEQ applies the NEQ predicate on the "description" field. -func DescriptionNEQ(v string) predicate.Label { - return predicate.Label(sql.FieldNEQ(FieldDescription, v)) -} - -// DescriptionIn applies the In predicate on the "description" field. -func DescriptionIn(vs ...string) predicate.Label { - return predicate.Label(sql.FieldIn(FieldDescription, vs...)) -} - -// DescriptionNotIn applies the NotIn predicate on the "description" field. -func DescriptionNotIn(vs ...string) predicate.Label { - return predicate.Label(sql.FieldNotIn(FieldDescription, vs...)) -} - -// DescriptionGT applies the GT predicate on the "description" field. -func DescriptionGT(v string) predicate.Label { - return predicate.Label(sql.FieldGT(FieldDescription, v)) -} - -// DescriptionGTE applies the GTE predicate on the "description" field. -func DescriptionGTE(v string) predicate.Label { - return predicate.Label(sql.FieldGTE(FieldDescription, v)) -} - -// DescriptionLT applies the LT predicate on the "description" field. -func DescriptionLT(v string) predicate.Label { - return predicate.Label(sql.FieldLT(FieldDescription, v)) -} - -// DescriptionLTE applies the LTE predicate on the "description" field. -func DescriptionLTE(v string) predicate.Label { - return predicate.Label(sql.FieldLTE(FieldDescription, v)) -} - -// DescriptionContains applies the Contains predicate on the "description" field. -func DescriptionContains(v string) predicate.Label { - return predicate.Label(sql.FieldContains(FieldDescription, v)) -} - -// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. -func DescriptionHasPrefix(v string) predicate.Label { - return predicate.Label(sql.FieldHasPrefix(FieldDescription, v)) -} - -// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. -func DescriptionHasSuffix(v string) predicate.Label { - return predicate.Label(sql.FieldHasSuffix(FieldDescription, v)) -} - -// DescriptionIsNil applies the IsNil predicate on the "description" field. -func DescriptionIsNil() predicate.Label { - return predicate.Label(sql.FieldIsNull(FieldDescription)) -} - -// DescriptionNotNil applies the NotNil predicate on the "description" field. -func DescriptionNotNil() predicate.Label { - return predicate.Label(sql.FieldNotNull(FieldDescription)) -} - -// DescriptionEqualFold applies the EqualFold predicate on the "description" field. -func DescriptionEqualFold(v string) predicate.Label { - return predicate.Label(sql.FieldEqualFold(FieldDescription, v)) -} - -// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. -func DescriptionContainsFold(v string) predicate.Label { - return predicate.Label(sql.FieldContainsFold(FieldDescription, v)) -} - -// ColorEQ applies the EQ predicate on the "color" field. -func ColorEQ(v string) predicate.Label { - return predicate.Label(sql.FieldEQ(FieldColor, v)) -} - -// ColorNEQ applies the NEQ predicate on the "color" field. -func ColorNEQ(v string) predicate.Label { - return predicate.Label(sql.FieldNEQ(FieldColor, v)) -} - -// ColorIn applies the In predicate on the "color" field. -func ColorIn(vs ...string) predicate.Label { - return predicate.Label(sql.FieldIn(FieldColor, vs...)) -} - -// ColorNotIn applies the NotIn predicate on the "color" field. -func ColorNotIn(vs ...string) predicate.Label { - return predicate.Label(sql.FieldNotIn(FieldColor, vs...)) -} - -// ColorGT applies the GT predicate on the "color" field. -func ColorGT(v string) predicate.Label { - return predicate.Label(sql.FieldGT(FieldColor, v)) -} - -// ColorGTE applies the GTE predicate on the "color" field. -func ColorGTE(v string) predicate.Label { - return predicate.Label(sql.FieldGTE(FieldColor, v)) -} - -// ColorLT applies the LT predicate on the "color" field. -func ColorLT(v string) predicate.Label { - return predicate.Label(sql.FieldLT(FieldColor, v)) -} - -// ColorLTE applies the LTE predicate on the "color" field. -func ColorLTE(v string) predicate.Label { - return predicate.Label(sql.FieldLTE(FieldColor, v)) -} - -// ColorContains applies the Contains predicate on the "color" field. -func ColorContains(v string) predicate.Label { - return predicate.Label(sql.FieldContains(FieldColor, v)) -} - -// ColorHasPrefix applies the HasPrefix predicate on the "color" field. -func ColorHasPrefix(v string) predicate.Label { - return predicate.Label(sql.FieldHasPrefix(FieldColor, v)) -} - -// ColorHasSuffix applies the HasSuffix predicate on the "color" field. -func ColorHasSuffix(v string) predicate.Label { - return predicate.Label(sql.FieldHasSuffix(FieldColor, v)) -} - -// ColorIsNil applies the IsNil predicate on the "color" field. -func ColorIsNil() predicate.Label { - return predicate.Label(sql.FieldIsNull(FieldColor)) -} - -// ColorNotNil applies the NotNil predicate on the "color" field. -func ColorNotNil() predicate.Label { - return predicate.Label(sql.FieldNotNull(FieldColor)) -} - -// ColorEqualFold applies the EqualFold predicate on the "color" field. -func ColorEqualFold(v string) predicate.Label { - return predicate.Label(sql.FieldEqualFold(FieldColor, v)) -} - -// ColorContainsFold applies the ContainsFold predicate on the "color" field. -func ColorContainsFold(v string) predicate.Label { - return predicate.Label(sql.FieldContainsFold(FieldColor, v)) -} - -// HasGroup applies the HasEdge predicate on the "group" edge. -func HasGroup() predicate.Label { - return predicate.Label(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). -func HasGroupWith(preds ...predicate.Group) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - step := newGroupStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// HasItems applies the HasEdge predicate on the "items" edge. -func HasItems() predicate.Label { - return predicate.Label(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, ItemsTable, ItemsPrimaryKey...), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasItemsWith applies the HasEdge predicate on the "items" edge with a given conditions (other predicates). -func HasItemsWith(preds ...predicate.Item) predicate.Label { - return predicate.Label(func(s *sql.Selector) { - step := newItemsStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Label) predicate.Label { - return predicate.Label(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Label) predicate.Label { - return predicate.Label(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Label) predicate.Label { - return predicate.Label(sql.NotPredicates(p)) -} diff --git a/backend/internal/data/ent/migrate/schema.go b/backend/internal/data/ent/migrate/schema.go index ef6161d8..673c431f 100644 --- a/backend/internal/data/ent/migrate/schema.go +++ b/backend/internal/data/ent/migrate/schema.go @@ -265,7 +265,7 @@ var ( {Name: "include_warranty_fields", Type: field.TypeBool, Default: false}, {Name: "include_purchase_fields", Type: field.TypeBool, Default: false}, {Name: "include_sold_fields", Type: field.TypeBool, Default: false}, - {Name: "default_label_ids", Type: field.TypeJSON, Nullable: true}, + {Name: "default_tag_ids", Type: field.TypeJSON, Nullable: true}, {Name: "group_item_templates", Type: field.TypeUUID}, {Name: "item_template_location", Type: field.TypeUUID, Nullable: true}, } @@ -296,30 +296,6 @@ var ( }, }, } - // LabelsColumns holds the columns for the "labels" table. - LabelsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeUUID}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "updated_at", Type: field.TypeTime}, - {Name: "name", Type: field.TypeString, Size: 255}, - {Name: "description", Type: field.TypeString, Nullable: true, Size: 1000}, - {Name: "color", Type: field.TypeString, Nullable: true, Size: 255}, - {Name: "group_labels", Type: field.TypeUUID}, - } - // LabelsTable holds the schema information for the "labels" table. - LabelsTable = &schema.Table{ - Name: "labels", - Columns: LabelsColumns, - PrimaryKey: []*schema.Column{LabelsColumns[0]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "labels_groups_labels", - Columns: []*schema.Column{LabelsColumns[6]}, - RefColumns: []*schema.Column{GroupsColumns[0]}, - OnDelete: schema.Cascade, - }, - }, - } // LocationsColumns holds the columns for the "locations" table. LocationsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -429,6 +405,30 @@ var ( }, }, } + // TagsColumns holds the columns for the "tags" table. + TagsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "name", Type: field.TypeString, Size: 255}, + {Name: "description", Type: field.TypeString, Nullable: true, Size: 1000}, + {Name: "color", Type: field.TypeString, Nullable: true, Size: 255}, + {Name: "group_tags", Type: field.TypeUUID}, + } + // TagsTable holds the schema information for the "tags" table. + TagsTable = &schema.Table{ + Name: "tags", + Columns: TagsColumns, + PrimaryKey: []*schema.Column{TagsColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "tags_groups_tags", + Columns: []*schema.Column{TagsColumns[6]}, + RefColumns: []*schema.Column{GroupsColumns[0]}, + OnDelete: schema.Cascade, + }, + }, + } // TemplateFieldsColumns holds the columns for the "template_fields" table. TemplateFieldsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID}, @@ -491,26 +491,26 @@ var ( }, }, } - // LabelItemsColumns holds the columns for the "label_items" table. - LabelItemsColumns = []*schema.Column{ - {Name: "label_id", Type: field.TypeUUID}, + // TagItemsColumns holds the columns for the "tag_items" table. + TagItemsColumns = []*schema.Column{ + {Name: "tag_id", Type: field.TypeUUID}, {Name: "item_id", Type: field.TypeUUID}, } - // LabelItemsTable holds the schema information for the "label_items" table. - LabelItemsTable = &schema.Table{ - Name: "label_items", - Columns: LabelItemsColumns, - PrimaryKey: []*schema.Column{LabelItemsColumns[0], LabelItemsColumns[1]}, + // TagItemsTable holds the schema information for the "tag_items" table. + TagItemsTable = &schema.Table{ + Name: "tag_items", + Columns: TagItemsColumns, + PrimaryKey: []*schema.Column{TagItemsColumns[0], TagItemsColumns[1]}, ForeignKeys: []*schema.ForeignKey{ { - Symbol: "label_items_label_id", - Columns: []*schema.Column{LabelItemsColumns[0]}, - RefColumns: []*schema.Column{LabelsColumns[0]}, + Symbol: "tag_items_tag_id", + Columns: []*schema.Column{TagItemsColumns[0]}, + RefColumns: []*schema.Column{TagsColumns[0]}, OnDelete: schema.Cascade, }, { - Symbol: "label_items_item_id", - Columns: []*schema.Column{LabelItemsColumns[1]}, + Symbol: "tag_items_item_id", + Columns: []*schema.Column{TagItemsColumns[1]}, RefColumns: []*schema.Column{ItemsColumns[0]}, OnDelete: schema.Cascade, }, @@ -526,13 +526,13 @@ var ( ItemsTable, ItemFieldsTable, ItemTemplatesTable, - LabelsTable, LocationsTable, MaintenanceEntriesTable, NotifiersTable, + TagsTable, TemplateFieldsTable, UsersTable, - LabelItemsTable, + TagItemsTable, } ) @@ -548,14 +548,14 @@ func init() { ItemFieldsTable.ForeignKeys[0].RefTable = ItemsTable ItemTemplatesTable.ForeignKeys[0].RefTable = GroupsTable ItemTemplatesTable.ForeignKeys[1].RefTable = LocationsTable - LabelsTable.ForeignKeys[0].RefTable = GroupsTable LocationsTable.ForeignKeys[0].RefTable = GroupsTable LocationsTable.ForeignKeys[1].RefTable = LocationsTable MaintenanceEntriesTable.ForeignKeys[0].RefTable = ItemsTable NotifiersTable.ForeignKeys[0].RefTable = GroupsTable NotifiersTable.ForeignKeys[1].RefTable = UsersTable + TagsTable.ForeignKeys[0].RefTable = GroupsTable TemplateFieldsTable.ForeignKeys[0].RefTable = ItemTemplatesTable UsersTable.ForeignKeys[0].RefTable = GroupsTable - LabelItemsTable.ForeignKeys[0].RefTable = LabelsTable - LabelItemsTable.ForeignKeys[1].RefTable = ItemsTable + TagItemsTable.ForeignKeys[0].RefTable = TagsTable + TagItemsTable.ForeignKeys[1].RefTable = ItemsTable } diff --git a/backend/internal/data/ent/mutation.go b/backend/internal/data/ent/mutation.go index f5a1b13d..c2421caa 100644 --- a/backend/internal/data/ent/mutation.go +++ b/backend/internal/data/ent/mutation.go @@ -20,11 +20,11 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -46,10 +46,10 @@ const ( TypeItem = "Item" TypeItemField = "ItemField" TypeItemTemplate = "ItemTemplate" - TypeLabel = "Label" TypeLocation = "Location" TypeMaintenanceEntry = "MaintenanceEntry" TypeNotifier = "Notifier" + TypeTag = "Tag" TypeTemplateField = "TemplateField" TypeUser = "User" ) @@ -1869,9 +1869,9 @@ type GroupMutation struct { items map[uuid.UUID]struct{} removeditems map[uuid.UUID]struct{} cleareditems bool - labels map[uuid.UUID]struct{} - removedlabels map[uuid.UUID]struct{} - clearedlabels bool + tags map[uuid.UUID]struct{} + removedtags map[uuid.UUID]struct{} + clearedtags bool invitation_tokens map[uuid.UUID]struct{} removedinvitation_tokens map[uuid.UUID]struct{} clearedinvitation_tokens bool @@ -2296,58 +2296,58 @@ func (m *GroupMutation) ResetItems() { m.removeditems = nil } -// AddLabelIDs adds the "labels" edge to the Label entity by ids. -func (m *GroupMutation) AddLabelIDs(ids ...uuid.UUID) { - if m.labels == nil { - m.labels = make(map[uuid.UUID]struct{}) +// AddTagIDs adds the "tags" edge to the Tag entity by ids. +func (m *GroupMutation) AddTagIDs(ids ...uuid.UUID) { + if m.tags == nil { + m.tags = make(map[uuid.UUID]struct{}) } for i := range ids { - m.labels[ids[i]] = struct{}{} + m.tags[ids[i]] = struct{}{} } } -// ClearLabels clears the "labels" edge to the Label entity. -func (m *GroupMutation) ClearLabels() { - m.clearedlabels = true +// ClearTags clears the "tags" edge to the Tag entity. +func (m *GroupMutation) ClearTags() { + m.clearedtags = true } -// LabelsCleared reports if the "labels" edge to the Label entity was cleared. -func (m *GroupMutation) LabelsCleared() bool { - return m.clearedlabels +// TagsCleared reports if the "tags" edge to the Tag entity was cleared. +func (m *GroupMutation) TagsCleared() bool { + return m.clearedtags } -// RemoveLabelIDs removes the "labels" edge to the Label entity by IDs. -func (m *GroupMutation) RemoveLabelIDs(ids ...uuid.UUID) { - if m.removedlabels == nil { - m.removedlabels = make(map[uuid.UUID]struct{}) +// RemoveTagIDs removes the "tags" edge to the Tag entity by IDs. +func (m *GroupMutation) RemoveTagIDs(ids ...uuid.UUID) { + if m.removedtags == nil { + m.removedtags = make(map[uuid.UUID]struct{}) } for i := range ids { - delete(m.labels, ids[i]) - m.removedlabels[ids[i]] = struct{}{} + delete(m.tags, ids[i]) + m.removedtags[ids[i]] = struct{}{} } } -// RemovedLabels returns the removed IDs of the "labels" edge to the Label entity. -func (m *GroupMutation) RemovedLabelsIDs() (ids []uuid.UUID) { - for id := range m.removedlabels { +// RemovedTags returns the removed IDs of the "tags" edge to the Tag entity. +func (m *GroupMutation) RemovedTagsIDs() (ids []uuid.UUID) { + for id := range m.removedtags { ids = append(ids, id) } return } -// LabelsIDs returns the "labels" edge IDs in the mutation. -func (m *GroupMutation) LabelsIDs() (ids []uuid.UUID) { - for id := range m.labels { +// TagsIDs returns the "tags" edge IDs in the mutation. +func (m *GroupMutation) TagsIDs() (ids []uuid.UUID) { + for id := range m.tags { ids = append(ids, id) } return } -// ResetLabels resets all changes to the "labels" edge. -func (m *GroupMutation) ResetLabels() { - m.labels = nil - m.clearedlabels = false - m.removedlabels = nil +// ResetTags resets all changes to the "tags" edge. +func (m *GroupMutation) ResetTags() { + m.tags = nil + m.clearedtags = false + m.removedtags = nil } // AddInvitationTokenIDs adds the "invitation_tokens" edge to the GroupInvitationToken entity by ids. @@ -2706,8 +2706,8 @@ func (m *GroupMutation) AddedEdges() []string { if m.items != nil { edges = append(edges, group.EdgeItems) } - if m.labels != nil { - edges = append(edges, group.EdgeLabels) + if m.tags != nil { + edges = append(edges, group.EdgeTags) } if m.invitation_tokens != nil { edges = append(edges, group.EdgeInvitationTokens) @@ -2743,9 +2743,9 @@ func (m *GroupMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case group.EdgeLabels: - ids := make([]ent.Value, 0, len(m.labels)) - for id := range m.labels { + case group.EdgeTags: + ids := make([]ent.Value, 0, len(m.tags)) + for id := range m.tags { ids = append(ids, id) } return ids @@ -2783,8 +2783,8 @@ func (m *GroupMutation) RemovedEdges() []string { if m.removeditems != nil { edges = append(edges, group.EdgeItems) } - if m.removedlabels != nil { - edges = append(edges, group.EdgeLabels) + if m.removedtags != nil { + edges = append(edges, group.EdgeTags) } if m.removedinvitation_tokens != nil { edges = append(edges, group.EdgeInvitationTokens) @@ -2820,9 +2820,9 @@ func (m *GroupMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case group.EdgeLabels: - ids := make([]ent.Value, 0, len(m.removedlabels)) - for id := range m.removedlabels { + case group.EdgeTags: + ids := make([]ent.Value, 0, len(m.removedtags)) + for id := range m.removedtags { ids = append(ids, id) } return ids @@ -2860,8 +2860,8 @@ func (m *GroupMutation) ClearedEdges() []string { if m.cleareditems { edges = append(edges, group.EdgeItems) } - if m.clearedlabels { - edges = append(edges, group.EdgeLabels) + if m.clearedtags { + edges = append(edges, group.EdgeTags) } if m.clearedinvitation_tokens { edges = append(edges, group.EdgeInvitationTokens) @@ -2885,8 +2885,8 @@ func (m *GroupMutation) EdgeCleared(name string) bool { return m.clearedlocations case group.EdgeItems: return m.cleareditems - case group.EdgeLabels: - return m.clearedlabels + case group.EdgeTags: + return m.clearedtags case group.EdgeInvitationTokens: return m.clearedinvitation_tokens case group.EdgeNotifiers: @@ -2918,8 +2918,8 @@ func (m *GroupMutation) ResetEdge(name string) error { case group.EdgeItems: m.ResetItems() return nil - case group.EdgeLabels: - m.ResetLabels() + case group.EdgeTags: + m.ResetTags() return nil case group.EdgeInvitationTokens: m.ResetInvitationTokens() @@ -3627,9 +3627,9 @@ type ItemMutation struct { children map[uuid.UUID]struct{} removedchildren map[uuid.UUID]struct{} clearedchildren bool - label map[uuid.UUID]struct{} - removedlabel map[uuid.UUID]struct{} - clearedlabel bool + tag map[uuid.UUID]struct{} + removedtag map[uuid.UUID]struct{} + clearedtag bool location *uuid.UUID clearedlocation bool fields map[uuid.UUID]struct{} @@ -4995,58 +4995,58 @@ func (m *ItemMutation) ResetChildren() { m.removedchildren = nil } -// AddLabelIDs adds the "label" edge to the Label entity by ids. -func (m *ItemMutation) AddLabelIDs(ids ...uuid.UUID) { - if m.label == nil { - m.label = make(map[uuid.UUID]struct{}) +// AddTagIDs adds the "tag" edge to the Tag entity by ids. +func (m *ItemMutation) AddTagIDs(ids ...uuid.UUID) { + if m.tag == nil { + m.tag = make(map[uuid.UUID]struct{}) } for i := range ids { - m.label[ids[i]] = struct{}{} + m.tag[ids[i]] = struct{}{} } } -// ClearLabel clears the "label" edge to the Label entity. -func (m *ItemMutation) ClearLabel() { - m.clearedlabel = true +// ClearTag clears the "tag" edge to the Tag entity. +func (m *ItemMutation) ClearTag() { + m.clearedtag = true } -// LabelCleared reports if the "label" edge to the Label entity was cleared. -func (m *ItemMutation) LabelCleared() bool { - return m.clearedlabel +// TagCleared reports if the "tag" edge to the Tag entity was cleared. +func (m *ItemMutation) TagCleared() bool { + return m.clearedtag } -// RemoveLabelIDs removes the "label" edge to the Label entity by IDs. -func (m *ItemMutation) RemoveLabelIDs(ids ...uuid.UUID) { - if m.removedlabel == nil { - m.removedlabel = make(map[uuid.UUID]struct{}) +// RemoveTagIDs removes the "tag" edge to the Tag entity by IDs. +func (m *ItemMutation) RemoveTagIDs(ids ...uuid.UUID) { + if m.removedtag == nil { + m.removedtag = make(map[uuid.UUID]struct{}) } for i := range ids { - delete(m.label, ids[i]) - m.removedlabel[ids[i]] = struct{}{} + delete(m.tag, ids[i]) + m.removedtag[ids[i]] = struct{}{} } } -// RemovedLabel returns the removed IDs of the "label" edge to the Label entity. -func (m *ItemMutation) RemovedLabelIDs() (ids []uuid.UUID) { - for id := range m.removedlabel { +// RemovedTag returns the removed IDs of the "tag" edge to the Tag entity. +func (m *ItemMutation) RemovedTagIDs() (ids []uuid.UUID) { + for id := range m.removedtag { ids = append(ids, id) } return } -// LabelIDs returns the "label" edge IDs in the mutation. -func (m *ItemMutation) LabelIDs() (ids []uuid.UUID) { - for id := range m.label { +// TagIDs returns the "tag" edge IDs in the mutation. +func (m *ItemMutation) TagIDs() (ids []uuid.UUID) { + for id := range m.tag { ids = append(ids, id) } return } -// ResetLabel resets all changes to the "label" edge. -func (m *ItemMutation) ResetLabel() { - m.label = nil - m.clearedlabel = false - m.removedlabel = nil +// ResetTag resets all changes to the "tag" edge. +func (m *ItemMutation) ResetTag() { + m.tag = nil + m.clearedtag = false + m.removedtag = nil } // SetLocationID sets the "location" edge to the Location entity by id. @@ -5916,8 +5916,8 @@ func (m *ItemMutation) AddedEdges() []string { if m.children != nil { edges = append(edges, item.EdgeChildren) } - if m.label != nil { - edges = append(edges, item.EdgeLabel) + if m.tag != nil { + edges = append(edges, item.EdgeTag) } if m.location != nil { edges = append(edges, item.EdgeLocation) @@ -5952,9 +5952,9 @@ func (m *ItemMutation) AddedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case item.EdgeLabel: - ids := make([]ent.Value, 0, len(m.label)) - for id := range m.label { + case item.EdgeTag: + ids := make([]ent.Value, 0, len(m.tag)) + for id := range m.tag { ids = append(ids, id) } return ids @@ -5990,8 +5990,8 @@ func (m *ItemMutation) RemovedEdges() []string { if m.removedchildren != nil { edges = append(edges, item.EdgeChildren) } - if m.removedlabel != nil { - edges = append(edges, item.EdgeLabel) + if m.removedtag != nil { + edges = append(edges, item.EdgeTag) } if m.removedfields != nil { edges = append(edges, item.EdgeFields) @@ -6015,9 +6015,9 @@ func (m *ItemMutation) RemovedIDs(name string) []ent.Value { ids = append(ids, id) } return ids - case item.EdgeLabel: - ids := make([]ent.Value, 0, len(m.removedlabel)) - for id := range m.removedlabel { + case item.EdgeTag: + ids := make([]ent.Value, 0, len(m.removedtag)) + for id := range m.removedtag { ids = append(ids, id) } return ids @@ -6055,8 +6055,8 @@ func (m *ItemMutation) ClearedEdges() []string { if m.clearedchildren { edges = append(edges, item.EdgeChildren) } - if m.clearedlabel { - edges = append(edges, item.EdgeLabel) + if m.clearedtag { + edges = append(edges, item.EdgeTag) } if m.clearedlocation { edges = append(edges, item.EdgeLocation) @@ -6083,8 +6083,8 @@ func (m *ItemMutation) EdgeCleared(name string) bool { return m.clearedparent case item.EdgeChildren: return m.clearedchildren - case item.EdgeLabel: - return m.clearedlabel + case item.EdgeTag: + return m.clearedtag case item.EdgeLocation: return m.clearedlocation case item.EdgeFields: @@ -6127,8 +6127,8 @@ func (m *ItemMutation) ResetEdge(name string) error { case item.EdgeChildren: m.ResetChildren() return nil - case item.EdgeLabel: - m.ResetLabel() + case item.EdgeTag: + m.ResetTag() return nil case item.EdgeLocation: m.ResetLocation() @@ -7097,8 +7097,8 @@ type ItemTemplateMutation struct { include_warranty_fields *bool include_purchase_fields *bool include_sold_fields *bool - default_label_ids *[]uuid.UUID - appenddefault_label_ids []uuid.UUID + default_tag_ids *[]uuid.UUID + appenddefault_tag_ids []uuid.UUID clearedFields map[string]struct{} group *uuid.UUID clearedgroup bool @@ -7903,69 +7903,69 @@ func (m *ItemTemplateMutation) ResetIncludeSoldFields() { m.include_sold_fields = nil } -// SetDefaultLabelIds sets the "default_label_ids" field. -func (m *ItemTemplateMutation) SetDefaultLabelIds(u []uuid.UUID) { - m.default_label_ids = &u - m.appenddefault_label_ids = nil +// SetDefaultTagIds sets the "default_tag_ids" field. +func (m *ItemTemplateMutation) SetDefaultTagIds(u []uuid.UUID) { + m.default_tag_ids = &u + m.appenddefault_tag_ids = nil } -// DefaultLabelIds returns the value of the "default_label_ids" field in the mutation. -func (m *ItemTemplateMutation) DefaultLabelIds() (r []uuid.UUID, exists bool) { - v := m.default_label_ids +// DefaultTagIds returns the value of the "default_tag_ids" field in the mutation. +func (m *ItemTemplateMutation) DefaultTagIds() (r []uuid.UUID, exists bool) { + v := m.default_tag_ids if v == nil { return } return *v, true } -// OldDefaultLabelIds returns the old "default_label_ids" field's value of the ItemTemplate entity. +// OldDefaultTagIds returns the old "default_tag_ids" field's value of the ItemTemplate entity. // If the ItemTemplate object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *ItemTemplateMutation) OldDefaultLabelIds(ctx context.Context) (v []uuid.UUID, err error) { +func (m *ItemTemplateMutation) OldDefaultTagIds(ctx context.Context) (v []uuid.UUID, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDefaultLabelIds is only allowed on UpdateOne operations") + return v, errors.New("OldDefaultTagIds is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDefaultLabelIds requires an ID field in the mutation") + return v, errors.New("OldDefaultTagIds requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { - return v, fmt.Errorf("querying old value for OldDefaultLabelIds: %w", err) + return v, fmt.Errorf("querying old value for OldDefaultTagIds: %w", err) } - return oldValue.DefaultLabelIds, nil + return oldValue.DefaultTagIds, nil } -// AppendDefaultLabelIds adds u to the "default_label_ids" field. -func (m *ItemTemplateMutation) AppendDefaultLabelIds(u []uuid.UUID) { - m.appenddefault_label_ids = append(m.appenddefault_label_ids, u...) +// AppendDefaultTagIds adds u to the "default_tag_ids" field. +func (m *ItemTemplateMutation) AppendDefaultTagIds(u []uuid.UUID) { + m.appenddefault_tag_ids = append(m.appenddefault_tag_ids, u...) } -// AppendedDefaultLabelIds returns the list of values that were appended to the "default_label_ids" field in this mutation. -func (m *ItemTemplateMutation) AppendedDefaultLabelIds() ([]uuid.UUID, bool) { - if len(m.appenddefault_label_ids) == 0 { +// AppendedDefaultTagIds returns the list of values that were appended to the "default_tag_ids" field in this mutation. +func (m *ItemTemplateMutation) AppendedDefaultTagIds() ([]uuid.UUID, bool) { + if len(m.appenddefault_tag_ids) == 0 { return nil, false } - return m.appenddefault_label_ids, true + return m.appenddefault_tag_ids, true } -// ClearDefaultLabelIds clears the value of the "default_label_ids" field. -func (m *ItemTemplateMutation) ClearDefaultLabelIds() { - m.default_label_ids = nil - m.appenddefault_label_ids = nil - m.clearedFields[itemtemplate.FieldDefaultLabelIds] = struct{}{} +// ClearDefaultTagIds clears the value of the "default_tag_ids" field. +func (m *ItemTemplateMutation) ClearDefaultTagIds() { + m.default_tag_ids = nil + m.appenddefault_tag_ids = nil + m.clearedFields[itemtemplate.FieldDefaultTagIds] = struct{}{} } -// DefaultLabelIdsCleared returns if the "default_label_ids" field was cleared in this mutation. -func (m *ItemTemplateMutation) DefaultLabelIdsCleared() bool { - _, ok := m.clearedFields[itemtemplate.FieldDefaultLabelIds] +// DefaultTagIdsCleared returns if the "default_tag_ids" field was cleared in this mutation. +func (m *ItemTemplateMutation) DefaultTagIdsCleared() bool { + _, ok := m.clearedFields[itemtemplate.FieldDefaultTagIds] return ok } -// ResetDefaultLabelIds resets all changes to the "default_label_ids" field. -func (m *ItemTemplateMutation) ResetDefaultLabelIds() { - m.default_label_ids = nil - m.appenddefault_label_ids = nil - delete(m.clearedFields, itemtemplate.FieldDefaultLabelIds) +// ResetDefaultTagIds resets all changes to the "default_tag_ids" field. +func (m *ItemTemplateMutation) ResetDefaultTagIds() { + m.default_tag_ids = nil + m.appenddefault_tag_ids = nil + delete(m.clearedFields, itemtemplate.FieldDefaultTagIds) } // SetGroupID sets the "group" edge to the Group entity by id. @@ -8183,8 +8183,8 @@ func (m *ItemTemplateMutation) Fields() []string { if m.include_sold_fields != nil { fields = append(fields, itemtemplate.FieldIncludeSoldFields) } - if m.default_label_ids != nil { - fields = append(fields, itemtemplate.FieldDefaultLabelIds) + if m.default_tag_ids != nil { + fields = append(fields, itemtemplate.FieldDefaultTagIds) } return fields } @@ -8226,8 +8226,8 @@ func (m *ItemTemplateMutation) Field(name string) (ent.Value, bool) { return m.IncludePurchaseFields() case itemtemplate.FieldIncludeSoldFields: return m.IncludeSoldFields() - case itemtemplate.FieldDefaultLabelIds: - return m.DefaultLabelIds() + case itemtemplate.FieldDefaultTagIds: + return m.DefaultTagIds() } return nil, false } @@ -8269,8 +8269,8 @@ func (m *ItemTemplateMutation) OldField(ctx context.Context, name string) (ent.V return m.OldIncludePurchaseFields(ctx) case itemtemplate.FieldIncludeSoldFields: return m.OldIncludeSoldFields(ctx) - case itemtemplate.FieldDefaultLabelIds: - return m.OldDefaultLabelIds(ctx) + case itemtemplate.FieldDefaultTagIds: + return m.OldDefaultTagIds(ctx) } return nil, fmt.Errorf("unknown ItemTemplate field %s", name) } @@ -8392,12 +8392,12 @@ func (m *ItemTemplateMutation) SetField(name string, value ent.Value) error { } m.SetIncludeSoldFields(v) return nil - case itemtemplate.FieldDefaultLabelIds: + case itemtemplate.FieldDefaultTagIds: v, ok := value.([]uuid.UUID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetDefaultLabelIds(v) + m.SetDefaultTagIds(v) return nil } return fmt.Errorf("unknown ItemTemplate field %s", name) @@ -8465,8 +8465,8 @@ func (m *ItemTemplateMutation) ClearedFields() []string { if m.FieldCleared(itemtemplate.FieldDefaultWarrantyDetails) { fields = append(fields, itemtemplate.FieldDefaultWarrantyDetails) } - if m.FieldCleared(itemtemplate.FieldDefaultLabelIds) { - fields = append(fields, itemtemplate.FieldDefaultLabelIds) + if m.FieldCleared(itemtemplate.FieldDefaultTagIds) { + fields = append(fields, itemtemplate.FieldDefaultTagIds) } return fields } @@ -8503,8 +8503,8 @@ func (m *ItemTemplateMutation) ClearField(name string) error { case itemtemplate.FieldDefaultWarrantyDetails: m.ClearDefaultWarrantyDetails() return nil - case itemtemplate.FieldDefaultLabelIds: - m.ClearDefaultLabelIds() + case itemtemplate.FieldDefaultTagIds: + m.ClearDefaultTagIds() return nil } return fmt.Errorf("unknown ItemTemplate nullable field %s", name) @@ -8562,8 +8562,8 @@ func (m *ItemTemplateMutation) ResetField(name string) error { case itemtemplate.FieldIncludeSoldFields: m.ResetIncludeSoldFields() return nil - case itemtemplate.FieldDefaultLabelIds: - m.ResetDefaultLabelIds() + case itemtemplate.FieldDefaultTagIds: + m.ResetDefaultTagIds() return nil } return fmt.Errorf("unknown ItemTemplate field %s", name) @@ -8689,747 +8689,6 @@ func (m *ItemTemplateMutation) ResetEdge(name string) error { return fmt.Errorf("unknown ItemTemplate edge %s", name) } -// LabelMutation represents an operation that mutates the Label nodes in the graph. -type LabelMutation struct { - config - op Op - typ string - id *uuid.UUID - created_at *time.Time - updated_at *time.Time - name *string - description *string - color *string - clearedFields map[string]struct{} - group *uuid.UUID - clearedgroup bool - items map[uuid.UUID]struct{} - removeditems map[uuid.UUID]struct{} - cleareditems bool - done bool - oldValue func(context.Context) (*Label, error) - predicates []predicate.Label -} - -var _ ent.Mutation = (*LabelMutation)(nil) - -// labelOption allows management of the mutation configuration using functional options. -type labelOption func(*LabelMutation) - -// newLabelMutation creates new mutation for the Label entity. -func newLabelMutation(c config, op Op, opts ...labelOption) *LabelMutation { - m := &LabelMutation{ - config: c, - op: op, - typ: TypeLabel, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withLabelID sets the ID field of the mutation. -func withLabelID(id uuid.UUID) labelOption { - return func(m *LabelMutation) { - var ( - err error - once sync.Once - value *Label - ) - m.oldValue = func(ctx context.Context) (*Label, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Label.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withLabel sets the old Label of the mutation. -func withLabel(node *Label) labelOption { - return func(m *LabelMutation) { - m.oldValue = func(context.Context) (*Label, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m LabelMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m LabelMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of Label entities. -func (m *LabelMutation) SetID(id uuid.UUID) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *LabelMutation) ID() (id uuid.UUID, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *LabelMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []uuid.UUID{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().Label.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *LabelMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *LabelMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the Label entity. -// If the Label object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *LabelMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *LabelMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *LabelMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *LabelMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the Label entity. -// If the Label object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *LabelMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *LabelMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetName sets the "name" field. -func (m *LabelMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *LabelMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "name" field's value of the Label entity. -// If the Label object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *LabelMutation) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldName is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldName requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *LabelMutation) ResetName() { - m.name = nil -} - -// SetDescription sets the "description" field. -func (m *LabelMutation) SetDescription(s string) { - m.description = &s -} - -// Description returns the value of the "description" field in the mutation. -func (m *LabelMutation) Description() (r string, exists bool) { - v := m.description - if v == nil { - return - } - return *v, true -} - -// OldDescription returns the old "description" field's value of the Label entity. -// If the Label object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *LabelMutation) OldDescription(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldDescription is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldDescription requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldDescription: %w", err) - } - return oldValue.Description, nil -} - -// ClearDescription clears the value of the "description" field. -func (m *LabelMutation) ClearDescription() { - m.description = nil - m.clearedFields[label.FieldDescription] = struct{}{} -} - -// DescriptionCleared returns if the "description" field was cleared in this mutation. -func (m *LabelMutation) DescriptionCleared() bool { - _, ok := m.clearedFields[label.FieldDescription] - return ok -} - -// ResetDescription resets all changes to the "description" field. -func (m *LabelMutation) ResetDescription() { - m.description = nil - delete(m.clearedFields, label.FieldDescription) -} - -// SetColor sets the "color" field. -func (m *LabelMutation) SetColor(s string) { - m.color = &s -} - -// Color returns the value of the "color" field in the mutation. -func (m *LabelMutation) Color() (r string, exists bool) { - v := m.color - if v == nil { - return - } - return *v, true -} - -// OldColor returns the old "color" field's value of the Label entity. -// If the Label object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *LabelMutation) OldColor(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldColor is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldColor requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldColor: %w", err) - } - return oldValue.Color, nil -} - -// ClearColor clears the value of the "color" field. -func (m *LabelMutation) ClearColor() { - m.color = nil - m.clearedFields[label.FieldColor] = struct{}{} -} - -// ColorCleared returns if the "color" field was cleared in this mutation. -func (m *LabelMutation) ColorCleared() bool { - _, ok := m.clearedFields[label.FieldColor] - return ok -} - -// ResetColor resets all changes to the "color" field. -func (m *LabelMutation) ResetColor() { - m.color = nil - delete(m.clearedFields, label.FieldColor) -} - -// SetGroupID sets the "group" edge to the Group entity by id. -func (m *LabelMutation) SetGroupID(id uuid.UUID) { - m.group = &id -} - -// ClearGroup clears the "group" edge to the Group entity. -func (m *LabelMutation) ClearGroup() { - m.clearedgroup = true -} - -// GroupCleared reports if the "group" edge to the Group entity was cleared. -func (m *LabelMutation) GroupCleared() bool { - return m.clearedgroup -} - -// GroupID returns the "group" edge ID in the mutation. -func (m *LabelMutation) GroupID() (id uuid.UUID, exists bool) { - if m.group != nil { - return *m.group, true - } - return -} - -// GroupIDs returns the "group" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// GroupID instead. It exists only for internal usage by the builders. -func (m *LabelMutation) GroupIDs() (ids []uuid.UUID) { - if id := m.group; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetGroup resets all changes to the "group" edge. -func (m *LabelMutation) ResetGroup() { - m.group = nil - m.clearedgroup = false -} - -// AddItemIDs adds the "items" edge to the Item entity by ids. -func (m *LabelMutation) AddItemIDs(ids ...uuid.UUID) { - if m.items == nil { - m.items = make(map[uuid.UUID]struct{}) - } - for i := range ids { - m.items[ids[i]] = struct{}{} - } -} - -// ClearItems clears the "items" edge to the Item entity. -func (m *LabelMutation) ClearItems() { - m.cleareditems = true -} - -// ItemsCleared reports if the "items" edge to the Item entity was cleared. -func (m *LabelMutation) ItemsCleared() bool { - return m.cleareditems -} - -// RemoveItemIDs removes the "items" edge to the Item entity by IDs. -func (m *LabelMutation) RemoveItemIDs(ids ...uuid.UUID) { - if m.removeditems == nil { - m.removeditems = make(map[uuid.UUID]struct{}) - } - for i := range ids { - delete(m.items, ids[i]) - m.removeditems[ids[i]] = struct{}{} - } -} - -// RemovedItems returns the removed IDs of the "items" edge to the Item entity. -func (m *LabelMutation) RemovedItemsIDs() (ids []uuid.UUID) { - for id := range m.removeditems { - ids = append(ids, id) - } - return -} - -// ItemsIDs returns the "items" edge IDs in the mutation. -func (m *LabelMutation) ItemsIDs() (ids []uuid.UUID) { - for id := range m.items { - ids = append(ids, id) - } - return -} - -// ResetItems resets all changes to the "items" edge. -func (m *LabelMutation) ResetItems() { - m.items = nil - m.cleareditems = false - m.removeditems = nil -} - -// Where appends a list predicates to the LabelMutation builder. -func (m *LabelMutation) Where(ps ...predicate.Label) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the LabelMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *LabelMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.Label, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *LabelMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *LabelMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (Label). -func (m *LabelMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *LabelMutation) Fields() []string { - fields := make([]string, 0, 5) - if m.created_at != nil { - fields = append(fields, label.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, label.FieldUpdatedAt) - } - if m.name != nil { - fields = append(fields, label.FieldName) - } - if m.description != nil { - fields = append(fields, label.FieldDescription) - } - if m.color != nil { - fields = append(fields, label.FieldColor) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *LabelMutation) Field(name string) (ent.Value, bool) { - switch name { - case label.FieldCreatedAt: - return m.CreatedAt() - case label.FieldUpdatedAt: - return m.UpdatedAt() - case label.FieldName: - return m.Name() - case label.FieldDescription: - return m.Description() - case label.FieldColor: - return m.Color() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *LabelMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case label.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case label.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case label.FieldName: - return m.OldName(ctx) - case label.FieldDescription: - return m.OldDescription(ctx) - case label.FieldColor: - return m.OldColor(ctx) - } - return nil, fmt.Errorf("unknown Label field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *LabelMutation) SetField(name string, value ent.Value) error { - switch name { - case label.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case label.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - case label.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case label.FieldDescription: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetDescription(v) - return nil - case label.FieldColor: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetColor(v) - return nil - } - return fmt.Errorf("unknown Label field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *LabelMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *LabelMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *LabelMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Label numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *LabelMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(label.FieldDescription) { - fields = append(fields, label.FieldDescription) - } - if m.FieldCleared(label.FieldColor) { - fields = append(fields, label.FieldColor) - } - return fields -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *LabelMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *LabelMutation) ClearField(name string) error { - switch name { - case label.FieldDescription: - m.ClearDescription() - return nil - case label.FieldColor: - m.ClearColor() - return nil - } - return fmt.Errorf("unknown Label nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *LabelMutation) ResetField(name string) error { - switch name { - case label.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case label.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case label.FieldName: - m.ResetName() - return nil - case label.FieldDescription: - m.ResetDescription() - return nil - case label.FieldColor: - m.ResetColor() - return nil - } - return fmt.Errorf("unknown Label field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *LabelMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.group != nil { - edges = append(edges, label.EdgeGroup) - } - if m.items != nil { - edges = append(edges, label.EdgeItems) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *LabelMutation) AddedIDs(name string) []ent.Value { - switch name { - case label.EdgeGroup: - if id := m.group; id != nil { - return []ent.Value{*id} - } - case label.EdgeItems: - ids := make([]ent.Value, 0, len(m.items)) - for id := range m.items { - ids = append(ids, id) - } - return ids - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *LabelMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) - if m.removeditems != nil { - edges = append(edges, label.EdgeItems) - } - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *LabelMutation) RemovedIDs(name string) []ent.Value { - switch name { - case label.EdgeItems: - ids := make([]ent.Value, 0, len(m.removeditems)) - for id := range m.removeditems { - ids = append(ids, id) - } - return ids - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *LabelMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.clearedgroup { - edges = append(edges, label.EdgeGroup) - } - if m.cleareditems { - edges = append(edges, label.EdgeItems) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *LabelMutation) EdgeCleared(name string) bool { - switch name { - case label.EdgeGroup: - return m.clearedgroup - case label.EdgeItems: - return m.cleareditems - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *LabelMutation) ClearEdge(name string) error { - switch name { - case label.EdgeGroup: - m.ClearGroup() - return nil - } - return fmt.Errorf("unknown Label unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *LabelMutation) ResetEdge(name string) error { - switch name { - case label.EdgeGroup: - m.ResetGroup() - return nil - case label.EdgeItems: - m.ResetItems() - return nil - } - return fmt.Errorf("unknown Label edge %s", name) -} - // LocationMutation represents an operation that mutates the Location nodes in the graph. type LocationMutation struct { config @@ -11856,6 +11115,747 @@ func (m *NotifierMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Notifier edge %s", name) } +// TagMutation represents an operation that mutates the Tag nodes in the graph. +type TagMutation struct { + config + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + name *string + description *string + color *string + clearedFields map[string]struct{} + group *uuid.UUID + clearedgroup bool + items map[uuid.UUID]struct{} + removeditems map[uuid.UUID]struct{} + cleareditems bool + done bool + oldValue func(context.Context) (*Tag, error) + predicates []predicate.Tag +} + +var _ ent.Mutation = (*TagMutation)(nil) + +// tagOption allows management of the mutation configuration using functional options. +type tagOption func(*TagMutation) + +// newTagMutation creates new mutation for the Tag entity. +func newTagMutation(c config, op Op, opts ...tagOption) *TagMutation { + m := &TagMutation{ + config: c, + op: op, + typ: TypeTag, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withTagID sets the ID field of the mutation. +func withTagID(id uuid.UUID) tagOption { + return func(m *TagMutation) { + var ( + err error + once sync.Once + value *Tag + ) + m.oldValue = func(ctx context.Context) (*Tag, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Tag.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withTag sets the old Tag of the mutation. +func withTag(node *Tag) tagOption { + return func(m *TagMutation) { + m.oldValue = func(context.Context) (*Tag, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m TagMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m TagMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of Tag entities. +func (m *TagMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *TagMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *TagMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().Tag.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCreatedAt sets the "created_at" field. +func (m *TagMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *TagMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the Tag entity. +// If the Tag object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TagMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *TagMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *TagMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *TagMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the Tag entity. +// If the Tag object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TagMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *TagMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetName sets the "name" field. +func (m *TagMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *TagMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the Tag entity. +// If the Tag object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TagMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *TagMutation) ResetName() { + m.name = nil +} + +// SetDescription sets the "description" field. +func (m *TagMutation) SetDescription(s string) { + m.description = &s +} + +// Description returns the value of the "description" field in the mutation. +func (m *TagMutation) Description() (r string, exists bool) { + v := m.description + if v == nil { + return + } + return *v, true +} + +// OldDescription returns the old "description" field's value of the Tag entity. +// If the Tag object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TagMutation) OldDescription(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDescription is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDescription requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDescription: %w", err) + } + return oldValue.Description, nil +} + +// ClearDescription clears the value of the "description" field. +func (m *TagMutation) ClearDescription() { + m.description = nil + m.clearedFields[tag.FieldDescription] = struct{}{} +} + +// DescriptionCleared returns if the "description" field was cleared in this mutation. +func (m *TagMutation) DescriptionCleared() bool { + _, ok := m.clearedFields[tag.FieldDescription] + return ok +} + +// ResetDescription resets all changes to the "description" field. +func (m *TagMutation) ResetDescription() { + m.description = nil + delete(m.clearedFields, tag.FieldDescription) +} + +// SetColor sets the "color" field. +func (m *TagMutation) SetColor(s string) { + m.color = &s +} + +// Color returns the value of the "color" field in the mutation. +func (m *TagMutation) Color() (r string, exists bool) { + v := m.color + if v == nil { + return + } + return *v, true +} + +// OldColor returns the old "color" field's value of the Tag entity. +// If the Tag object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *TagMutation) OldColor(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldColor is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldColor requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldColor: %w", err) + } + return oldValue.Color, nil +} + +// ClearColor clears the value of the "color" field. +func (m *TagMutation) ClearColor() { + m.color = nil + m.clearedFields[tag.FieldColor] = struct{}{} +} + +// ColorCleared returns if the "color" field was cleared in this mutation. +func (m *TagMutation) ColorCleared() bool { + _, ok := m.clearedFields[tag.FieldColor] + return ok +} + +// ResetColor resets all changes to the "color" field. +func (m *TagMutation) ResetColor() { + m.color = nil + delete(m.clearedFields, tag.FieldColor) +} + +// SetGroupID sets the "group" edge to the Group entity by id. +func (m *TagMutation) SetGroupID(id uuid.UUID) { + m.group = &id +} + +// ClearGroup clears the "group" edge to the Group entity. +func (m *TagMutation) ClearGroup() { + m.clearedgroup = true +} + +// GroupCleared reports if the "group" edge to the Group entity was cleared. +func (m *TagMutation) GroupCleared() bool { + return m.clearedgroup +} + +// GroupID returns the "group" edge ID in the mutation. +func (m *TagMutation) GroupID() (id uuid.UUID, exists bool) { + if m.group != nil { + return *m.group, true + } + return +} + +// GroupIDs returns the "group" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// GroupID instead. It exists only for internal usage by the builders. +func (m *TagMutation) GroupIDs() (ids []uuid.UUID) { + if id := m.group; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetGroup resets all changes to the "group" edge. +func (m *TagMutation) ResetGroup() { + m.group = nil + m.clearedgroup = false +} + +// AddItemIDs adds the "items" edge to the Item entity by ids. +func (m *TagMutation) AddItemIDs(ids ...uuid.UUID) { + if m.items == nil { + m.items = make(map[uuid.UUID]struct{}) + } + for i := range ids { + m.items[ids[i]] = struct{}{} + } +} + +// ClearItems clears the "items" edge to the Item entity. +func (m *TagMutation) ClearItems() { + m.cleareditems = true +} + +// ItemsCleared reports if the "items" edge to the Item entity was cleared. +func (m *TagMutation) ItemsCleared() bool { + return m.cleareditems +} + +// RemoveItemIDs removes the "items" edge to the Item entity by IDs. +func (m *TagMutation) RemoveItemIDs(ids ...uuid.UUID) { + if m.removeditems == nil { + m.removeditems = make(map[uuid.UUID]struct{}) + } + for i := range ids { + delete(m.items, ids[i]) + m.removeditems[ids[i]] = struct{}{} + } +} + +// RemovedItems returns the removed IDs of the "items" edge to the Item entity. +func (m *TagMutation) RemovedItemsIDs() (ids []uuid.UUID) { + for id := range m.removeditems { + ids = append(ids, id) + } + return +} + +// ItemsIDs returns the "items" edge IDs in the mutation. +func (m *TagMutation) ItemsIDs() (ids []uuid.UUID) { + for id := range m.items { + ids = append(ids, id) + } + return +} + +// ResetItems resets all changes to the "items" edge. +func (m *TagMutation) ResetItems() { + m.items = nil + m.cleareditems = false + m.removeditems = nil +} + +// Where appends a list predicates to the TagMutation builder. +func (m *TagMutation) Where(ps ...predicate.Tag) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the TagMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *TagMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Tag, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *TagMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *TagMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Tag). +func (m *TagMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *TagMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.created_at != nil { + fields = append(fields, tag.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, tag.FieldUpdatedAt) + } + if m.name != nil { + fields = append(fields, tag.FieldName) + } + if m.description != nil { + fields = append(fields, tag.FieldDescription) + } + if m.color != nil { + fields = append(fields, tag.FieldColor) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *TagMutation) Field(name string) (ent.Value, bool) { + switch name { + case tag.FieldCreatedAt: + return m.CreatedAt() + case tag.FieldUpdatedAt: + return m.UpdatedAt() + case tag.FieldName: + return m.Name() + case tag.FieldDescription: + return m.Description() + case tag.FieldColor: + return m.Color() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *TagMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case tag.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case tag.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case tag.FieldName: + return m.OldName(ctx) + case tag.FieldDescription: + return m.OldDescription(ctx) + case tag.FieldColor: + return m.OldColor(ctx) + } + return nil, fmt.Errorf("unknown Tag field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TagMutation) SetField(name string, value ent.Value) error { + switch name { + case tag.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case tag.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case tag.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case tag.FieldDescription: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDescription(v) + return nil + case tag.FieldColor: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetColor(v) + return nil + } + return fmt.Errorf("unknown Tag field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *TagMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *TagMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *TagMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown Tag numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *TagMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(tag.FieldDescription) { + fields = append(fields, tag.FieldDescription) + } + if m.FieldCleared(tag.FieldColor) { + fields = append(fields, tag.FieldColor) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *TagMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *TagMutation) ClearField(name string) error { + switch name { + case tag.FieldDescription: + m.ClearDescription() + return nil + case tag.FieldColor: + m.ClearColor() + return nil + } + return fmt.Errorf("unknown Tag nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *TagMutation) ResetField(name string) error { + switch name { + case tag.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case tag.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case tag.FieldName: + m.ResetName() + return nil + case tag.FieldDescription: + m.ResetDescription() + return nil + case tag.FieldColor: + m.ResetColor() + return nil + } + return fmt.Errorf("unknown Tag field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *TagMutation) AddedEdges() []string { + edges := make([]string, 0, 2) + if m.group != nil { + edges = append(edges, tag.EdgeGroup) + } + if m.items != nil { + edges = append(edges, tag.EdgeItems) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *TagMutation) AddedIDs(name string) []ent.Value { + switch name { + case tag.EdgeGroup: + if id := m.group; id != nil { + return []ent.Value{*id} + } + case tag.EdgeItems: + ids := make([]ent.Value, 0, len(m.items)) + for id := range m.items { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *TagMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + if m.removeditems != nil { + edges = append(edges, tag.EdgeItems) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *TagMutation) RemovedIDs(name string) []ent.Value { + switch name { + case tag.EdgeItems: + ids := make([]ent.Value, 0, len(m.removeditems)) + for id := range m.removeditems { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *TagMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedgroup { + edges = append(edges, tag.EdgeGroup) + } + if m.cleareditems { + edges = append(edges, tag.EdgeItems) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *TagMutation) EdgeCleared(name string) bool { + switch name { + case tag.EdgeGroup: + return m.clearedgroup + case tag.EdgeItems: + return m.cleareditems + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *TagMutation) ClearEdge(name string) error { + switch name { + case tag.EdgeGroup: + m.ClearGroup() + return nil + } + return fmt.Errorf("unknown Tag unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *TagMutation) ResetEdge(name string) error { + switch name { + case tag.EdgeGroup: + m.ResetGroup() + return nil + case tag.EdgeItems: + m.ResetItems() + return nil + } + return fmt.Errorf("unknown Tag edge %s", name) +} + // TemplateFieldMutation represents an operation that mutates the TemplateField nodes in the graph. type TemplateFieldMutation struct { config diff --git a/backend/internal/data/ent/predicate/predicate.go b/backend/internal/data/ent/predicate/predicate.go index 0d9d47f5..7f2bfd04 100644 --- a/backend/internal/data/ent/predicate/predicate.go +++ b/backend/internal/data/ent/predicate/predicate.go @@ -30,9 +30,6 @@ type ItemField func(*sql.Selector) // ItemTemplate is the predicate function for itemtemplate builders. type ItemTemplate func(*sql.Selector) -// Label is the predicate function for label builders. -type Label func(*sql.Selector) - // Location is the predicate function for location builders. type Location func(*sql.Selector) @@ -42,6 +39,9 @@ type MaintenanceEntry func(*sql.Selector) // Notifier is the predicate function for notifier builders. type Notifier func(*sql.Selector) +// Tag is the predicate function for tag builders. +type Tag func(*sql.Selector) + // TemplateField is the predicate function for templatefield builders. type TemplateField func(*sql.Selector) diff --git a/backend/internal/data/ent/runtime.go b/backend/internal/data/ent/runtime.go index 0476c5c6..53f76972 100644 --- a/backend/internal/data/ent/runtime.go +++ b/backend/internal/data/ent/runtime.go @@ -13,11 +13,11 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/notifier" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/user" ) @@ -403,53 +403,6 @@ func init() { itemtemplateDescID := itemtemplateMixinFields0[0].Descriptor() // itemtemplate.DefaultID holds the default value on creation for the id field. itemtemplate.DefaultID = itemtemplateDescID.Default.(func() uuid.UUID) - labelMixin := schema.Label{}.Mixin() - labelMixinFields0 := labelMixin[0].Fields() - _ = labelMixinFields0 - labelMixinFields1 := labelMixin[1].Fields() - _ = labelMixinFields1 - labelFields := schema.Label{}.Fields() - _ = labelFields - // labelDescCreatedAt is the schema descriptor for created_at field. - labelDescCreatedAt := labelMixinFields0[1].Descriptor() - // label.DefaultCreatedAt holds the default value on creation for the created_at field. - label.DefaultCreatedAt = labelDescCreatedAt.Default.(func() time.Time) - // labelDescUpdatedAt is the schema descriptor for updated_at field. - labelDescUpdatedAt := labelMixinFields0[2].Descriptor() - // label.DefaultUpdatedAt holds the default value on creation for the updated_at field. - label.DefaultUpdatedAt = labelDescUpdatedAt.Default.(func() time.Time) - // label.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. - label.UpdateDefaultUpdatedAt = labelDescUpdatedAt.UpdateDefault.(func() time.Time) - // labelDescName is the schema descriptor for name field. - labelDescName := labelMixinFields1[0].Descriptor() - // label.NameValidator is a validator for the "name" field. It is called by the builders before save. - label.NameValidator = func() func(string) error { - validators := labelDescName.Validators - fns := [...]func(string) error{ - validators[0].(func(string) error), - validators[1].(func(string) error), - } - return func(name string) error { - for _, fn := range fns { - if err := fn(name); err != nil { - return err - } - } - return nil - } - }() - // labelDescDescription is the schema descriptor for description field. - labelDescDescription := labelMixinFields1[1].Descriptor() - // label.DescriptionValidator is a validator for the "description" field. It is called by the builders before save. - label.DescriptionValidator = labelDescDescription.Validators[0].(func(string) error) - // labelDescColor is the schema descriptor for color field. - labelDescColor := labelFields[0].Descriptor() - // label.ColorValidator is a validator for the "color" field. It is called by the builders before save. - label.ColorValidator = labelDescColor.Validators[0].(func(string) error) - // labelDescID is the schema descriptor for id field. - labelDescID := labelMixinFields0[0].Descriptor() - // label.DefaultID holds the default value on creation for the id field. - label.DefaultID = labelDescID.Default.(func() uuid.UUID) locationMixin := schema.Location{}.Mixin() locationMixinFields0 := locationMixin[0].Fields() _ = locationMixinFields0 @@ -597,6 +550,53 @@ func init() { notifierDescID := notifierMixinFields0[0].Descriptor() // notifier.DefaultID holds the default value on creation for the id field. notifier.DefaultID = notifierDescID.Default.(func() uuid.UUID) + tagMixin := schema.Tag{}.Mixin() + tagMixinFields0 := tagMixin[0].Fields() + _ = tagMixinFields0 + tagMixinFields1 := tagMixin[1].Fields() + _ = tagMixinFields1 + tagFields := schema.Tag{}.Fields() + _ = tagFields + // tagDescCreatedAt is the schema descriptor for created_at field. + tagDescCreatedAt := tagMixinFields0[1].Descriptor() + // tag.DefaultCreatedAt holds the default value on creation for the created_at field. + tag.DefaultCreatedAt = tagDescCreatedAt.Default.(func() time.Time) + // tagDescUpdatedAt is the schema descriptor for updated_at field. + tagDescUpdatedAt := tagMixinFields0[2].Descriptor() + // tag.DefaultUpdatedAt holds the default value on creation for the updated_at field. + tag.DefaultUpdatedAt = tagDescUpdatedAt.Default.(func() time.Time) + // tag.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + tag.UpdateDefaultUpdatedAt = tagDescUpdatedAt.UpdateDefault.(func() time.Time) + // tagDescName is the schema descriptor for name field. + tagDescName := tagMixinFields1[0].Descriptor() + // tag.NameValidator is a validator for the "name" field. It is called by the builders before save. + tag.NameValidator = func() func(string) error { + validators := tagDescName.Validators + fns := [...]func(string) error{ + validators[0].(func(string) error), + validators[1].(func(string) error), + } + return func(name string) error { + for _, fn := range fns { + if err := fn(name); err != nil { + return err + } + } + return nil + } + }() + // tagDescDescription is the schema descriptor for description field. + tagDescDescription := tagMixinFields1[1].Descriptor() + // tag.DescriptionValidator is a validator for the "description" field. It is called by the builders before save. + tag.DescriptionValidator = tagDescDescription.Validators[0].(func(string) error) + // tagDescColor is the schema descriptor for color field. + tagDescColor := tagFields[0].Descriptor() + // tag.ColorValidator is a validator for the "color" field. It is called by the builders before save. + tag.ColorValidator = tagDescColor.Validators[0].(func(string) error) + // tagDescID is the schema descriptor for id field. + tagDescID := tagMixinFields0[0].Descriptor() + // tag.DefaultID holds the default value on creation for the id field. + tag.DefaultID = tagDescID.Default.(func() uuid.UUID) templatefieldMixin := schema.TemplateField{}.Mixin() templatefieldMixinFields0 := templatefieldMixin[0].Fields() _ = templatefieldMixinFields0 diff --git a/backend/internal/data/ent/schema/group.go b/backend/internal/data/ent/schema/group.go index 4deac1ae..974d040d 100644 --- a/backend/internal/data/ent/schema/group.go +++ b/backend/internal/data/ent/schema/group.go @@ -45,7 +45,7 @@ func (Group) Edges() []ent.Edge { owned("users", User.Type), owned("locations", Location.Type), owned("items", Item.Type), - owned("labels", Label.Type), + owned("tags", Tag.Type), owned("invitation_tokens", GroupInvitationToken.Type), owned("notifiers", Notifier.Type), owned("item_templates", ItemTemplate.Type), diff --git a/backend/internal/data/ent/schema/item.go b/backend/internal/data/ent/schema/item.go index b689933e..a2f8f803 100644 --- a/backend/internal/data/ent/schema/item.go +++ b/backend/internal/data/ent/schema/item.go @@ -112,7 +112,7 @@ func (Item) Edges() []ent.Edge { edge.To("children", Item.Type). From("parent"). Unique(), - edge.From("label", Label.Type). + edge.From("tag", Tag.Type). Ref("items"), edge.From("location", Location.Type). Ref("items"). diff --git a/backend/internal/data/ent/schema/item_template.go b/backend/internal/data/ent/schema/item_template.go index bb86170a..e609fb8f 100644 --- a/backend/internal/data/ent/schema/item_template.go +++ b/backend/internal/data/ent/schema/item_template.go @@ -86,10 +86,10 @@ func (ItemTemplate) Fields() []ent.Field { Comment("Whether to include sold fields in items created from this template"), // ------------------------------------ - // Default labels (stored as JSON array of UUIDs to allow reuse across templates) - field.JSON("default_label_ids", []uuid.UUID{}). + // Default tags (stored as JSON array of UUIDs to allow reuse across templates) + field.JSON("default_tag_ids", []uuid.UUID{}). Optional(). - Comment("Default label IDs for items created from this template"), + Comment("Default tag IDs for items created from this template"), } } diff --git a/backend/internal/data/ent/schema/label.go b/backend/internal/data/ent/schema/tag.go similarity index 60% rename from backend/internal/data/ent/schema/label.go rename to backend/internal/data/ent/schema/tag.go index 2ec79164..5853aad0 100644 --- a/backend/internal/data/ent/schema/label.go +++ b/backend/internal/data/ent/schema/tag.go @@ -7,21 +7,21 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema/mixins" ) -// Label holds the schema definition for the Label entity. -type Label struct { +// Tag holds the schema definition for the Tag entity. +type Tag struct { ent.Schema } -func (Label) Mixin() []ent.Mixin { +func (Tag) Mixin() []ent.Mixin { return []ent.Mixin{ mixins.BaseMixin{}, mixins.DetailsMixin{}, - GroupMixin{ref: "labels"}, + GroupMixin{ref: "tags"}, } } -// Fields of the Label. -func (Label) Fields() []ent.Field { +// Fields of the Tag. +func (Tag) Fields() []ent.Field { return []ent.Field{ field.String("color"). MaxLen(255). @@ -29,8 +29,8 @@ func (Label) Fields() []ent.Field { } } -// Edges of the Label. -func (Label) Edges() []ent.Edge { +// Edges of the Tag. +func (Tag) Edges() []ent.Edge { return []ent.Edge{ edge.To("items", Item.Type), } diff --git a/backend/internal/data/ent/label.go b/backend/internal/data/ent/tag.go similarity index 69% rename from backend/internal/data/ent/label.go rename to backend/internal/data/ent/tag.go index 8203bd5d..8be402d1 100644 --- a/backend/internal/data/ent/label.go +++ b/backend/internal/data/ent/tag.go @@ -11,11 +11,11 @@ import ( "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) -// Label is the model entity for the Label schema. -type Label struct { +// Tag is the model entity for the Tag schema. +type Tag struct { config `json:"-"` // ID of the ent. ID uuid.UUID `json:"id,omitempty"` @@ -30,14 +30,14 @@ type Label struct { // Color holds the value of the "color" field. Color string `json:"color,omitempty"` // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the LabelQuery when eager-loading is set. - Edges LabelEdges `json:"edges"` - group_labels *uuid.UUID + // The values are being populated by the TagQuery when eager-loading is set. + Edges TagEdges `json:"edges"` + group_tags *uuid.UUID selectValues sql.SelectValues } -// LabelEdges holds the relations/edges for other nodes in the graph. -type LabelEdges struct { +// TagEdges holds the relations/edges for other nodes in the graph. +type TagEdges struct { // Group holds the value of the group edge. Group *Group `json:"group,omitempty"` // Items holds the value of the items edge. @@ -49,7 +49,7 @@ type LabelEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. -func (e LabelEdges) GroupOrErr() (*Group, error) { +func (e TagEdges) GroupOrErr() (*Group, error) { if e.Group != nil { return e.Group, nil } else if e.loadedTypes[0] { @@ -60,7 +60,7 @@ func (e LabelEdges) GroupOrErr() (*Group, error) { // ItemsOrErr returns the Items value or an error if the edge // was not loaded in eager-loading. -func (e LabelEdges) ItemsOrErr() ([]*Item, error) { +func (e TagEdges) ItemsOrErr() ([]*Item, error) { if e.loadedTypes[1] { return e.Items, nil } @@ -68,17 +68,17 @@ func (e LabelEdges) ItemsOrErr() ([]*Item, error) { } // scanValues returns the types for scanning values from sql.Rows. -func (*Label) scanValues(columns []string) ([]any, error) { +func (*Tag) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case label.FieldName, label.FieldDescription, label.FieldColor: + case tag.FieldName, tag.FieldDescription, tag.FieldColor: values[i] = new(sql.NullString) - case label.FieldCreatedAt, label.FieldUpdatedAt: + case tag.FieldCreatedAt, tag.FieldUpdatedAt: values[i] = new(sql.NullTime) - case label.FieldID: + case tag.FieldID: values[i] = new(uuid.UUID) - case label.ForeignKeys[0]: // group_labels + case tag.ForeignKeys[0]: // group_tags values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: values[i] = new(sql.UnknownType) @@ -88,55 +88,55 @@ func (*Label) scanValues(columns []string) ([]any, error) { } // assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Label fields. -func (_m *Label) assignValues(columns []string, values []any) error { +// to the Tag fields. +func (_m *Tag) assignValues(columns []string, values []any) error { if m, n := len(values), len(columns); m < n { return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) } for i := range columns { switch columns[i] { - case label.FieldID: + case tag.FieldID: if value, ok := values[i].(*uuid.UUID); !ok { return fmt.Errorf("unexpected type %T for field id", values[i]) } else if value != nil { _m.ID = *value } - case label.FieldCreatedAt: + case tag.FieldCreatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field created_at", values[i]) } else if value.Valid { _m.CreatedAt = value.Time } - case label.FieldUpdatedAt: + case tag.FieldUpdatedAt: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field updated_at", values[i]) } else if value.Valid { _m.UpdatedAt = value.Time } - case label.FieldName: + case tag.FieldName: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field name", values[i]) } else if value.Valid { _m.Name = value.String } - case label.FieldDescription: + case tag.FieldDescription: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field description", values[i]) } else if value.Valid { _m.Description = value.String } - case label.FieldColor: + case tag.FieldColor: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field color", values[i]) } else if value.Valid { _m.Color = value.String } - case label.ForeignKeys[0]: + case tag.ForeignKeys[0]: if value, ok := values[i].(*sql.NullScanner); !ok { - return fmt.Errorf("unexpected type %T for field group_labels", values[i]) + return fmt.Errorf("unexpected type %T for field group_tags", values[i]) } else if value.Valid { - _m.group_labels = new(uuid.UUID) - *_m.group_labels = *value.S.(*uuid.UUID) + _m.group_tags = new(uuid.UUID) + *_m.group_tags = *value.S.(*uuid.UUID) } default: _m.selectValues.Set(columns[i], values[i]) @@ -145,44 +145,44 @@ func (_m *Label) assignValues(columns []string, values []any) error { return nil } -// Value returns the ent.Value that was dynamically selected and assigned to the Label. +// Value returns the ent.Value that was dynamically selected and assigned to the Tag. // This includes values selected through modifiers, order, etc. -func (_m *Label) Value(name string) (ent.Value, error) { +func (_m *Tag) Value(name string) (ent.Value, error) { return _m.selectValues.Get(name) } -// QueryGroup queries the "group" edge of the Label entity. -func (_m *Label) QueryGroup() *GroupQuery { - return NewLabelClient(_m.config).QueryGroup(_m) +// QueryGroup queries the "group" edge of the Tag entity. +func (_m *Tag) QueryGroup() *GroupQuery { + return NewTagClient(_m.config).QueryGroup(_m) } -// QueryItems queries the "items" edge of the Label entity. -func (_m *Label) QueryItems() *ItemQuery { - return NewLabelClient(_m.config).QueryItems(_m) +// QueryItems queries the "items" edge of the Tag entity. +func (_m *Tag) QueryItems() *ItemQuery { + return NewTagClient(_m.config).QueryItems(_m) } -// Update returns a builder for updating this Label. -// Note that you need to call Label.Unwrap() before calling this method if this Label +// Update returns a builder for updating this Tag. +// Note that you need to call Tag.Unwrap() before calling this method if this Tag // was returned from a transaction, and the transaction was committed or rolled back. -func (_m *Label) Update() *LabelUpdateOne { - return NewLabelClient(_m.config).UpdateOne(_m) +func (_m *Tag) Update() *TagUpdateOne { + return NewTagClient(_m.config).UpdateOne(_m) } -// Unwrap unwraps the Label entity that was returned from a transaction after it was closed, +// Unwrap unwraps the Tag entity that was returned from a transaction after it was closed, // so that all future queries will be executed through the driver which created the transaction. -func (_m *Label) Unwrap() *Label { +func (_m *Tag) Unwrap() *Tag { _tx, ok := _m.config.driver.(*txDriver) if !ok { - panic("ent: Label is not a transactional entity") + panic("ent: Tag is not a transactional entity") } _m.config.driver = _tx.drv return _m } // String implements the fmt.Stringer. -func (_m *Label) String() string { +func (_m *Tag) String() string { var builder strings.Builder - builder.WriteString("Label(") + builder.WriteString("Tag(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) builder.WriteString("created_at=") builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) @@ -202,5 +202,5 @@ func (_m *Label) String() string { return builder.String() } -// Labels is a parsable slice of Label. -type Labels []*Label +// Tags is a parsable slice of Tag. +type Tags []*Tag diff --git a/backend/internal/data/ent/label/label.go b/backend/internal/data/ent/tag/tag.go similarity index 92% rename from backend/internal/data/ent/label/label.go rename to backend/internal/data/ent/tag/tag.go index df34c877..c6a2a2c6 100644 --- a/backend/internal/data/ent/label/label.go +++ b/backend/internal/data/ent/tag/tag.go @@ -1,6 +1,6 @@ // Code generated by ent, DO NOT EDIT. -package label +package tag import ( "time" @@ -11,8 +11,8 @@ import ( ) const ( - // Label holds the string label denoting the label type in the database. - Label = "label" + // Label holds the string label denoting the tag type in the database. + Label = "tag" // FieldID holds the string denoting the id field in the database. FieldID = "id" // FieldCreatedAt holds the string denoting the created_at field in the database. @@ -29,23 +29,23 @@ const ( EdgeGroup = "group" // EdgeItems holds the string denoting the items edge name in mutations. EdgeItems = "items" - // Table holds the table name of the label in the database. - Table = "labels" + // Table holds the table name of the tag in the database. + Table = "tags" // GroupTable is the table that holds the group relation/edge. - GroupTable = "labels" + GroupTable = "tags" // GroupInverseTable is the table name for the Group entity. // It exists in this package in order to avoid circular dependency with the "group" package. GroupInverseTable = "groups" // GroupColumn is the table column denoting the group relation/edge. - GroupColumn = "group_labels" + GroupColumn = "group_tags" // ItemsTable is the table that holds the items relation/edge. The primary key declared below. - ItemsTable = "label_items" + ItemsTable = "tag_items" // ItemsInverseTable is the table name for the Item entity. // It exists in this package in order to avoid circular dependency with the "item" package. ItemsInverseTable = "items" ) -// Columns holds all SQL columns for label fields. +// Columns holds all SQL columns for tag fields. var Columns = []string{ FieldID, FieldCreatedAt, @@ -55,16 +55,16 @@ var Columns = []string{ FieldColor, } -// ForeignKeys holds the SQL foreign-keys that are owned by the "labels" +// ForeignKeys holds the SQL foreign-keys that are owned by the "tags" // table and are not defined as standalone fields in the schema. var ForeignKeys = []string{ - "group_labels", + "group_tags", } var ( // ItemsPrimaryKey and ItemsColumn2 are the table columns denoting the // primary key for the items relation (M2M). - ItemsPrimaryKey = []string{"label_id", "item_id"} + ItemsPrimaryKey = []string{"tag_id", "item_id"} ) // ValidColumn reports if the column name is valid (part of the table columns). @@ -99,7 +99,7 @@ var ( DefaultID func() uuid.UUID ) -// OrderOption defines the ordering options for the Label queries. +// OrderOption defines the ordering options for the Tag queries. type OrderOption func(*sql.Selector) // ByID orders the results by the id field. diff --git a/backend/internal/data/ent/tag/where.go b/backend/internal/data/ent/tag/where.go new file mode 100644 index 00000000..775a03a8 --- /dev/null +++ b/backend/internal/data/ent/tag/where.go @@ -0,0 +1,438 @@ +// Code generated by ent, DO NOT EDIT. + +package tag + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/google/uuid" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.Tag { + return predicate.Tag(sql.FieldLTE(FieldID, id)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldName, v)) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldDescription, v)) +} + +// Color applies equality check predicate on the "color" field. It's identical to ColorEQ. +func Color(v string) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldColor, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.Tag { + return predicate.Tag(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Tag { + return predicate.Tag(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.Tag { + return predicate.Tag(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.Tag { + return predicate.Tag(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.Tag { + return predicate.Tag(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Tag { + return predicate.Tag(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Tag { + return predicate.Tag(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Tag { + return predicate.Tag(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Tag { + return predicate.Tag(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Tag { + return predicate.Tag(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Tag { + return predicate.Tag(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Tag { + return predicate.Tag(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Tag { + return predicate.Tag(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Tag { + return predicate.Tag(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Tag { + return predicate.Tag(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Tag { + return predicate.Tag(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Tag { + return predicate.Tag(sql.FieldContainsFold(FieldName, v)) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldDescription, v)) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.Tag { + return predicate.Tag(sql.FieldNEQ(FieldDescription, v)) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.Tag { + return predicate.Tag(sql.FieldIn(FieldDescription, vs...)) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.Tag { + return predicate.Tag(sql.FieldNotIn(FieldDescription, vs...)) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.Tag { + return predicate.Tag(sql.FieldGT(FieldDescription, v)) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.Tag { + return predicate.Tag(sql.FieldGTE(FieldDescription, v)) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.Tag { + return predicate.Tag(sql.FieldLT(FieldDescription, v)) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.Tag { + return predicate.Tag(sql.FieldLTE(FieldDescription, v)) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.Tag { + return predicate.Tag(sql.FieldContains(FieldDescription, v)) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.Tag { + return predicate.Tag(sql.FieldHasPrefix(FieldDescription, v)) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.Tag { + return predicate.Tag(sql.FieldHasSuffix(FieldDescription, v)) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.Tag { + return predicate.Tag(sql.FieldIsNull(FieldDescription)) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.Tag { + return predicate.Tag(sql.FieldNotNull(FieldDescription)) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.Tag { + return predicate.Tag(sql.FieldEqualFold(FieldDescription, v)) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.Tag { + return predicate.Tag(sql.FieldContainsFold(FieldDescription, v)) +} + +// ColorEQ applies the EQ predicate on the "color" field. +func ColorEQ(v string) predicate.Tag { + return predicate.Tag(sql.FieldEQ(FieldColor, v)) +} + +// ColorNEQ applies the NEQ predicate on the "color" field. +func ColorNEQ(v string) predicate.Tag { + return predicate.Tag(sql.FieldNEQ(FieldColor, v)) +} + +// ColorIn applies the In predicate on the "color" field. +func ColorIn(vs ...string) predicate.Tag { + return predicate.Tag(sql.FieldIn(FieldColor, vs...)) +} + +// ColorNotIn applies the NotIn predicate on the "color" field. +func ColorNotIn(vs ...string) predicate.Tag { + return predicate.Tag(sql.FieldNotIn(FieldColor, vs...)) +} + +// ColorGT applies the GT predicate on the "color" field. +func ColorGT(v string) predicate.Tag { + return predicate.Tag(sql.FieldGT(FieldColor, v)) +} + +// ColorGTE applies the GTE predicate on the "color" field. +func ColorGTE(v string) predicate.Tag { + return predicate.Tag(sql.FieldGTE(FieldColor, v)) +} + +// ColorLT applies the LT predicate on the "color" field. +func ColorLT(v string) predicate.Tag { + return predicate.Tag(sql.FieldLT(FieldColor, v)) +} + +// ColorLTE applies the LTE predicate on the "color" field. +func ColorLTE(v string) predicate.Tag { + return predicate.Tag(sql.FieldLTE(FieldColor, v)) +} + +// ColorContains applies the Contains predicate on the "color" field. +func ColorContains(v string) predicate.Tag { + return predicate.Tag(sql.FieldContains(FieldColor, v)) +} + +// ColorHasPrefix applies the HasPrefix predicate on the "color" field. +func ColorHasPrefix(v string) predicate.Tag { + return predicate.Tag(sql.FieldHasPrefix(FieldColor, v)) +} + +// ColorHasSuffix applies the HasSuffix predicate on the "color" field. +func ColorHasSuffix(v string) predicate.Tag { + return predicate.Tag(sql.FieldHasSuffix(FieldColor, v)) +} + +// ColorIsNil applies the IsNil predicate on the "color" field. +func ColorIsNil() predicate.Tag { + return predicate.Tag(sql.FieldIsNull(FieldColor)) +} + +// ColorNotNil applies the NotNil predicate on the "color" field. +func ColorNotNil() predicate.Tag { + return predicate.Tag(sql.FieldNotNull(FieldColor)) +} + +// ColorEqualFold applies the EqualFold predicate on the "color" field. +func ColorEqualFold(v string) predicate.Tag { + return predicate.Tag(sql.FieldEqualFold(FieldColor, v)) +} + +// ColorContainsFold applies the ContainsFold predicate on the "color" field. +func ColorContainsFold(v string) predicate.Tag { + return predicate.Tag(sql.FieldContainsFold(FieldColor, v)) +} + +// HasGroup applies the HasEdge predicate on the "group" edge. +func HasGroup() predicate.Tag { + return predicate.Tag(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). +func HasGroupWith(preds ...predicate.Group) predicate.Tag { + return predicate.Tag(func(s *sql.Selector) { + step := newGroupStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasItems applies the HasEdge predicate on the "items" edge. +func HasItems() predicate.Tag { + return predicate.Tag(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, ItemsTable, ItemsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasItemsWith applies the HasEdge predicate on the "items" edge with a given conditions (other predicates). +func HasItemsWith(preds ...predicate.Item) predicate.Tag { + return predicate.Tag(func(s *sql.Selector) { + step := newItemsStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Tag) predicate.Tag { + return predicate.Tag(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Tag) predicate.Tag { + return predicate.Tag(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Tag) predicate.Tag { + return predicate.Tag(sql.NotPredicates(p)) +} diff --git a/backend/internal/data/ent/label_create.go b/backend/internal/data/ent/tag_create.go similarity index 67% rename from backend/internal/data/ent/label_create.go rename to backend/internal/data/ent/tag_create.go index a1cdf28c..bac61933 100644 --- a/backend/internal/data/ent/label_create.go +++ b/backend/internal/data/ent/tag_create.go @@ -13,24 +13,24 @@ import ( "github.com/google/uuid" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) -// LabelCreate is the builder for creating a Label entity. -type LabelCreate struct { +// TagCreate is the builder for creating a Tag entity. +type TagCreate struct { config - mutation *LabelMutation + mutation *TagMutation hooks []Hook } // SetCreatedAt sets the "created_at" field. -func (_c *LabelCreate) SetCreatedAt(v time.Time) *LabelCreate { +func (_c *TagCreate) SetCreatedAt(v time.Time) *TagCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *LabelCreate) SetNillableCreatedAt(v *time.Time) *LabelCreate { +func (_c *TagCreate) SetNillableCreatedAt(v *time.Time) *TagCreate { if v != nil { _c.SetCreatedAt(*v) } @@ -38,13 +38,13 @@ func (_c *LabelCreate) SetNillableCreatedAt(v *time.Time) *LabelCreate { } // SetUpdatedAt sets the "updated_at" field. -func (_c *LabelCreate) SetUpdatedAt(v time.Time) *LabelCreate { +func (_c *TagCreate) SetUpdatedAt(v time.Time) *TagCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *LabelCreate) SetNillableUpdatedAt(v *time.Time) *LabelCreate { +func (_c *TagCreate) SetNillableUpdatedAt(v *time.Time) *TagCreate { if v != nil { _c.SetUpdatedAt(*v) } @@ -52,19 +52,19 @@ func (_c *LabelCreate) SetNillableUpdatedAt(v *time.Time) *LabelCreate { } // SetName sets the "name" field. -func (_c *LabelCreate) SetName(v string) *LabelCreate { +func (_c *TagCreate) SetName(v string) *TagCreate { _c.mutation.SetName(v) return _c } // SetDescription sets the "description" field. -func (_c *LabelCreate) SetDescription(v string) *LabelCreate { +func (_c *TagCreate) SetDescription(v string) *TagCreate { _c.mutation.SetDescription(v) return _c } // SetNillableDescription sets the "description" field if the given value is not nil. -func (_c *LabelCreate) SetNillableDescription(v *string) *LabelCreate { +func (_c *TagCreate) SetNillableDescription(v *string) *TagCreate { if v != nil { _c.SetDescription(*v) } @@ -72,13 +72,13 @@ func (_c *LabelCreate) SetNillableDescription(v *string) *LabelCreate { } // SetColor sets the "color" field. -func (_c *LabelCreate) SetColor(v string) *LabelCreate { +func (_c *TagCreate) SetColor(v string) *TagCreate { _c.mutation.SetColor(v) return _c } // SetNillableColor sets the "color" field if the given value is not nil. -func (_c *LabelCreate) SetNillableColor(v *string) *LabelCreate { +func (_c *TagCreate) SetNillableColor(v *string) *TagCreate { if v != nil { _c.SetColor(*v) } @@ -86,13 +86,13 @@ func (_c *LabelCreate) SetNillableColor(v *string) *LabelCreate { } // SetID sets the "id" field. -func (_c *LabelCreate) SetID(v uuid.UUID) *LabelCreate { +func (_c *TagCreate) SetID(v uuid.UUID) *TagCreate { _c.mutation.SetID(v) return _c } // SetNillableID sets the "id" field if the given value is not nil. -func (_c *LabelCreate) SetNillableID(v *uuid.UUID) *LabelCreate { +func (_c *TagCreate) SetNillableID(v *uuid.UUID) *TagCreate { if v != nil { _c.SetID(*v) } @@ -100,24 +100,24 @@ func (_c *LabelCreate) SetNillableID(v *uuid.UUID) *LabelCreate { } // SetGroupID sets the "group" edge to the Group entity by ID. -func (_c *LabelCreate) SetGroupID(id uuid.UUID) *LabelCreate { +func (_c *TagCreate) SetGroupID(id uuid.UUID) *TagCreate { _c.mutation.SetGroupID(id) return _c } // SetGroup sets the "group" edge to the Group entity. -func (_c *LabelCreate) SetGroup(v *Group) *LabelCreate { +func (_c *TagCreate) SetGroup(v *Group) *TagCreate { return _c.SetGroupID(v.ID) } // AddItemIDs adds the "items" edge to the Item entity by IDs. -func (_c *LabelCreate) AddItemIDs(ids ...uuid.UUID) *LabelCreate { +func (_c *TagCreate) AddItemIDs(ids ...uuid.UUID) *TagCreate { _c.mutation.AddItemIDs(ids...) return _c } // AddItems adds the "items" edges to the Item entity. -func (_c *LabelCreate) AddItems(v ...*Item) *LabelCreate { +func (_c *TagCreate) AddItems(v ...*Item) *TagCreate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID @@ -125,19 +125,19 @@ func (_c *LabelCreate) AddItems(v ...*Item) *LabelCreate { return _c.AddItemIDs(ids...) } -// Mutation returns the LabelMutation object of the builder. -func (_c *LabelCreate) Mutation() *LabelMutation { +// Mutation returns the TagMutation object of the builder. +func (_c *TagCreate) Mutation() *TagMutation { return _c.mutation } -// Save creates the Label in the database. -func (_c *LabelCreate) Save(ctx context.Context) (*Label, error) { +// Save creates the Tag in the database. +func (_c *TagCreate) Save(ctx context.Context) (*Tag, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. -func (_c *LabelCreate) SaveX(ctx context.Context) *Label { +func (_c *TagCreate) SaveX(ctx context.Context) *Tag { v, err := _c.Save(ctx) if err != nil { panic(err) @@ -146,67 +146,67 @@ func (_c *LabelCreate) SaveX(ctx context.Context) *Label { } // Exec executes the query. -func (_c *LabelCreate) Exec(ctx context.Context) error { +func (_c *TagCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (_c *LabelCreate) ExecX(ctx context.Context) { +func (_c *TagCreate) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. -func (_c *LabelCreate) defaults() { +func (_c *TagCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { - v := label.DefaultCreatedAt() + v := tag.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { - v := label.DefaultUpdatedAt() + v := tag.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } if _, ok := _c.mutation.ID(); !ok { - v := label.DefaultID() + v := tag.DefaultID() _c.mutation.SetID(v) } } // check runs all checks and user-defined validators on the builder. -func (_c *LabelCreate) check() error { +func (_c *TagCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Label.created_at"`)} + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Tag.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Label.updated_at"`)} + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Tag.updated_at"`)} } if _, ok := _c.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Label.name"`)} + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Tag.name"`)} } if v, ok := _c.mutation.Name(); ok { - if err := label.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Label.name": %w`, err)} + if err := tag.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Tag.name": %w`, err)} } } if v, ok := _c.mutation.Description(); ok { - if err := label.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Label.description": %w`, err)} + if err := tag.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Tag.description": %w`, err)} } } if v, ok := _c.mutation.Color(); ok { - if err := label.ColorValidator(v); err != nil { - return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Label.color": %w`, err)} + if err := tag.ColorValidator(v); err != nil { + return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Tag.color": %w`, err)} } } if len(_c.mutation.GroupIDs()) == 0 { - return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Label.group"`)} + return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Tag.group"`)} } return nil } -func (_c *LabelCreate) sqlSave(ctx context.Context) (*Label, error) { +func (_c *TagCreate) sqlSave(ctx context.Context) (*Tag, error) { if err := _c.check(); err != nil { return nil, err } @@ -229,41 +229,41 @@ func (_c *LabelCreate) sqlSave(ctx context.Context) (*Label, error) { return _node, nil } -func (_c *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) { +func (_c *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { var ( - _node = &Label{config: _c.config} - _spec = sqlgraph.NewCreateSpec(label.Table, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) + _node = &Tag{config: _c.config} + _spec = sqlgraph.NewCreateSpec(tag.Table, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID)) ) if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = &id } if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(label.FieldCreatedAt, field.TypeTime, value) + _spec.SetField(tag.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(label.FieldUpdatedAt, field.TypeTime, value) + _spec.SetField(tag.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := _c.mutation.Name(); ok { - _spec.SetField(label.FieldName, field.TypeString, value) + _spec.SetField(tag.FieldName, field.TypeString, value) _node.Name = value } if value, ok := _c.mutation.Description(); ok { - _spec.SetField(label.FieldDescription, field.TypeString, value) + _spec.SetField(tag.FieldDescription, field.TypeString, value) _node.Description = value } if value, ok := _c.mutation.Color(); ok { - _spec.SetField(label.FieldColor, field.TypeString, value) + _spec.SetField(tag.FieldColor, field.TypeString, value) _node.Color = value } if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: label.GroupTable, - Columns: []string{label.GroupColumn}, + Table: tag.GroupTable, + Columns: []string{tag.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), @@ -272,15 +272,15 @@ func (_c *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) { for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } - _node.group_labels = &nodes[0] + _node.group_tags = &nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.ItemsIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, - Table: label.ItemsTable, - Columns: label.ItemsPrimaryKey, + Table: tag.ItemsTable, + Columns: tag.ItemsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), @@ -294,27 +294,27 @@ func (_c *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) { return _node, _spec } -// LabelCreateBulk is the builder for creating many Label entities in bulk. -type LabelCreateBulk struct { +// TagCreateBulk is the builder for creating many Tag entities in bulk. +type TagCreateBulk struct { config err error - builders []*LabelCreate + builders []*TagCreate } -// Save creates the Label entities in the database. -func (_c *LabelCreateBulk) Save(ctx context.Context) ([]*Label, error) { +// Save creates the Tag entities in the database. +func (_c *TagCreateBulk) Save(ctx context.Context) ([]*Tag, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*Label, len(_c.builders)) + nodes := make([]*Tag, len(_c.builders)) mutators := make([]Mutator, len(_c.builders)) for i := range _c.builders { func(i int, root context.Context) { builder := _c.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*LabelMutation) + mutation, ok := m.(*TagMutation) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } @@ -357,7 +357,7 @@ func (_c *LabelCreateBulk) Save(ctx context.Context) ([]*Label, error) { } // SaveX is like Save, but panics if an error occurs. -func (_c *LabelCreateBulk) SaveX(ctx context.Context) []*Label { +func (_c *TagCreateBulk) SaveX(ctx context.Context) []*Tag { v, err := _c.Save(ctx) if err != nil { panic(err) @@ -366,13 +366,13 @@ func (_c *LabelCreateBulk) SaveX(ctx context.Context) []*Label { } // Exec executes the query. -func (_c *LabelCreateBulk) Exec(ctx context.Context) error { +func (_c *TagCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (_c *LabelCreateBulk) ExecX(ctx context.Context) { +func (_c *TagCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } diff --git a/backend/internal/data/ent/label_delete.go b/backend/internal/data/ent/tag_delete.go similarity index 55% rename from backend/internal/data/ent/label_delete.go rename to backend/internal/data/ent/tag_delete.go index 68cb8fac..4b53b4ed 100644 --- a/backend/internal/data/ent/label_delete.go +++ b/backend/internal/data/ent/tag_delete.go @@ -8,30 +8,30 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) -// LabelDelete is the builder for deleting a Label entity. -type LabelDelete struct { +// TagDelete is the builder for deleting a Tag entity. +type TagDelete struct { config hooks []Hook - mutation *LabelMutation + mutation *TagMutation } -// Where appends a list predicates to the LabelDelete builder. -func (_d *LabelDelete) Where(ps ...predicate.Label) *LabelDelete { +// Where appends a list predicates to the TagDelete builder. +func (_d *TagDelete) Where(ps ...predicate.Tag) *TagDelete { _d.mutation.Where(ps...) return _d } // Exec executes the deletion query and returns how many vertices were deleted. -func (_d *LabelDelete) Exec(ctx context.Context) (int, error) { +func (_d *TagDelete) Exec(ctx context.Context) (int, error) { return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) } // ExecX is like Exec, but panics if an error occurs. -func (_d *LabelDelete) ExecX(ctx context.Context) int { +func (_d *TagDelete) ExecX(ctx context.Context) int { n, err := _d.Exec(ctx) if err != nil { panic(err) @@ -39,8 +39,8 @@ func (_d *LabelDelete) ExecX(ctx context.Context) int { return n } -func (_d *LabelDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(label.Table, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) +func (_d *TagDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(tag.Table, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID)) if ps := _d.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -56,32 +56,32 @@ func (_d *LabelDelete) sqlExec(ctx context.Context) (int, error) { return affected, err } -// LabelDeleteOne is the builder for deleting a single Label entity. -type LabelDeleteOne struct { - _d *LabelDelete +// TagDeleteOne is the builder for deleting a single Tag entity. +type TagDeleteOne struct { + _d *TagDelete } -// Where appends a list predicates to the LabelDelete builder. -func (_d *LabelDeleteOne) Where(ps ...predicate.Label) *LabelDeleteOne { +// Where appends a list predicates to the TagDelete builder. +func (_d *TagDeleteOne) Where(ps ...predicate.Tag) *TagDeleteOne { _d._d.mutation.Where(ps...) return _d } // Exec executes the deletion query. -func (_d *LabelDeleteOne) Exec(ctx context.Context) error { +func (_d *TagDeleteOne) Exec(ctx context.Context) error { n, err := _d._d.Exec(ctx) switch { case err != nil: return err case n == 0: - return &NotFoundError{label.Label} + return &NotFoundError{tag.Label} default: return nil } } // ExecX is like Exec, but panics if an error occurs. -func (_d *LabelDeleteOne) ExecX(ctx context.Context) { +func (_d *TagDeleteOne) ExecX(ctx context.Context) { if err := _d.Exec(ctx); err != nil { panic(err) } diff --git a/backend/internal/data/ent/label_query.go b/backend/internal/data/ent/tag_query.go similarity index 66% rename from backend/internal/data/ent/label_query.go rename to backend/internal/data/ent/tag_query.go index f3661691..efa7ada3 100644 --- a/backend/internal/data/ent/label_query.go +++ b/backend/internal/data/ent/tag_query.go @@ -15,17 +15,17 @@ import ( "github.com/google/uuid" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) -// LabelQuery is the builder for querying Label entities. -type LabelQuery struct { +// TagQuery is the builder for querying Tag entities. +type TagQuery struct { config ctx *QueryContext - order []label.OrderOption + order []tag.OrderOption inters []Interceptor - predicates []predicate.Label + predicates []predicate.Tag withGroup *GroupQuery withItems *ItemQuery withFKs bool @@ -34,39 +34,39 @@ type LabelQuery struct { path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the LabelQuery builder. -func (_q *LabelQuery) Where(ps ...predicate.Label) *LabelQuery { +// Where adds a new predicate for the TagQuery builder. +func (_q *TagQuery) Where(ps ...predicate.Tag) *TagQuery { _q.predicates = append(_q.predicates, ps...) return _q } // Limit the number of records to be returned by this query. -func (_q *LabelQuery) Limit(limit int) *LabelQuery { +func (_q *TagQuery) Limit(limit int) *TagQuery { _q.ctx.Limit = &limit return _q } // Offset to start from. -func (_q *LabelQuery) Offset(offset int) *LabelQuery { +func (_q *TagQuery) Offset(offset int) *TagQuery { _q.ctx.Offset = &offset return _q } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. -func (_q *LabelQuery) Unique(unique bool) *LabelQuery { +func (_q *TagQuery) Unique(unique bool) *TagQuery { _q.ctx.Unique = &unique return _q } // Order specifies how the records should be ordered. -func (_q *LabelQuery) Order(o ...label.OrderOption) *LabelQuery { +func (_q *TagQuery) Order(o ...tag.OrderOption) *TagQuery { _q.order = append(_q.order, o...) return _q } // QueryGroup chains the current query on the "group" edge. -func (_q *LabelQuery) QueryGroup() *GroupQuery { +func (_q *TagQuery) QueryGroup() *GroupQuery { query := (&GroupClient{config: _q.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := _q.prepareQuery(ctx); err != nil { @@ -77,9 +77,9 @@ func (_q *LabelQuery) QueryGroup() *GroupQuery { return nil, err } step := sqlgraph.NewStep( - sqlgraph.From(label.Table, label.FieldID, selector), + sqlgraph.From(tag.Table, tag.FieldID, selector), sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, label.GroupTable, label.GroupColumn), + sqlgraph.Edge(sqlgraph.M2O, true, tag.GroupTable, tag.GroupColumn), ) fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) return fromU, nil @@ -88,7 +88,7 @@ func (_q *LabelQuery) QueryGroup() *GroupQuery { } // QueryItems chains the current query on the "items" edge. -func (_q *LabelQuery) QueryItems() *ItemQuery { +func (_q *TagQuery) QueryItems() *ItemQuery { query := (&ItemClient{config: _q.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := _q.prepareQuery(ctx); err != nil { @@ -99,9 +99,9 @@ func (_q *LabelQuery) QueryItems() *ItemQuery { return nil, err } step := sqlgraph.NewStep( - sqlgraph.From(label.Table, label.FieldID, selector), + sqlgraph.From(tag.Table, tag.FieldID, selector), sqlgraph.To(item.Table, item.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, label.ItemsTable, label.ItemsPrimaryKey...), + sqlgraph.Edge(sqlgraph.M2M, false, tag.ItemsTable, tag.ItemsPrimaryKey...), ) fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) return fromU, nil @@ -109,21 +109,21 @@ func (_q *LabelQuery) QueryItems() *ItemQuery { return query } -// First returns the first Label entity from the query. -// Returns a *NotFoundError when no Label was found. -func (_q *LabelQuery) First(ctx context.Context) (*Label, error) { +// First returns the first Tag entity from the query. +// Returns a *NotFoundError when no Tag was found. +func (_q *TagQuery) First(ctx context.Context) (*Tag, error) { nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } if len(nodes) == 0 { - return nil, &NotFoundError{label.Label} + return nil, &NotFoundError{tag.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. -func (_q *LabelQuery) FirstX(ctx context.Context) *Label { +func (_q *TagQuery) FirstX(ctx context.Context) *Tag { node, err := _q.First(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -131,22 +131,22 @@ func (_q *LabelQuery) FirstX(ctx context.Context) *Label { return node } -// FirstID returns the first Label ID from the query. -// Returns a *NotFoundError when no Label ID was found. -func (_q *LabelQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { +// FirstID returns the first Tag ID from the query. +// Returns a *NotFoundError when no Tag ID was found. +func (_q *TagQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { - err = &NotFoundError{label.Label} + err = &NotFoundError{tag.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. -func (_q *LabelQuery) FirstIDX(ctx context.Context) uuid.UUID { +func (_q *TagQuery) FirstIDX(ctx context.Context) uuid.UUID { id, err := _q.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -154,10 +154,10 @@ func (_q *LabelQuery) FirstIDX(ctx context.Context) uuid.UUID { return id } -// Only returns a single Label entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one Label entity is found. -// Returns a *NotFoundError when no Label entities are found. -func (_q *LabelQuery) Only(ctx context.Context) (*Label, error) { +// Only returns a single Tag entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Tag entity is found. +// Returns a *NotFoundError when no Tag entities are found. +func (_q *TagQuery) Only(ctx context.Context) (*Tag, error) { nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) if err != nil { return nil, err @@ -166,14 +166,14 @@ func (_q *LabelQuery) Only(ctx context.Context) (*Label, error) { case 1: return nodes[0], nil case 0: - return nil, &NotFoundError{label.Label} + return nil, &NotFoundError{tag.Label} default: - return nil, &NotSingularError{label.Label} + return nil, &NotSingularError{tag.Label} } } // OnlyX is like Only, but panics if an error occurs. -func (_q *LabelQuery) OnlyX(ctx context.Context) *Label { +func (_q *TagQuery) OnlyX(ctx context.Context) *Tag { node, err := _q.Only(ctx) if err != nil { panic(err) @@ -181,10 +181,10 @@ func (_q *LabelQuery) OnlyX(ctx context.Context) *Label { return node } -// OnlyID is like Only, but returns the only Label ID in the query. -// Returns a *NotSingularError when more than one Label ID is found. +// OnlyID is like Only, but returns the only Tag ID in the query. +// Returns a *NotSingularError when more than one Tag ID is found. // Returns a *NotFoundError when no entities are found. -func (_q *LabelQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { +func (_q *TagQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { return @@ -193,15 +193,15 @@ func (_q *LabelQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { case 1: id = ids[0] case 0: - err = &NotFoundError{label.Label} + err = &NotFoundError{tag.Label} default: - err = &NotSingularError{label.Label} + err = &NotSingularError{tag.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *LabelQuery) OnlyIDX(ctx context.Context) uuid.UUID { +func (_q *TagQuery) OnlyIDX(ctx context.Context) uuid.UUID { id, err := _q.OnlyID(ctx) if err != nil { panic(err) @@ -209,18 +209,18 @@ func (_q *LabelQuery) OnlyIDX(ctx context.Context) uuid.UUID { return id } -// All executes the query and returns a list of Labels. -func (_q *LabelQuery) All(ctx context.Context) ([]*Label, error) { +// All executes the query and returns a list of Tags. +func (_q *TagQuery) All(ctx context.Context) ([]*Tag, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) if err := _q.prepareQuery(ctx); err != nil { return nil, err } - qr := querierAll[[]*Label, *LabelQuery]() - return withInterceptors[[]*Label](ctx, _q, qr, _q.inters) + qr := querierAll[[]*Tag, *TagQuery]() + return withInterceptors[[]*Tag](ctx, _q, qr, _q.inters) } // AllX is like All, but panics if an error occurs. -func (_q *LabelQuery) AllX(ctx context.Context) []*Label { +func (_q *TagQuery) AllX(ctx context.Context) []*Tag { nodes, err := _q.All(ctx) if err != nil { panic(err) @@ -228,20 +228,20 @@ func (_q *LabelQuery) AllX(ctx context.Context) []*Label { return nodes } -// IDs executes the query and returns a list of Label IDs. -func (_q *LabelQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { +// IDs executes the query and returns a list of Tag IDs. +func (_q *TagQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if _q.ctx.Unique == nil && _q.path != nil { _q.Unique(true) } ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(label.FieldID).Scan(ctx, &ids); err != nil { + if err = _q.Select(tag.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. -func (_q *LabelQuery) IDsX(ctx context.Context) []uuid.UUID { +func (_q *TagQuery) IDsX(ctx context.Context) []uuid.UUID { ids, err := _q.IDs(ctx) if err != nil { panic(err) @@ -250,16 +250,16 @@ func (_q *LabelQuery) IDsX(ctx context.Context) []uuid.UUID { } // Count returns the count of the given query. -func (_q *LabelQuery) Count(ctx context.Context) (int, error) { +func (_q *TagQuery) Count(ctx context.Context) (int, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) if err := _q.prepareQuery(ctx); err != nil { return 0, err } - return withInterceptors[int](ctx, _q, querierCount[*LabelQuery](), _q.inters) + return withInterceptors[int](ctx, _q, querierCount[*TagQuery](), _q.inters) } // CountX is like Count, but panics if an error occurs. -func (_q *LabelQuery) CountX(ctx context.Context) int { +func (_q *TagQuery) CountX(ctx context.Context) int { count, err := _q.Count(ctx) if err != nil { panic(err) @@ -268,7 +268,7 @@ func (_q *LabelQuery) CountX(ctx context.Context) int { } // Exist returns true if the query has elements in the graph. -func (_q *LabelQuery) Exist(ctx context.Context) (bool, error) { +func (_q *TagQuery) Exist(ctx context.Context) (bool, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) switch _, err := _q.FirstID(ctx); { case IsNotFound(err): @@ -281,7 +281,7 @@ func (_q *LabelQuery) Exist(ctx context.Context) (bool, error) { } // ExistX is like Exist, but panics if an error occurs. -func (_q *LabelQuery) ExistX(ctx context.Context) bool { +func (_q *TagQuery) ExistX(ctx context.Context) bool { exist, err := _q.Exist(ctx) if err != nil { panic(err) @@ -289,18 +289,18 @@ func (_q *LabelQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the LabelQuery builder, including all associated steps. It can be +// Clone returns a duplicate of the TagQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. -func (_q *LabelQuery) Clone() *LabelQuery { +func (_q *TagQuery) Clone() *TagQuery { if _q == nil { return nil } - return &LabelQuery{ + return &TagQuery{ config: _q.config, ctx: _q.ctx.Clone(), - order: append([]label.OrderOption{}, _q.order...), + order: append([]tag.OrderOption{}, _q.order...), inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Label{}, _q.predicates...), + predicates: append([]predicate.Tag{}, _q.predicates...), withGroup: _q.withGroup.Clone(), withItems: _q.withItems.Clone(), // clone intermediate query. @@ -311,7 +311,7 @@ func (_q *LabelQuery) Clone() *LabelQuery { // WithGroup tells the query-builder to eager-load the nodes that are connected to // the "group" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *LabelQuery) WithGroup(opts ...func(*GroupQuery)) *LabelQuery { +func (_q *TagQuery) WithGroup(opts ...func(*GroupQuery)) *TagQuery { query := (&GroupClient{config: _q.config}).Query() for _, opt := range opts { opt(query) @@ -322,7 +322,7 @@ func (_q *LabelQuery) WithGroup(opts ...func(*GroupQuery)) *LabelQuery { // WithItems tells the query-builder to eager-load the nodes that are connected to // the "items" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *LabelQuery) WithItems(opts ...func(*ItemQuery)) *LabelQuery { +func (_q *TagQuery) WithItems(opts ...func(*ItemQuery)) *TagQuery { query := (&ItemClient{config: _q.config}).Query() for _, opt := range opts { opt(query) @@ -341,15 +341,15 @@ func (_q *LabelQuery) WithItems(opts ...func(*ItemQuery)) *LabelQuery { // Count int `json:"count,omitempty"` // } // -// client.Label.Query(). -// GroupBy(label.FieldCreatedAt). +// client.Tag.Query(). +// GroupBy(tag.FieldCreatedAt). // Aggregate(ent.Count()). // Scan(ctx, &v) -func (_q *LabelQuery) GroupBy(field string, fields ...string) *LabelGroupBy { +func (_q *TagQuery) GroupBy(field string, fields ...string) *TagGroupBy { _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &LabelGroupBy{build: _q} + grbuild := &TagGroupBy{build: _q} grbuild.flds = &_q.ctx.Fields - grbuild.label = label.Label + grbuild.label = tag.Label grbuild.scan = grbuild.Scan return grbuild } @@ -363,23 +363,23 @@ func (_q *LabelQuery) GroupBy(field string, fields ...string) *LabelGroupBy { // CreatedAt time.Time `json:"created_at,omitempty"` // } // -// client.Label.Query(). -// Select(label.FieldCreatedAt). +// client.Tag.Query(). +// Select(tag.FieldCreatedAt). // Scan(ctx, &v) -func (_q *LabelQuery) Select(fields ...string) *LabelSelect { +func (_q *TagQuery) Select(fields ...string) *TagSelect { _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &LabelSelect{LabelQuery: _q} - sbuild.label = label.Label + sbuild := &TagSelect{TagQuery: _q} + sbuild.label = tag.Label sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan return sbuild } -// Aggregate returns a LabelSelect configured with the given aggregations. -func (_q *LabelQuery) Aggregate(fns ...AggregateFunc) *LabelSelect { +// Aggregate returns a TagSelect configured with the given aggregations. +func (_q *TagQuery) Aggregate(fns ...AggregateFunc) *TagSelect { return _q.Select().Aggregate(fns...) } -func (_q *LabelQuery) prepareQuery(ctx context.Context) error { +func (_q *TagQuery) prepareQuery(ctx context.Context) error { for _, inter := range _q.inters { if inter == nil { return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") @@ -391,7 +391,7 @@ func (_q *LabelQuery) prepareQuery(ctx context.Context) error { } } for _, f := range _q.ctx.Fields { - if !label.ValidColumn(f) { + if !tag.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } @@ -405,9 +405,9 @@ func (_q *LabelQuery) prepareQuery(ctx context.Context) error { return nil } -func (_q *LabelQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Label, error) { +func (_q *TagQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Tag, error) { var ( - nodes = []*Label{} + nodes = []*Tag{} withFKs = _q.withFKs _spec = _q.querySpec() loadedTypes = [2]bool{ @@ -419,13 +419,13 @@ func (_q *LabelQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Label, withFKs = true } if withFKs { - _spec.Node.Columns = append(_spec.Node.Columns, label.ForeignKeys...) + _spec.Node.Columns = append(_spec.Node.Columns, tag.ForeignKeys...) } _spec.ScanValues = func(columns []string) ([]any, error) { - return (*Label).scanValues(nil, columns) + return (*Tag).scanValues(nil, columns) } _spec.Assign = func(columns []string, values []any) error { - node := &Label{config: _q.config} + node := &Tag{config: _q.config} nodes = append(nodes, node) node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) @@ -441,28 +441,28 @@ func (_q *LabelQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Label, } if query := _q.withGroup; query != nil { if err := _q.loadGroup(ctx, query, nodes, nil, - func(n *Label, e *Group) { n.Edges.Group = e }); err != nil { + func(n *Tag, e *Group) { n.Edges.Group = e }); err != nil { return nil, err } } if query := _q.withItems; query != nil { if err := _q.loadItems(ctx, query, nodes, - func(n *Label) { n.Edges.Items = []*Item{} }, - func(n *Label, e *Item) { n.Edges.Items = append(n.Edges.Items, e) }); err != nil { + func(n *Tag) { n.Edges.Items = []*Item{} }, + func(n *Tag, e *Item) { n.Edges.Items = append(n.Edges.Items, e) }); err != nil { return nil, err } } return nodes, nil } -func (_q *LabelQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Label, init func(*Label), assign func(*Label, *Group)) error { +func (_q *TagQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Tag, init func(*Tag), assign func(*Tag, *Group)) error { ids := make([]uuid.UUID, 0, len(nodes)) - nodeids := make(map[uuid.UUID][]*Label) + nodeids := make(map[uuid.UUID][]*Tag) for i := range nodes { - if nodes[i].group_labels == nil { + if nodes[i].group_tags == nil { continue } - fk := *nodes[i].group_labels + fk := *nodes[i].group_tags if _, ok := nodeids[fk]; !ok { ids = append(ids, fk) } @@ -479,7 +479,7 @@ func (_q *LabelQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes [] for _, n := range neighbors { nodes, ok := nodeids[n.ID] if !ok { - return fmt.Errorf(`unexpected foreign-key "group_labels" returned %v`, n.ID) + return fmt.Errorf(`unexpected foreign-key "group_tags" returned %v`, n.ID) } for i := range nodes { assign(nodes[i], n) @@ -487,10 +487,10 @@ func (_q *LabelQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes [] } return nil } -func (_q *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []*Label, init func(*Label), assign func(*Label, *Item)) error { +func (_q *TagQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []*Tag, init func(*Tag), assign func(*Tag, *Item)) error { edgeIDs := make([]driver.Value, len(nodes)) - byID := make(map[uuid.UUID]*Label) - nids := make(map[uuid.UUID]map[*Label]struct{}) + byID := make(map[uuid.UUID]*Tag) + nids := make(map[uuid.UUID]map[*Tag]struct{}) for i, node := range nodes { edgeIDs[i] = node.ID byID[node.ID] = node @@ -499,11 +499,11 @@ func (_q *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []* } } query.Where(func(s *sql.Selector) { - joinT := sql.Table(label.ItemsTable) - s.Join(joinT).On(s.C(item.FieldID), joinT.C(label.ItemsPrimaryKey[1])) - s.Where(sql.InValues(joinT.C(label.ItemsPrimaryKey[0]), edgeIDs...)) + joinT := sql.Table(tag.ItemsTable) + s.Join(joinT).On(s.C(item.FieldID), joinT.C(tag.ItemsPrimaryKey[1])) + s.Where(sql.InValues(joinT.C(tag.ItemsPrimaryKey[0]), edgeIDs...)) columns := s.SelectedColumns() - s.Select(joinT.C(label.ItemsPrimaryKey[0])) + s.Select(joinT.C(tag.ItemsPrimaryKey[0])) s.AppendSelect(columns...) s.SetDistinct(false) }) @@ -525,7 +525,7 @@ func (_q *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []* outValue := *values[0].(*uuid.UUID) inValue := *values[1].(*uuid.UUID) if nids[inValue] == nil { - nids[inValue] = map[*Label]struct{}{byID[outValue]: {}} + nids[inValue] = map[*Tag]struct{}{byID[outValue]: {}} return assign(columns[1:], values[1:]) } nids[inValue][byID[outValue]] = struct{}{} @@ -549,7 +549,7 @@ func (_q *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []* return nil } -func (_q *LabelQuery) sqlCount(ctx context.Context) (int, error) { +func (_q *TagQuery) sqlCount(ctx context.Context) (int, error) { _spec := _q.querySpec() _spec.Node.Columns = _q.ctx.Fields if len(_q.ctx.Fields) > 0 { @@ -558,8 +558,8 @@ func (_q *LabelQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, _q.driver, _spec) } -func (_q *LabelQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) +func (_q *TagQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(tag.Table, tag.Columns, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID)) _spec.From = _q.sql if unique := _q.ctx.Unique; unique != nil { _spec.Unique = *unique @@ -568,9 +568,9 @@ func (_q *LabelQuery) querySpec() *sqlgraph.QuerySpec { } if fields := _q.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, label.FieldID) + _spec.Node.Columns = append(_spec.Node.Columns, tag.FieldID) for i := range fields { - if fields[i] != label.FieldID { + if fields[i] != tag.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } @@ -598,12 +598,12 @@ func (_q *LabelQuery) querySpec() *sqlgraph.QuerySpec { return _spec } -func (_q *LabelQuery) sqlQuery(ctx context.Context) *sql.Selector { +func (_q *TagQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(label.Table) + t1 := builder.Table(tag.Table) columns := _q.ctx.Fields if len(columns) == 0 { - columns = label.Columns + columns = tag.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if _q.sql != nil { @@ -630,28 +630,28 @@ func (_q *LabelQuery) sqlQuery(ctx context.Context) *sql.Selector { return selector } -// LabelGroupBy is the group-by builder for Label entities. -type LabelGroupBy struct { +// TagGroupBy is the group-by builder for Tag entities. +type TagGroupBy struct { selector - build *LabelQuery + build *TagQuery } // Aggregate adds the given aggregation functions to the group-by query. -func (_g *LabelGroupBy) Aggregate(fns ...AggregateFunc) *LabelGroupBy { +func (_g *TagGroupBy) Aggregate(fns ...AggregateFunc) *TagGroupBy { _g.fns = append(_g.fns, fns...) return _g } // Scan applies the selector query and scans the result into the given value. -func (_g *LabelGroupBy) Scan(ctx context.Context, v any) error { +func (_g *TagGroupBy) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) if err := _g.build.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*LabelQuery, *LabelGroupBy](ctx, _g.build, _g, _g.build.inters, v) + return scanWithInterceptors[*TagQuery, *TagGroupBy](ctx, _g.build, _g, _g.build.inters, v) } -func (_g *LabelGroupBy) sqlScan(ctx context.Context, root *LabelQuery, v any) error { +func (_g *TagGroupBy) sqlScan(ctx context.Context, root *TagQuery, v any) error { selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(_g.fns)) for _, fn := range _g.fns { @@ -678,28 +678,28 @@ func (_g *LabelGroupBy) sqlScan(ctx context.Context, root *LabelQuery, v any) er return sql.ScanSlice(rows, v) } -// LabelSelect is the builder for selecting fields of Label entities. -type LabelSelect struct { - *LabelQuery +// TagSelect is the builder for selecting fields of Tag entities. +type TagSelect struct { + *TagQuery selector } // Aggregate adds the given aggregation functions to the selector query. -func (_s *LabelSelect) Aggregate(fns ...AggregateFunc) *LabelSelect { +func (_s *TagSelect) Aggregate(fns ...AggregateFunc) *TagSelect { _s.fns = append(_s.fns, fns...) return _s } // Scan applies the selector query and scans the result into the given value. -func (_s *LabelSelect) Scan(ctx context.Context, v any) error { +func (_s *TagSelect) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) if err := _s.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*LabelQuery, *LabelSelect](ctx, _s.LabelQuery, _s, _s.inters, v) + return scanWithInterceptors[*TagQuery, *TagSelect](ctx, _s.TagQuery, _s, _s.inters, v) } -func (_s *LabelSelect) sqlScan(ctx context.Context, root *LabelQuery, v any) error { +func (_s *TagSelect) sqlScan(ctx context.Context, root *TagQuery, v any) error { selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(_s.fns)) for _, fn := range _s.fns { diff --git a/backend/internal/data/ent/label_update.go b/backend/internal/data/ent/tag_update.go similarity index 65% rename from backend/internal/data/ent/label_update.go rename to backend/internal/data/ent/tag_update.go index b9beb1ae..51879f59 100644 --- a/backend/internal/data/ent/label_update.go +++ b/backend/internal/data/ent/tag_update.go @@ -14,37 +14,37 @@ import ( "github.com/google/uuid" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" ) -// LabelUpdate is the builder for updating Label entities. -type LabelUpdate struct { +// TagUpdate is the builder for updating Tag entities. +type TagUpdate struct { config hooks []Hook - mutation *LabelMutation + mutation *TagMutation } -// Where appends a list predicates to the LabelUpdate builder. -func (_u *LabelUpdate) Where(ps ...predicate.Label) *LabelUpdate { +// Where appends a list predicates to the TagUpdate builder. +func (_u *TagUpdate) Where(ps ...predicate.Tag) *TagUpdate { _u.mutation.Where(ps...) return _u } // SetUpdatedAt sets the "updated_at" field. -func (_u *LabelUpdate) SetUpdatedAt(v time.Time) *LabelUpdate { +func (_u *TagUpdate) SetUpdatedAt(v time.Time) *TagUpdate { _u.mutation.SetUpdatedAt(v) return _u } // SetName sets the "name" field. -func (_u *LabelUpdate) SetName(v string) *LabelUpdate { +func (_u *TagUpdate) SetName(v string) *TagUpdate { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. -func (_u *LabelUpdate) SetNillableName(v *string) *LabelUpdate { +func (_u *TagUpdate) SetNillableName(v *string) *TagUpdate { if v != nil { _u.SetName(*v) } @@ -52,13 +52,13 @@ func (_u *LabelUpdate) SetNillableName(v *string) *LabelUpdate { } // SetDescription sets the "description" field. -func (_u *LabelUpdate) SetDescription(v string) *LabelUpdate { +func (_u *TagUpdate) SetDescription(v string) *TagUpdate { _u.mutation.SetDescription(v) return _u } // SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *LabelUpdate) SetNillableDescription(v *string) *LabelUpdate { +func (_u *TagUpdate) SetNillableDescription(v *string) *TagUpdate { if v != nil { _u.SetDescription(*v) } @@ -66,19 +66,19 @@ func (_u *LabelUpdate) SetNillableDescription(v *string) *LabelUpdate { } // ClearDescription clears the value of the "description" field. -func (_u *LabelUpdate) ClearDescription() *LabelUpdate { +func (_u *TagUpdate) ClearDescription() *TagUpdate { _u.mutation.ClearDescription() return _u } // SetColor sets the "color" field. -func (_u *LabelUpdate) SetColor(v string) *LabelUpdate { +func (_u *TagUpdate) SetColor(v string) *TagUpdate { _u.mutation.SetColor(v) return _u } // SetNillableColor sets the "color" field if the given value is not nil. -func (_u *LabelUpdate) SetNillableColor(v *string) *LabelUpdate { +func (_u *TagUpdate) SetNillableColor(v *string) *TagUpdate { if v != nil { _u.SetColor(*v) } @@ -86,30 +86,30 @@ func (_u *LabelUpdate) SetNillableColor(v *string) *LabelUpdate { } // ClearColor clears the value of the "color" field. -func (_u *LabelUpdate) ClearColor() *LabelUpdate { +func (_u *TagUpdate) ClearColor() *TagUpdate { _u.mutation.ClearColor() return _u } // SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *LabelUpdate) SetGroupID(id uuid.UUID) *LabelUpdate { +func (_u *TagUpdate) SetGroupID(id uuid.UUID) *TagUpdate { _u.mutation.SetGroupID(id) return _u } // SetGroup sets the "group" edge to the Group entity. -func (_u *LabelUpdate) SetGroup(v *Group) *LabelUpdate { +func (_u *TagUpdate) SetGroup(v *Group) *TagUpdate { return _u.SetGroupID(v.ID) } // AddItemIDs adds the "items" edge to the Item entity by IDs. -func (_u *LabelUpdate) AddItemIDs(ids ...uuid.UUID) *LabelUpdate { +func (_u *TagUpdate) AddItemIDs(ids ...uuid.UUID) *TagUpdate { _u.mutation.AddItemIDs(ids...) return _u } // AddItems adds the "items" edges to the Item entity. -func (_u *LabelUpdate) AddItems(v ...*Item) *LabelUpdate { +func (_u *TagUpdate) AddItems(v ...*Item) *TagUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID @@ -117,31 +117,31 @@ func (_u *LabelUpdate) AddItems(v ...*Item) *LabelUpdate { return _u.AddItemIDs(ids...) } -// Mutation returns the LabelMutation object of the builder. -func (_u *LabelUpdate) Mutation() *LabelMutation { +// Mutation returns the TagMutation object of the builder. +func (_u *TagUpdate) Mutation() *TagMutation { return _u.mutation } // ClearGroup clears the "group" edge to the Group entity. -func (_u *LabelUpdate) ClearGroup() *LabelUpdate { +func (_u *TagUpdate) ClearGroup() *TagUpdate { _u.mutation.ClearGroup() return _u } // ClearItems clears all "items" edges to the Item entity. -func (_u *LabelUpdate) ClearItems() *LabelUpdate { +func (_u *TagUpdate) ClearItems() *TagUpdate { _u.mutation.ClearItems() return _u } // RemoveItemIDs removes the "items" edge to Item entities by IDs. -func (_u *LabelUpdate) RemoveItemIDs(ids ...uuid.UUID) *LabelUpdate { +func (_u *TagUpdate) RemoveItemIDs(ids ...uuid.UUID) *TagUpdate { _u.mutation.RemoveItemIDs(ids...) return _u } // RemoveItems removes "items" edges to Item entities. -func (_u *LabelUpdate) RemoveItems(v ...*Item) *LabelUpdate { +func (_u *TagUpdate) RemoveItems(v ...*Item) *TagUpdate { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID @@ -150,13 +150,13 @@ func (_u *LabelUpdate) RemoveItems(v ...*Item) *LabelUpdate { } // Save executes the query and returns the number of nodes affected by the update operation. -func (_u *LabelUpdate) Save(ctx context.Context) (int, error) { +func (_u *TagUpdate) Save(ctx context.Context) (int, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. -func (_u *LabelUpdate) SaveX(ctx context.Context) int { +func (_u *TagUpdate) SaveX(ctx context.Context) int { affected, err := _u.Save(ctx) if err != nil { panic(err) @@ -165,54 +165,54 @@ func (_u *LabelUpdate) SaveX(ctx context.Context) int { } // Exec executes the query. -func (_u *LabelUpdate) Exec(ctx context.Context) error { +func (_u *TagUpdate) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (_u *LabelUpdate) ExecX(ctx context.Context) { +func (_u *TagUpdate) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. -func (_u *LabelUpdate) defaults() { +func (_u *TagUpdate) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { - v := label.UpdateDefaultUpdatedAt() + v := tag.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. -func (_u *LabelUpdate) check() error { +func (_u *TagUpdate) check() error { if v, ok := _u.mutation.Name(); ok { - if err := label.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Label.name": %w`, err)} + if err := tag.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Tag.name": %w`, err)} } } if v, ok := _u.mutation.Description(); ok { - if err := label.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Label.description": %w`, err)} + if err := tag.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Tag.description": %w`, err)} } } if v, ok := _u.mutation.Color(); ok { - if err := label.ColorValidator(v); err != nil { - return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Label.color": %w`, err)} + if err := tag.ColorValidator(v); err != nil { + return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Tag.color": %w`, err)} } } if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "Label.group"`) + return errors.New(`ent: clearing a required unique edge "Tag.group"`) } return nil } -func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { +func (_u *TagUpdate) sqlSave(ctx context.Context) (_node int, err error) { if err := _u.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) + _spec := sqlgraph.NewUpdateSpec(tag.Table, tag.Columns, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID)) if ps := _u.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -221,29 +221,29 @@ func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { } } if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(label.FieldUpdatedAt, field.TypeTime, value) + _spec.SetField(tag.FieldUpdatedAt, field.TypeTime, value) } if value, ok := _u.mutation.Name(); ok { - _spec.SetField(label.FieldName, field.TypeString, value) + _spec.SetField(tag.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Description(); ok { - _spec.SetField(label.FieldDescription, field.TypeString, value) + _spec.SetField(tag.FieldDescription, field.TypeString, value) } if _u.mutation.DescriptionCleared() { - _spec.ClearField(label.FieldDescription, field.TypeString) + _spec.ClearField(tag.FieldDescription, field.TypeString) } if value, ok := _u.mutation.Color(); ok { - _spec.SetField(label.FieldColor, field.TypeString, value) + _spec.SetField(tag.FieldColor, field.TypeString, value) } if _u.mutation.ColorCleared() { - _spec.ClearField(label.FieldColor, field.TypeString) + _spec.ClearField(tag.FieldColor, field.TypeString) } if _u.mutation.GroupCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: label.GroupTable, - Columns: []string{label.GroupColumn}, + Table: tag.GroupTable, + Columns: []string{tag.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), @@ -255,8 +255,8 @@ func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: label.GroupTable, - Columns: []string{label.GroupColumn}, + Table: tag.GroupTable, + Columns: []string{tag.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), @@ -271,8 +271,8 @@ func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, - Table: label.ItemsTable, - Columns: label.ItemsPrimaryKey, + Table: tag.ItemsTable, + Columns: tag.ItemsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), @@ -284,8 +284,8 @@ func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, - Table: label.ItemsTable, - Columns: label.ItemsPrimaryKey, + Table: tag.ItemsTable, + Columns: tag.ItemsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), @@ -300,8 +300,8 @@ func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, - Table: label.ItemsTable, - Columns: label.ItemsPrimaryKey, + Table: tag.ItemsTable, + Columns: tag.ItemsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), @@ -314,7 +314,7 @@ func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { } if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{label.Label} + err = &NotFoundError{tag.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } @@ -324,28 +324,28 @@ func (_u *LabelUpdate) sqlSave(ctx context.Context) (_node int, err error) { return _node, nil } -// LabelUpdateOne is the builder for updating a single Label entity. -type LabelUpdateOne struct { +// TagUpdateOne is the builder for updating a single Tag entity. +type TagUpdateOne struct { config fields []string hooks []Hook - mutation *LabelMutation + mutation *TagMutation } // SetUpdatedAt sets the "updated_at" field. -func (_u *LabelUpdateOne) SetUpdatedAt(v time.Time) *LabelUpdateOne { +func (_u *TagUpdateOne) SetUpdatedAt(v time.Time) *TagUpdateOne { _u.mutation.SetUpdatedAt(v) return _u } // SetName sets the "name" field. -func (_u *LabelUpdateOne) SetName(v string) *LabelUpdateOne { +func (_u *TagUpdateOne) SetName(v string) *TagUpdateOne { _u.mutation.SetName(v) return _u } // SetNillableName sets the "name" field if the given value is not nil. -func (_u *LabelUpdateOne) SetNillableName(v *string) *LabelUpdateOne { +func (_u *TagUpdateOne) SetNillableName(v *string) *TagUpdateOne { if v != nil { _u.SetName(*v) } @@ -353,13 +353,13 @@ func (_u *LabelUpdateOne) SetNillableName(v *string) *LabelUpdateOne { } // SetDescription sets the "description" field. -func (_u *LabelUpdateOne) SetDescription(v string) *LabelUpdateOne { +func (_u *TagUpdateOne) SetDescription(v string) *TagUpdateOne { _u.mutation.SetDescription(v) return _u } // SetNillableDescription sets the "description" field if the given value is not nil. -func (_u *LabelUpdateOne) SetNillableDescription(v *string) *LabelUpdateOne { +func (_u *TagUpdateOne) SetNillableDescription(v *string) *TagUpdateOne { if v != nil { _u.SetDescription(*v) } @@ -367,19 +367,19 @@ func (_u *LabelUpdateOne) SetNillableDescription(v *string) *LabelUpdateOne { } // ClearDescription clears the value of the "description" field. -func (_u *LabelUpdateOne) ClearDescription() *LabelUpdateOne { +func (_u *TagUpdateOne) ClearDescription() *TagUpdateOne { _u.mutation.ClearDescription() return _u } // SetColor sets the "color" field. -func (_u *LabelUpdateOne) SetColor(v string) *LabelUpdateOne { +func (_u *TagUpdateOne) SetColor(v string) *TagUpdateOne { _u.mutation.SetColor(v) return _u } // SetNillableColor sets the "color" field if the given value is not nil. -func (_u *LabelUpdateOne) SetNillableColor(v *string) *LabelUpdateOne { +func (_u *TagUpdateOne) SetNillableColor(v *string) *TagUpdateOne { if v != nil { _u.SetColor(*v) } @@ -387,30 +387,30 @@ func (_u *LabelUpdateOne) SetNillableColor(v *string) *LabelUpdateOne { } // ClearColor clears the value of the "color" field. -func (_u *LabelUpdateOne) ClearColor() *LabelUpdateOne { +func (_u *TagUpdateOne) ClearColor() *TagUpdateOne { _u.mutation.ClearColor() return _u } // SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *LabelUpdateOne) SetGroupID(id uuid.UUID) *LabelUpdateOne { +func (_u *TagUpdateOne) SetGroupID(id uuid.UUID) *TagUpdateOne { _u.mutation.SetGroupID(id) return _u } // SetGroup sets the "group" edge to the Group entity. -func (_u *LabelUpdateOne) SetGroup(v *Group) *LabelUpdateOne { +func (_u *TagUpdateOne) SetGroup(v *Group) *TagUpdateOne { return _u.SetGroupID(v.ID) } // AddItemIDs adds the "items" edge to the Item entity by IDs. -func (_u *LabelUpdateOne) AddItemIDs(ids ...uuid.UUID) *LabelUpdateOne { +func (_u *TagUpdateOne) AddItemIDs(ids ...uuid.UUID) *TagUpdateOne { _u.mutation.AddItemIDs(ids...) return _u } // AddItems adds the "items" edges to the Item entity. -func (_u *LabelUpdateOne) AddItems(v ...*Item) *LabelUpdateOne { +func (_u *TagUpdateOne) AddItems(v ...*Item) *TagUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID @@ -418,31 +418,31 @@ func (_u *LabelUpdateOne) AddItems(v ...*Item) *LabelUpdateOne { return _u.AddItemIDs(ids...) } -// Mutation returns the LabelMutation object of the builder. -func (_u *LabelUpdateOne) Mutation() *LabelMutation { +// Mutation returns the TagMutation object of the builder. +func (_u *TagUpdateOne) Mutation() *TagMutation { return _u.mutation } // ClearGroup clears the "group" edge to the Group entity. -func (_u *LabelUpdateOne) ClearGroup() *LabelUpdateOne { +func (_u *TagUpdateOne) ClearGroup() *TagUpdateOne { _u.mutation.ClearGroup() return _u } // ClearItems clears all "items" edges to the Item entity. -func (_u *LabelUpdateOne) ClearItems() *LabelUpdateOne { +func (_u *TagUpdateOne) ClearItems() *TagUpdateOne { _u.mutation.ClearItems() return _u } // RemoveItemIDs removes the "items" edge to Item entities by IDs. -func (_u *LabelUpdateOne) RemoveItemIDs(ids ...uuid.UUID) *LabelUpdateOne { +func (_u *TagUpdateOne) RemoveItemIDs(ids ...uuid.UUID) *TagUpdateOne { _u.mutation.RemoveItemIDs(ids...) return _u } // RemoveItems removes "items" edges to Item entities. -func (_u *LabelUpdateOne) RemoveItems(v ...*Item) *LabelUpdateOne { +func (_u *TagUpdateOne) RemoveItems(v ...*Item) *TagUpdateOne { ids := make([]uuid.UUID, len(v)) for i := range v { ids[i] = v[i].ID @@ -450,27 +450,27 @@ func (_u *LabelUpdateOne) RemoveItems(v ...*Item) *LabelUpdateOne { return _u.RemoveItemIDs(ids...) } -// Where appends a list predicates to the LabelUpdate builder. -func (_u *LabelUpdateOne) Where(ps ...predicate.Label) *LabelUpdateOne { +// Where appends a list predicates to the TagUpdate builder. +func (_u *TagUpdateOne) Where(ps ...predicate.Tag) *TagUpdateOne { _u.mutation.Where(ps...) return _u } // Select allows selecting one or more fields (columns) of the returned entity. // The default is selecting all fields defined in the entity schema. -func (_u *LabelUpdateOne) Select(field string, fields ...string) *LabelUpdateOne { +func (_u *TagUpdateOne) Select(field string, fields ...string) *TagUpdateOne { _u.fields = append([]string{field}, fields...) return _u } -// Save executes the query and returns the updated Label entity. -func (_u *LabelUpdateOne) Save(ctx context.Context) (*Label, error) { +// Save executes the query and returns the updated Tag entity. +func (_u *TagUpdateOne) Save(ctx context.Context) (*Tag, error) { _u.defaults() return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) } // SaveX is like Save, but panics if an error occurs. -func (_u *LabelUpdateOne) SaveX(ctx context.Context) *Label { +func (_u *TagUpdateOne) SaveX(ctx context.Context) *Tag { node, err := _u.Save(ctx) if err != nil { panic(err) @@ -479,67 +479,67 @@ func (_u *LabelUpdateOne) SaveX(ctx context.Context) *Label { } // Exec executes the query on the entity. -func (_u *LabelUpdateOne) Exec(ctx context.Context) error { +func (_u *TagUpdateOne) Exec(ctx context.Context) error { _, err := _u.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. -func (_u *LabelUpdateOne) ExecX(ctx context.Context) { +func (_u *TagUpdateOne) ExecX(ctx context.Context) { if err := _u.Exec(ctx); err != nil { panic(err) } } // defaults sets the default values of the builder before save. -func (_u *LabelUpdateOne) defaults() { +func (_u *TagUpdateOne) defaults() { if _, ok := _u.mutation.UpdatedAt(); !ok { - v := label.UpdateDefaultUpdatedAt() + v := tag.UpdateDefaultUpdatedAt() _u.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. -func (_u *LabelUpdateOne) check() error { +func (_u *TagUpdateOne) check() error { if v, ok := _u.mutation.Name(); ok { - if err := label.NameValidator(v); err != nil { - return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Label.name": %w`, err)} + if err := tag.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Tag.name": %w`, err)} } } if v, ok := _u.mutation.Description(); ok { - if err := label.DescriptionValidator(v); err != nil { - return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Label.description": %w`, err)} + if err := tag.DescriptionValidator(v); err != nil { + return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Tag.description": %w`, err)} } } if v, ok := _u.mutation.Color(); ok { - if err := label.ColorValidator(v); err != nil { - return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Label.color": %w`, err)} + if err := tag.ColorValidator(v); err != nil { + return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Tag.color": %w`, err)} } } if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "Label.group"`) + return errors.New(`ent: clearing a required unique edge "Tag.group"`) } return nil } -func (_u *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) { +func (_u *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { if err := _u.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(label.Table, label.Columns, sqlgraph.NewFieldSpec(label.FieldID, field.TypeUUID)) + _spec := sqlgraph.NewUpdateSpec(tag.Table, tag.Columns, sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID)) id, ok := _u.mutation.ID() if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Label.id" for update`)} + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Tag.id" for update`)} } _spec.Node.ID.Value = id if fields := _u.fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, label.FieldID) + _spec.Node.Columns = append(_spec.Node.Columns, tag.FieldID) for _, f := range fields { - if !label.ValidColumn(f) { + if !tag.ValidColumn(f) { return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } - if f != label.FieldID { + if f != tag.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, f) } } @@ -552,29 +552,29 @@ func (_u *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) } } if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(label.FieldUpdatedAt, field.TypeTime, value) + _spec.SetField(tag.FieldUpdatedAt, field.TypeTime, value) } if value, ok := _u.mutation.Name(); ok { - _spec.SetField(label.FieldName, field.TypeString, value) + _spec.SetField(tag.FieldName, field.TypeString, value) } if value, ok := _u.mutation.Description(); ok { - _spec.SetField(label.FieldDescription, field.TypeString, value) + _spec.SetField(tag.FieldDescription, field.TypeString, value) } if _u.mutation.DescriptionCleared() { - _spec.ClearField(label.FieldDescription, field.TypeString) + _spec.ClearField(tag.FieldDescription, field.TypeString) } if value, ok := _u.mutation.Color(); ok { - _spec.SetField(label.FieldColor, field.TypeString, value) + _spec.SetField(tag.FieldColor, field.TypeString, value) } if _u.mutation.ColorCleared() { - _spec.ClearField(label.FieldColor, field.TypeString) + _spec.ClearField(tag.FieldColor, field.TypeString) } if _u.mutation.GroupCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: label.GroupTable, - Columns: []string{label.GroupColumn}, + Table: tag.GroupTable, + Columns: []string{tag.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), @@ -586,8 +586,8 @@ func (_u *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: label.GroupTable, - Columns: []string{label.GroupColumn}, + Table: tag.GroupTable, + Columns: []string{tag.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), @@ -602,8 +602,8 @@ func (_u *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, - Table: label.ItemsTable, - Columns: label.ItemsPrimaryKey, + Table: tag.ItemsTable, + Columns: tag.ItemsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), @@ -615,8 +615,8 @@ func (_u *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, - Table: label.ItemsTable, - Columns: label.ItemsPrimaryKey, + Table: tag.ItemsTable, + Columns: tag.ItemsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), @@ -631,8 +631,8 @@ func (_u *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2M, Inverse: false, - Table: label.ItemsTable, - Columns: label.ItemsPrimaryKey, + Table: tag.ItemsTable, + Columns: tag.ItemsPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(item.FieldID, field.TypeUUID), @@ -643,12 +643,12 @@ func (_u *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error) } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - _node = &Label{config: _u.config} + _node = &Tag{config: _u.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{label.Label} + err = &NotFoundError{tag.Label} } else if sqlgraph.IsConstraintError(err) { err = &ConstraintError{msg: err.Error(), wrap: err} } diff --git a/backend/internal/data/ent/tx.go b/backend/internal/data/ent/tx.go index f8561a0b..bc3eac6a 100644 --- a/backend/internal/data/ent/tx.go +++ b/backend/internal/data/ent/tx.go @@ -28,14 +28,14 @@ type Tx struct { ItemField *ItemFieldClient // ItemTemplate is the client for interacting with the ItemTemplate builders. ItemTemplate *ItemTemplateClient - // Label is the client for interacting with the Label builders. - Label *LabelClient // Location is the client for interacting with the Location builders. Location *LocationClient // MaintenanceEntry is the client for interacting with the MaintenanceEntry builders. MaintenanceEntry *MaintenanceEntryClient // Notifier is the client for interacting with the Notifier builders. Notifier *NotifierClient + // Tag is the client for interacting with the Tag builders. + Tag *TagClient // TemplateField is the client for interacting with the TemplateField builders. TemplateField *TemplateFieldClient // User is the client for interacting with the User builders. @@ -179,10 +179,10 @@ func (tx *Tx) init() { tx.Item = NewItemClient(tx.config) tx.ItemField = NewItemFieldClient(tx.config) tx.ItemTemplate = NewItemTemplateClient(tx.config) - tx.Label = NewLabelClient(tx.config) tx.Location = NewLocationClient(tx.config) tx.MaintenanceEntry = NewMaintenanceEntryClient(tx.config) tx.Notifier = NewNotifierClient(tx.config) + tx.Tag = NewTagClient(tx.config) tx.TemplateField = NewTemplateFieldClient(tx.config) tx.User = NewUserClient(tx.config) } diff --git a/backend/internal/data/repo/repo_group.go b/backend/internal/data/repo/repo_group.go index de1f01f4..755755ca 100644 --- a/backend/internal/data/repo/repo_group.go +++ b/backend/internal/data/repo/repo_group.go @@ -11,7 +11,7 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/groupinvitationtoken" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" ) @@ -79,7 +79,7 @@ type ( TotalUsers int `json:"totalUsers"` TotalItems int `json:"totalItems"` TotalLocations int `json:"totalLocations"` - TotalLabels int `json:"totalLabels"` + TotalTags int `json:"totalTags"` TotalItemPrice float64 `json:"totalItemPrice"` TotalWithWarranty int `json:"totalWithWarranty"` } @@ -131,21 +131,21 @@ func (r *GroupRepository) StatsLocationsByPurchasePrice(ctx context.Context, gid return v, err } -func (r *GroupRepository) StatsLabelsByPurchasePrice(ctx context.Context, gid uuid.UUID) ([]TotalsByOrganizer, error) { +func (r *GroupRepository) StatsTagsByPurchasePrice(ctx context.Context, gid uuid.UUID) ([]TotalsByOrganizer, error) { var v []TotalsByOrganizer - err := r.db.Label.Query(). + err := r.db.Tag.Query(). Where( - label.HasGroupWith(group.ID(gid)), + tag.HasGroupWith(group.ID(gid)), ). - GroupBy(label.FieldID, label.FieldName). + GroupBy(tag.FieldID, tag.FieldName). Aggregate(func(sq *sql.Selector) string { itemTable := sql.Table(item.Table) - jt := sql.Table(label.ItemsTable) + jt := sql.Table(tag.ItemsTable) - sq.Join(jt).On(sq.C(label.FieldID), jt.C(label.ItemsPrimaryKey[0])) - sq.Join(itemTable).On(jt.C(label.ItemsPrimaryKey[1]), itemTable.C(item.FieldID)) + sq.Join(jt).On(sq.C(tag.FieldID), jt.C(tag.ItemsPrimaryKey[0])) + sq.Join(itemTable).On(jt.C(tag.ItemsPrimaryKey[1]), itemTable.C(item.FieldID)) return sql.As(sql.Sum(itemTable.C(item.FieldPurchasePrice)), "total") }). @@ -226,7 +226,7 @@ func (r *GroupRepository) StatsGroup(ctx context.Context, gid uuid.UUID) (GroupS (SELECT COUNT(*) FROM users WHERE group_users = $2) AS total_users, (SELECT COUNT(*) FROM items WHERE group_items = $2 AND items.archived = false) AS total_items, (SELECT COUNT(*) FROM locations WHERE group_locations = $2) AS total_locations, - (SELECT COUNT(*) FROM labels WHERE group_labels = $2) AS total_labels, + (SELECT COUNT(*) FROM tags WHERE group_tags = $2) AS total_tags, (SELECT SUM(purchase_price*quantity) FROM items WHERE group_items = $2 AND items.archived = false) AS total_item_price, (SELECT COUNT(*) FROM items @@ -241,7 +241,7 @@ func (r *GroupRepository) StatsGroup(ctx context.Context, gid uuid.UUID) (GroupS var maybeTotalItemPrice *float64 var maybeTotalWithWarranty *int - err := row.Scan(&stats.TotalUsers, &stats.TotalItems, &stats.TotalLocations, &stats.TotalLabels, &maybeTotalItemPrice, &maybeTotalWithWarranty) + err := row.Scan(&stats.TotalUsers, &stats.TotalItems, &stats.TotalLocations, &stats.TotalTags, &maybeTotalItemPrice, &maybeTotalWithWarranty) if err != nil { return GroupStatistics{}, err } diff --git a/backend/internal/data/repo/repo_group_test.go b/backend/internal/data/repo/repo_group_test.go index 91b7844b..a3de7bf9 100644 --- a/backend/internal/data/repo/repo_group_test.go +++ b/backend/internal/data/repo/repo_group_test.go @@ -36,13 +36,13 @@ func Test_Group_Update(t *testing.T) { // TODO: Fix this test at some point, the data itself in production/development is working fine, it only fails on the test /*func Test_Group_GroupStatistics(t *testing.T) { useItems(t, 20) - useLabels(t, 20) + useTags(t, 20) stats, err := tRepos.Groups.StatsGroup(context.Background(), tGroup.ID) require.NoError(t, err) assert.Equal(t, 20, stats.TotalItems) - assert.Equal(t, 20, stats.TotalLabels) + assert.Equal(t, 20, stats.TotalTags) assert.Equal(t, 1, stats.TotalUsers) assert.Equal(t, 1, stats.TotalLocations) }*/ diff --git a/backend/internal/data/repo/repo_item_templates.go b/backend/internal/data/repo/repo_item_templates.go index 6b9eba03..20022eab 100644 --- a/backend/internal/data/repo/repo_item_templates.go +++ b/backend/internal/data/repo/repo_item_templates.go @@ -10,7 +10,7 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemtemplate" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/templatefield" ) @@ -27,7 +27,7 @@ type ( TextValue string `json:"textValue"` } - TemplateLabelSummary struct { + TemplateTagSummary struct { ID uuid.UUID `json:"id"` Name string `json:"name"` } @@ -52,9 +52,9 @@ type ( DefaultLifetimeWarranty bool `json:"defaultLifetimeWarranty"` DefaultWarrantyDetails *string `json:"defaultWarrantyDetails,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"` - // Default location and labels + // Default location and tags DefaultLocationID uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"` - DefaultLabelIDs *[]uuid.UUID `json:"defaultLabelIds,omitempty" extensions:"x-nullable"` + DefaultTagIDs *[]uuid.UUID `json:"defaultTagIds,omitempty" extensions:"x-nullable"` // Metadata flags IncludeWarrantyFields bool `json:"includeWarrantyFields"` @@ -81,9 +81,9 @@ type ( DefaultLifetimeWarranty bool `json:"defaultLifetimeWarranty"` DefaultWarrantyDetails *string `json:"defaultWarrantyDetails,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"` - // Default location and labels + // Default location and tags DefaultLocationID uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"` - DefaultLabelIDs *[]uuid.UUID `json:"defaultLabelIds,omitempty" extensions:"x-nullable"` + DefaultTagIDs *[]uuid.UUID `json:"defaultTagIds,omitempty" extensions:"x-nullable"` // Metadata flags IncludeWarrantyFields bool `json:"includeWarrantyFields"` @@ -120,9 +120,9 @@ type ( DefaultLifetimeWarranty bool `json:"defaultLifetimeWarranty"` DefaultWarrantyDetails string `json:"defaultWarrantyDetails"` - // Default location and labels + // Default location and tags DefaultLocation *TemplateLocationSummary `json:"defaultLocation"` - DefaultLabels []TemplateLabelSummary `json:"defaultLabels"` + DefaultTags []TemplateTagSummary `json:"defaultTags"` // Metadata flags IncludeWarrantyFields bool `json:"includeWarrantyFields"` @@ -177,15 +177,15 @@ func (r *ItemTemplatesRepository) mapTemplateOut(ctx context.Context, template * } } - // Fetch labels from database using stored IDs - labels := make([]TemplateLabelSummary, 0) - if len(template.DefaultLabelIds) > 0 { - labelEntities, err := r.db.Label.Query(). - Where(label.IDIn(template.DefaultLabelIds...)). + // Fetch tags from database using stored IDs + tags := make([]TemplateTagSummary, 0) + if len(template.DefaultTagIds) > 0 { + tagEntities, err := r.db.Tag.Query(). + Where(tag.IDIn(template.DefaultTagIds...)). All(ctx) if err == nil { - for _, l := range labelEntities { - labels = append(labels, TemplateLabelSummary{ + for _, l := range tagEntities { + tags = append(tags, TemplateTagSummary{ ID: l.ID, Name: l.Name, }) @@ -209,7 +209,7 @@ func (r *ItemTemplatesRepository) mapTemplateOut(ctx context.Context, template * DefaultLifetimeWarranty: template.DefaultLifetimeWarranty, DefaultWarrantyDetails: template.DefaultWarrantyDetails, DefaultLocation: location, - DefaultLabels: labels, + DefaultTags: tags, IncludeWarrantyFields: template.IncludeWarrantyFields, IncludePurchaseFields: template.IncludePurchaseFields, IncludeSoldFields: template.IncludeSoldFields, @@ -284,9 +284,9 @@ func (r *ItemTemplatesRepository) Create(ctx context.Context, gid uuid.UUID, dat if data.DefaultLocationID != uuid.Nil { q.SetLocationID(data.DefaultLocationID) } - // Set default label IDs (stored as JSON) - if data.DefaultLabelIDs != nil && len(*data.DefaultLabelIDs) > 0 { - q.SetDefaultLabelIds(*data.DefaultLabelIDs) + // Set default tag IDs (stored as JSON) + if data.DefaultTagIDs != nil && len(*data.DefaultTagIDs) > 0 { + q.SetDefaultTagIds(*data.DefaultTagIDs) } template, err := q.Save(ctx) @@ -351,11 +351,11 @@ func (r *ItemTemplatesRepository) Update(ctx context.Context, gid uuid.UUID, dat updateQ.ClearLocation() } - // Update default label IDs (stored as JSON) - if data.DefaultLabelIDs != nil && len(*data.DefaultLabelIDs) > 0 { - updateQ.SetDefaultLabelIds(*data.DefaultLabelIDs) + // Update default tag IDs (stored as JSON) + if data.DefaultTagIDs != nil && len(*data.DefaultTagIDs) > 0 { + updateQ.SetDefaultTagIds(*data.DefaultTagIDs) } else { - updateQ.ClearDefaultLabelIds() + updateQ.ClearDefaultTagIds() } _, err = updateQ.Save(ctx) diff --git a/backend/internal/data/repo/repo_item_templates_test.go b/backend/internal/data/repo/repo_item_templates_test.go index 4f6e6cfb..bc23896f 100644 --- a/backend/internal/data/repo/repo_item_templates_test.go +++ b/backend/internal/data/repo/repo_item_templates_test.go @@ -263,34 +263,34 @@ func TestItemTemplatesRepository_CreateWithLocation(t *testing.T) { require.NoError(t, err) } -func TestItemTemplatesRepository_CreateWithLabels(t *testing.T) { - // Create some labels - label1, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ +func TestItemTemplatesRepository_CreateWithTags(t *testing.T) { + // Create some tags + tag1, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ Name: fk.Str(10), Description: fk.Str(50), }) require.NoError(t, err) - label2, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ + tag2, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ Name: fk.Str(10), Description: fk.Str(50), }) require.NoError(t, err) t.Cleanup(func() { - _ = tRepos.Labels.delete(context.Background(), label1.ID) - _ = tRepos.Labels.delete(context.Background(), label2.ID) + _ = tRepos.Tags.delete(context.Background(), tag1.ID) + _ = tRepos.Tags.delete(context.Background(), tag2.ID) }) - // Create template with labels + // Create template with tags data := templateFactory() - labelIDs := []uuid.UUID{label1.ID, label2.ID} - data.DefaultLabelIDs = &labelIDs + tagIDs := []uuid.UUID{tag1.ID, tag2.ID} + data.DefaultTagIDs = &tagIDs template, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data) require.NoError(t, err) - assert.Len(t, template.DefaultLabels, 2) + assert.Len(t, template.DefaultTags, 2) // Cleanup err = tRepos.ItemTemplates.Delete(context.Background(), tGroup.ID, template.ID) diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 3d2390fc..0b8924a9 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -13,7 +13,7 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/item" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/itemfield" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/location" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/maintenanceentry" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" @@ -38,8 +38,8 @@ type ( Search string `json:"search"` AssetID AssetID `json:"assetId"` LocationIDs []uuid.UUID `json:"locationIds"` - LabelIDs []uuid.UUID `json:"labelIds"` - NegateLabels bool `json:"negateLabels"` + TagIDs []uuid.UUID `json:"tagIds"` + NegateTags bool `json:"negateTags"` OnlyWithoutPhoto bool `json:"onlyWithoutPhoto"` OnlyWithPhoto bool `json:"onlyWithPhoto"` ParentItemIDs []uuid.UUID `json:"parentIds"` @@ -76,7 +76,7 @@ type ( // Edges LocationID uuid.UUID `json:"locationId"` - LabelIDs []uuid.UUID `json:"labelIds"` + TagIDs []uuid.UUID `json:"tagIds"` } ItemUpdate struct { @@ -92,7 +92,7 @@ type ( // Edges LocationID uuid.UUID `json:"locationId"` - LabelIDs []uuid.UUID `json:"labelIds"` + TagIDs []uuid.UUID `json:"tagIds"` // Identifications SerialNumber string `json:"serialNumber"` @@ -125,7 +125,7 @@ type ( Quantity *int `json:"quantity,omitempty" extensions:"x-nullable,x-omitempty"` ImportRef *string `json:"-,omitempty" extensions:"x-nullable,x-omitempty"` LocationID uuid.UUID `json:"locationId" extensions:"x-nullable,x-omitempty"` - LabelIDs []uuid.UUID `json:"labelIds" extensions:"x-nullable,x-omitempty"` + TagIDs []uuid.UUID `json:"tagIds" extensions:"x-nullable,x-omitempty"` } ItemSummary struct { @@ -144,7 +144,7 @@ type ( // Edges Location *LocationSummary `json:"location,omitempty" extensions:"x-nullable,x-omitempty"` - Labels []LabelSummary `json:"labels"` + Tags []TagSummary `json:"tags"` ImageID *uuid.UUID `json:"imageId,omitempty" extensions:"x-nullable,x-omitempty"` ThumbnailId *uuid.UUID `json:"thumbnailId,omitempty" extensions:"x-nullable,x-omitempty"` @@ -196,9 +196,9 @@ func mapItemSummary(item *ent.Item) ItemSummary { location = &loc } - labels := make([]LabelSummary, len(item.Edges.Label)) - if item.Edges.Label != nil { - labels = mapEach(item.Edges.Label, mapLabelSummary) + tags := make([]TagSummary, len(item.Edges.Tag)) + if item.Edges.Tag != nil { + tags = mapEach(item.Edges.Tag, mapTagSummary) } var imageID *uuid.UUID @@ -235,7 +235,7 @@ func mapItemSummary(item *ent.Item) ItemSummary { // Edges Location: location, - Labels: labels, + Tags: tags, // Warranty Insured: item.Insured, @@ -329,7 +329,7 @@ func (e *ItemsRepository) getOneTx(ctx context.Context, tx *ent.Tx, where ...pre return mapItemOutErr(q. WithFields(). - WithLabel(). + WithTag(). WithLocation(). WithGroup(). WithParent(). @@ -412,24 +412,24 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite // of filters is OR'd together. // // The goal is to allow matches like where the item has - // - one of the selected labels AND + // - one of the selected tags AND // - one of the selected locations AND // - one of the selected fields key/value matches var andPredicates []predicate.Item { - if len(q.LabelIDs) > 0 { - labelPredicates := make([]predicate.Item, 0, len(q.LabelIDs)) - for _, l := range q.LabelIDs { - if !q.NegateLabels { - labelPredicates = append(labelPredicates, item.HasLabelWith(label.ID(l))) + if len(q.TagIDs) > 0 { + tagPredicates := make([]predicate.Item, 0, len(q.TagIDs)) + for _, l := range q.TagIDs { + if !q.NegateTags { + tagPredicates = append(tagPredicates, item.HasTagWith(tag.ID(l))) } else { - labelPredicates = append(labelPredicates, item.Not(item.HasLabelWith(label.ID(l)))) + tagPredicates = append(tagPredicates, item.Not(item.HasTagWith(tag.ID(l)))) } } - if !q.NegateLabels { - andPredicates = append(andPredicates, item.Or(labelPredicates...)) + if !q.NegateTags { + andPredicates = append(andPredicates, item.Or(tagPredicates...)) } else { - andPredicates = append(andPredicates, item.And(labelPredicates...)) + andPredicates = append(andPredicates, item.And(tagPredicates...)) } } @@ -504,7 +504,7 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite } qb = qb. - WithLabel(). + WithTag(). WithLocation(). WithAttachments(func(aq *ent.AttachmentQuery) { aq.Where( @@ -549,7 +549,7 @@ func (e *ItemsRepository) QueryByAssetID(ctx context.Context, gid uuid.UUID, ass items, err := mapItemsSummaryErr( qb.Order(ent.Asc(item.FieldName)). - WithLabel(). + WithTag(). WithLocation(). All(ctx), ) @@ -565,11 +565,11 @@ func (e *ItemsRepository) QueryByAssetID(ctx context.Context, gid uuid.UUID, ass }, nil } -// GetAll returns all the items in the database with the Labels and Locations eager loaded. +// GetAll returns all the items in the database with the Tags and Locations eager loaded. func (e *ItemsRepository) GetAll(ctx context.Context, gid uuid.UUID) ([]ItemOut, error) { return mapItemsOutErr(e.db.Item.Query(). Where(item.HasGroupWith(group.ID(gid))). - WithLabel(). + WithTag(). WithLocation(). WithFields(). All(ctx)) @@ -641,8 +641,8 @@ func (e *ItemsRepository) Create(ctx context.Context, gid uuid.UUID, data ItemCr q.SetParentID(data.ParentID) } - if len(data.LabelIDs) > 0 { - q.AddLabelIDs(data.LabelIDs...) + if len(data.TagIDs) > 0 { + q.AddTagIDs(data.TagIDs...) } result, err := q.Save(ctx) @@ -660,7 +660,7 @@ type ItemCreateFromTemplate struct { Description string Quantity int LocationID uuid.UUID - LabelIDs []uuid.UUID + TagIDs []uuid.UUID Insured bool Manufacturer string ModelNumber string @@ -707,8 +707,8 @@ func (e *ItemsRepository) CreateFromTemplate(ctx context.Context, gid uuid.UUID, SetLifetimeWarranty(data.LifetimeWarranty). SetWarrantyDetails(data.WarrantyDetails) - if len(data.LabelIDs) > 0 { - itemBuilder.AddLabelIDs(data.LabelIDs...) + if len(data.TagIDs) > 0 { + itemBuilder.AddTagIDs(data.TagIDs...) } _, err = itemBuilder.Save(ctx) @@ -809,7 +809,7 @@ func (e *ItemsRepository) DeleteByGroup(ctx context.Context, gid, id uuid.UUID) return err } -func (e *ItemsRepository) WipeInventory(ctx context.Context, gid uuid.UUID, wipeLabels bool, wipeLocations bool, wipeMaintenance bool) (int, error) { +func (e *ItemsRepository) WipeInventory(ctx context.Context, gid uuid.UUID, wipeTags bool, wipeLocations bool, wipeMaintenance bool) (int, error) { deleted := 0 // Wipe maintenance records if requested @@ -865,14 +865,14 @@ func (e *ItemsRepository) WipeInventory(ctx context.Context, gid uuid.UUID, wipe deleted++ } - // Wipe labels if requested - if wipeLabels { - labelCount, err := e.db.Label.Delete().Where(label.HasGroupWith(group.ID(gid))).Exec(ctx) + // Wipe tags if requested + if wipeTags { + tagCount, err := e.db.Tag.Delete().Where(tag.HasGroupWith(group.ID(gid))).Exec(ctx) if err != nil { - log.Err(err).Msg("failed to delete labels during wipe inventory") + log.Err(err).Msg("failed to delete tags during wipe inventory") } else { - log.Info().Int("count", labelCount).Msg("deleted labels during wipe inventory") - deleted += labelCount + log.Info().Int("count", tagCount).Msg("deleted tags during wipe inventory") + deleted += tagCount } } @@ -916,23 +916,23 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, gid uuid.UUID, data SetAssetID(int(data.AssetID)). SetSyncChildItemsLocations(data.SyncChildItemsLocations) - currentLabels, err := e.db.Item.Query().Where(item.ID(data.ID)).QueryLabel().All(ctx) + currentTags, err := e.db.Item.Query().Where(item.ID(data.ID)).QueryTag().All(ctx) if err != nil { return ItemOut{}, err } - set := newIDSet(currentLabels) + set := newIDSet(currentTags) - for _, l := range data.LabelIDs { + for _, l := range data.TagIDs { if set.Contains(l) { set.Remove(l) continue } - q.AddLabelIDs(l) + q.AddTagIDs(l) } if set.Len() > 0 { - q.RemoveLabelIDs(set.Slice()...) + q.RemoveTagIDs(set.Slice()...) } if data.ParentID != uuid.Nil { @@ -1087,26 +1087,26 @@ func (e *ItemsRepository) Patch(ctx context.Context, gid, id uuid.UUID, data Ite return err } - if data.LabelIDs != nil { - currentLabels, err := tx.Item.Query().Where(item.ID(id), item.HasGroupWith(group.ID(gid))).QueryLabel().All(ctx) + if data.TagIDs != nil { + currentTags, err := tx.Item.Query().Where(item.ID(id), item.HasGroupWith(group.ID(gid))).QueryTag().All(ctx) if err != nil { return err } - set := newIDSet(currentLabels) + set := newIDSet(currentTags) - addLabels := []uuid.UUID{} - for _, l := range data.LabelIDs { + addTags := []uuid.UUID{} + for _, l := range data.TagIDs { if set.Contains(l) { set.Remove(l) } else { - addLabels = append(addLabels, l) + addTags = append(addTags, l) } } - if len(addLabels) > 0 { + if len(addTags) > 0 { if err := tx.Item.Update(). Where(item.ID(id), item.HasGroupWith(group.ID(gid))). - AddLabelIDs(addLabels...). + AddTagIDs(addTags...). Exec(ctx); err != nil { return err } @@ -1114,7 +1114,7 @@ func (e *ItemsRepository) Patch(ctx context.Context, gid, id uuid.UUID, data Ite if set.Len() > 0 { if err := tx.Item.Update(). Where(item.ID(id), item.HasGroupWith(group.ID(gid))). - RemoveLabelIDs(set.Slice()...). + RemoveTagIDs(set.Slice()...). Exec(ctx); err != nil { return err } @@ -1402,13 +1402,13 @@ func (e *ItemsRepository) Duplicate(ctx context.Context, gid, id uuid.UUID, opti itemBuilder.SetParentID(originalItem.Parent.ID) } - // Add labels - if len(originalItem.Labels) > 0 { - labelIDs := make([]uuid.UUID, len(originalItem.Labels)) - for i, label := range originalItem.Labels { - labelIDs[i] = label.ID + // Add tags + if len(originalItem.Tags) > 0 { + tagIDs := make([]uuid.UUID, len(originalItem.Tags)) + for i, tag := range originalItem.Tags { + tagIDs[i] = tag.ID } - itemBuilder.AddLabelIDs(labelIDs...) + itemBuilder.AddTagIDs(tagIDs...) } _, err = itemBuilder.Save(ctx) diff --git a/backend/internal/data/repo/repo_items_test.go b/backend/internal/data/repo/repo_items_test.go index 59f45fc2..e0236030 100644 --- a/backend/internal/data/repo/repo_items_test.go +++ b/backend/internal/data/repo/repo_items_test.go @@ -165,14 +165,14 @@ func TestItemsRepository_Delete(t *testing.T) { assert.Empty(t, results) } -func TestItemsRepository_Update_Labels(t *testing.T) { +func TestItemsRepository_Update_Tags(t *testing.T) { entity := useItems(t, 1)[0] - labels := useLabels(t, 3) + tags := useTags(t, 3) - labelsIDs := []uuid.UUID{labels[0].ID, labels[1].ID, labels[2].ID} + tagsIDs := []uuid.UUID{tags[0].ID, tags[1].ID, tags[2].ID} type args struct { - labelIds []uuid.UUID + tagIds []uuid.UUID } tests := []struct { @@ -181,44 +181,44 @@ func TestItemsRepository_Update_Labels(t *testing.T) { want []uuid.UUID }{ { - name: "add all labels", + name: "add all tags", args: args{ - labelIds: labelsIDs, + tagIds: tagsIDs, }, - want: labelsIDs, + want: tagsIDs, }, { - name: "update with one label", + name: "update with one tag", args: args{ - labelIds: labelsIDs[:1], + tagIds: tagsIDs[:1], }, - want: labelsIDs[:1], + want: tagsIDs[:1], }, { - name: "add one new label to existing single label", + name: "add one new tag to existing single tag", args: args{ - labelIds: labelsIDs[1:], + tagIds: tagsIDs[1:], }, - want: labelsIDs[1:], + want: tagsIDs[1:], }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // Apply all labels to entity + // Apply all tags to entity updateData := ItemUpdate{ ID: entity.ID, Name: entity.Name, LocationID: entity.Location.ID, - LabelIDs: tt.args.labelIds, + TagIDs: tt.args.tagIds, } updated, err := tRepos.Items.UpdateByGroup(context.Background(), tGroup.ID, updateData) require.NoError(t, err) - assert.Len(t, tt.want, len(updated.Labels)) + assert.Len(t, tt.want, len(updated.Tags)) - for _, label := range updated.Labels { - assert.Contains(t, tt.want, label.ID) + for _, tag := range updated.Tags { + assert.Contains(t, tt.want, tag.ID) } }) } @@ -234,7 +234,7 @@ func TestItemsRepository_Update(t *testing.T) { Name: entity.Name, LocationID: entity.Location.ID, SerialNumber: fk.Str(10), - LabelIDs: nil, + TagIDs: nil, ModelNumber: fk.Str(10), Manufacturer: fk.Str(10), PurchaseTime: types.DateFromTime(time.Now()), @@ -399,51 +399,51 @@ func TestItemsRepository_DeleteByGroupWithAttachments(t *testing.T) { } func TestItemsRepository_WipeInventory(t *testing.T) { - // Create test data: items, labels, locations, and maintenance entries - + // Create test data: items, tags, locations, and maintenance entries + // Create locations loc1, err := tRepos.Locations.Create(context.Background(), tGroup.ID, LocationCreate{ Name: "Test Location 1", Description: "Test location for wipe test", }) require.NoError(t, err) - + loc2, err := tRepos.Locations.Create(context.Background(), tGroup.ID, LocationCreate{ Name: "Test Location 2", Description: "Another test location", }) require.NoError(t, err) - - // Create labels - label1, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ - Name: "Test Label 1", - Description: "Test label for wipe test", + + // Create tags + tag1, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ + Name: "Test Tag 1", + Description: "Test tag for wipe test", }) require.NoError(t, err) - - label2, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ - Name: "Test Label 2", - Description: "Another test label", + + tag2, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ + Name: "Test Tag 2", + Description: "Another test tag", }) require.NoError(t, err) - + // Create items item1, err := tRepos.Items.Create(context.Background(), tGroup.ID, ItemCreate{ Name: "Test Item 1", Description: "Test item for wipe test", LocationID: loc1.ID, - LabelIDs: []uuid.UUID{label1.ID}, + TagIDs: []uuid.UUID{tag1.ID}, }) require.NoError(t, err) - + item2, err := tRepos.Items.Create(context.Background(), tGroup.ID, ItemCreate{ Name: "Test Item 2", Description: "Another test item", LocationID: loc2.ID, - LabelIDs: []uuid.UUID{label2.ID}, + TagIDs: []uuid.UUID{tag2.ID}, }) require.NoError(t, err) - + // Create maintenance entries for items _, err = tRepos.MaintEntry.Create(context.Background(), item1.ID, MaintenanceEntryCreate{ CompletedDate: types.DateFromTime(time.Now()), @@ -452,7 +452,7 @@ func TestItemsRepository_WipeInventory(t *testing.T) { Cost: 100.0, }) require.NoError(t, err) - + _, err = tRepos.MaintEntry.Create(context.Background(), item2.ID, MaintenanceEntryCreate{ CompletedDate: types.DateFromTime(time.Now()), Name: "Test Maintenance 2", @@ -460,40 +460,40 @@ func TestItemsRepository_WipeInventory(t *testing.T) { Cost: 200.0, }) require.NoError(t, err) - + // Test 1: Wipe inventory with all options enabled - t.Run("wipe all including labels, locations, and maintenance", func(t *testing.T) { + t.Run("wipe all including tags, locations, and maintenance", func(t *testing.T) { deleted, err := tRepos.Items.WipeInventory(context.Background(), tGroup.ID, true, true, true) require.NoError(t, err) assert.Greater(t, deleted, 0, "Should have deleted at least some entities") - + // Verify items are deleted _, err = tRepos.Items.GetOneByGroup(context.Background(), tGroup.ID, item1.ID) require.Error(t, err, "Item 1 should be deleted") - + _, err = tRepos.Items.GetOneByGroup(context.Background(), tGroup.ID, item2.ID) require.Error(t, err, "Item 2 should be deleted") - + // Verify maintenance entries are deleted (query by item ID, should return empty) maint1List, err := tRepos.MaintEntry.GetMaintenanceByItemID(context.Background(), tGroup.ID, item1.ID, MaintenanceFilters{}) require.NoError(t, err) assert.Empty(t, maint1List, "Maintenance entry 1 should be deleted") - + maint2List, err := tRepos.MaintEntry.GetMaintenanceByItemID(context.Background(), tGroup.ID, item2.ID, MaintenanceFilters{}) require.NoError(t, err) assert.Empty(t, maint2List, "Maintenance entry 2 should be deleted") - - // Verify labels are deleted - _, err = tRepos.Labels.GetOneByGroup(context.Background(), tGroup.ID, label1.ID) - require.Error(t, err, "Label 1 should be deleted") - - _, err = tRepos.Labels.GetOneByGroup(context.Background(), tGroup.ID, label2.ID) - require.Error(t, err, "Label 2 should be deleted") - + + // Verify tags are deleted + _, err = tRepos.Tags.GetOneByGroup(context.Background(), tGroup.ID, tag1.ID) + require.Error(t, err, "Tag 1 should be deleted") + + _, err = tRepos.Tags.GetOneByGroup(context.Background(), tGroup.ID, tag2.ID) + require.Error(t, err, "Tag 2 should be deleted") + // Verify locations are deleted _, err = tRepos.Locations.Get(context.Background(), loc1.ID) require.Error(t, err, "Location 1 should be deleted") - + _, err = tRepos.Locations.Get(context.Background(), loc2.ID) require.Error(t, err, "Location 2 should be deleted") }) @@ -506,21 +506,21 @@ func TestItemsRepository_WipeInventory_OnlyItems(t *testing.T) { Description: "Test location for wipe test", }) require.NoError(t, err) - - label, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ - Name: "Test Label", - Description: "Test label for wipe test", + + tag, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ + Name: "Test Tag", + Description: "Test tag for wipe test", }) require.NoError(t, err) - + item, err := tRepos.Items.Create(context.Background(), tGroup.ID, ItemCreate{ Name: "Test Item", Description: "Test item for wipe test", LocationID: loc.ID, - LabelIDs: []uuid.UUID{label.ID}, + TagIDs: []uuid.UUID{tag.ID}, }) require.NoError(t, err) - + _, err = tRepos.MaintEntry.Create(context.Background(), item.ID, MaintenanceEntryCreate{ CompletedDate: types.DateFromTime(time.Now()), Name: "Test Maintenance", @@ -528,31 +528,30 @@ func TestItemsRepository_WipeInventory_OnlyItems(t *testing.T) { Cost: 100.0, }) require.NoError(t, err) - - // Test: Wipe inventory with only items (no labels, locations, or maintenance) + + // Test: Wipe inventory with only items (no tags, locations, or maintenance) deleted, err := tRepos.Items.WipeInventory(context.Background(), tGroup.ID, false, false, false) require.NoError(t, err) assert.Greater(t, deleted, 0, "Should have deleted at least the item") - + // Verify item is deleted _, err = tRepos.Items.GetOneByGroup(context.Background(), tGroup.ID, item.ID) require.Error(t, err, "Item should be deleted") - + // Verify maintenance entry is deleted due to cascade maintList, err := tRepos.MaintEntry.GetMaintenanceByItemID(context.Background(), tGroup.ID, item.ID, MaintenanceFilters{}) require.NoError(t, err) assert.Empty(t, maintList, "Maintenance entry should be cascade deleted with item") - - // Verify label still exists - _, err = tRepos.Labels.GetOneByGroup(context.Background(), tGroup.ID, label.ID) - require.NoError(t, err, "Label should still exist") - + + // Verify tag still exists + _, err = tRepos.Tags.GetOneByGroup(context.Background(), tGroup.ID, tag.ID) + require.NoError(t, err, "Tag should still exist") + // Verify location still exists _, err = tRepos.Locations.Get(context.Background(), loc.ID) require.NoError(t, err, "Location should still exist") - + // Cleanup - _ = tRepos.Labels.DeleteByGroup(context.Background(), tGroup.ID, label.ID) + _ = tRepos.Tags.DeleteByGroup(context.Background(), tGroup.ID, tag.ID) _ = tRepos.Locations.delete(context.Background(), loc.ID) } - diff --git a/backend/internal/data/repo/repo_labels.go b/backend/internal/data/repo/repo_labels.go index fab7a1ec..43d19a30 100644 --- a/backend/internal/data/repo/repo_labels.go +++ b/backend/internal/data/repo/repo_labels.go @@ -8,30 +8,30 @@ import ( "github.com/sysadminsmedia/homebox/backend/internal/core/services/reporting/eventbus" "github.com/sysadminsmedia/homebox/backend/internal/data/ent" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/group" - "github.com/sysadminsmedia/homebox/backend/internal/data/ent/label" + "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag" "github.com/sysadminsmedia/homebox/backend/internal/data/ent/predicate" ) -type LabelRepository struct { +type TagRepository struct { db *ent.Client bus *eventbus.EventBus } type ( - LabelCreate struct { + TagCreate struct { Name string `json:"name" validate:"required,min=1,max=255"` Description string `json:"description" validate:"max=1000"` Color string `json:"color"` } - LabelUpdate struct { + TagUpdate struct { ID uuid.UUID `json:"id"` Name string `json:"name" validate:"required,min=1,max=255"` Description string `json:"description" validate:"max=1000"` Color string `json:"color"` } - LabelSummary struct { + TagSummary struct { ID uuid.UUID `json:"id"` Name string `json:"name"` Description string `json:"description"` @@ -40,86 +40,86 @@ type ( UpdatedAt time.Time `json:"updatedAt"` } - LabelOut struct { - LabelSummary + TagOut struct { + TagSummary } ) -func mapLabelSummary(label *ent.Label) LabelSummary { - return LabelSummary{ - ID: label.ID, - Name: label.Name, - Description: label.Description, - Color: label.Color, - CreatedAt: label.CreatedAt, - UpdatedAt: label.UpdatedAt, +func mapTagSummary(tag *ent.Tag) TagSummary { + return TagSummary{ + ID: tag.ID, + Name: tag.Name, + Description: tag.Description, + Color: tag.Color, + CreatedAt: tag.CreatedAt, + UpdatedAt: tag.UpdatedAt, } } var ( - mapLabelOutErr = mapTErrFunc(mapLabelOut) - mapLabelsOut = mapTEachErrFunc(mapLabelSummary) + mapTagOutErr = mapTErrFunc(mapTagOut) + mapTagsOut = mapTEachErrFunc(mapTagSummary) ) -func mapLabelOut(label *ent.Label) LabelOut { - return LabelOut{ - LabelSummary: mapLabelSummary(label), +func mapTagOut(tag *ent.Tag) TagOut { + return TagOut{ + TagSummary: mapTagSummary(tag), } } -func (r *LabelRepository) publishMutationEvent(gid uuid.UUID) { +func (r *TagRepository) publishMutationEvent(gid uuid.UUID) { if r.bus != nil { - r.bus.Publish(eventbus.EventLabelMutation, eventbus.GroupMutationEvent{GID: gid}) + r.bus.Publish(eventbus.EventTagMutation, eventbus.GroupMutationEvent{GID: gid}) } } -func (r *LabelRepository) getOne(ctx context.Context, where ...predicate.Label) (LabelOut, error) { - return mapLabelOutErr(r.db.Label.Query(). +func (r *TagRepository) getOne(ctx context.Context, where ...predicate.Tag) (TagOut, error) { + return mapTagOutErr(r.db.Tag.Query(). Where(where...). WithGroup(). Only(ctx), ) } -func (r *LabelRepository) GetOne(ctx context.Context, id uuid.UUID) (LabelOut, error) { - return r.getOne(ctx, label.ID(id)) +func (r *TagRepository) GetOne(ctx context.Context, id uuid.UUID) (TagOut, error) { + return r.getOne(ctx, tag.ID(id)) } -func (r *LabelRepository) GetOneByGroup(ctx context.Context, gid, ld uuid.UUID) (LabelOut, error) { - return r.getOne(ctx, label.ID(ld), label.HasGroupWith(group.ID(gid))) +func (r *TagRepository) GetOneByGroup(ctx context.Context, gid, ld uuid.UUID) (TagOut, error) { + return r.getOne(ctx, tag.ID(ld), tag.HasGroupWith(group.ID(gid))) } -func (r *LabelRepository) GetAll(ctx context.Context, groupID uuid.UUID) ([]LabelSummary, error) { - return mapLabelsOut(r.db.Label.Query(). - Where(label.HasGroupWith(group.ID(groupID))). - Order(ent.Asc(label.FieldName)). +func (r *TagRepository) GetAll(ctx context.Context, groupID uuid.UUID) ([]TagSummary, error) { + return mapTagsOut(r.db.Tag.Query(). + Where(tag.HasGroupWith(group.ID(groupID))). + Order(ent.Asc(tag.FieldName)). WithGroup(). All(ctx), ) } -func (r *LabelRepository) Create(ctx context.Context, groupID uuid.UUID, data LabelCreate) (LabelOut, error) { - label, err := r.db.Label.Create(). +func (r *TagRepository) Create(ctx context.Context, groupID uuid.UUID, data TagCreate) (TagOut, error) { + tag, err := r.db.Tag.Create(). SetName(data.Name). SetDescription(data.Description). SetColor(data.Color). SetGroupID(groupID). Save(ctx) if err != nil { - return LabelOut{}, err + return TagOut{}, err } - label.Edges.Group = &ent.Group{ID: groupID} // bootstrap group ID + tag.Edges.Group = &ent.Group{ID: groupID} // bootstrap group ID r.publishMutationEvent(groupID) - return mapLabelOut(label), err + return mapTagOut(tag), err } -func (r *LabelRepository) update(ctx context.Context, data LabelUpdate, where ...predicate.Label) (int, error) { +func (r *TagRepository) update(ctx context.Context, data TagUpdate, where ...predicate.Tag) (int, error) { if len(where) == 0 { panic("empty where not supported empty") } - return r.db.Label.Update(). + return r.db.Tag.Update(). Where(where...). SetName(data.Name). SetDescription(data.Description). @@ -127,27 +127,27 @@ func (r *LabelRepository) update(ctx context.Context, data LabelUpdate, where .. Save(ctx) } -func (r *LabelRepository) UpdateByGroup(ctx context.Context, gid uuid.UUID, data LabelUpdate) (LabelOut, error) { - _, err := r.update(ctx, data, label.ID(data.ID), label.HasGroupWith(group.ID(gid))) +func (r *TagRepository) UpdateByGroup(ctx context.Context, gid uuid.UUID, data TagUpdate) (TagOut, error) { + _, err := r.update(ctx, data, tag.ID(data.ID), tag.HasGroupWith(group.ID(gid))) if err != nil { - return LabelOut{}, err + return TagOut{}, err } r.publishMutationEvent(gid) return r.GetOne(ctx, data.ID) } -// delete removes the label from the database. This should only be used when -// the label's ownership is already confirmed/validated. -func (r *LabelRepository) delete(ctx context.Context, id uuid.UUID) error { - return r.db.Label.DeleteOneID(id).Exec(ctx) +// delete removes the tag from the database. This should only be used when +// the tag's ownership is already confirmed/validated. +func (r *TagRepository) delete(ctx context.Context, id uuid.UUID) error { + return r.db.Tag.DeleteOneID(id).Exec(ctx) } -func (r *LabelRepository) DeleteByGroup(ctx context.Context, gid, id uuid.UUID) error { - _, err := r.db.Label.Delete(). +func (r *TagRepository) DeleteByGroup(ctx context.Context, gid, id uuid.UUID) error { + _, err := r.db.Tag.Delete(). Where( - label.ID(id), - label.HasGroupWith(group.ID(gid)), + tag.ID(id), + tag.HasGroupWith(group.ID(gid)), ).Exec(ctx) if err != nil { return err diff --git a/backend/internal/data/repo/repo_labels_test.go b/backend/internal/data/repo/repo_labels_test.go index 8b1d66fc..4b5a400c 100644 --- a/backend/internal/data/repo/repo_labels_test.go +++ b/backend/internal/data/repo/repo_labels_test.go @@ -8,96 +8,96 @@ import ( "github.com/stretchr/testify/require" ) -func labelFactory() LabelCreate { - return LabelCreate{ +func tagFactory() TagCreate { + return TagCreate{ Name: fk.Str(10), Description: fk.Str(100), } } -func useLabels(t *testing.T, len int) []LabelOut { +func useTags(t *testing.T, len int) []TagOut { t.Helper() - labels := make([]LabelOut, len) + tags := make([]TagOut, len) for i := 0; i < len; i++ { - itm := labelFactory() + itm := tagFactory() - item, err := tRepos.Labels.Create(context.Background(), tGroup.ID, itm) + item, err := tRepos.Tags.Create(context.Background(), tGroup.ID, itm) require.NoError(t, err) - labels[i] = item + tags[i] = item } t.Cleanup(func() { - for _, item := range labels { - _ = tRepos.Labels.delete(context.Background(), item.ID) + for _, item := range tags { + _ = tRepos.Tags.delete(context.Background(), item.ID) } }) - return labels + return tags } -func TestLabelRepository_Get(t *testing.T) { - labels := useLabels(t, 1) - label := labels[0] +func TestTagRepository_Get(t *testing.T) { + tags := useTags(t, 1) + tag := tags[0] // Get by ID - foundLoc, err := tRepos.Labels.GetOne(context.Background(), label.ID) + foundLoc, err := tRepos.Tags.GetOne(context.Background(), tag.ID) require.NoError(t, err) - assert.Equal(t, label.ID, foundLoc.ID) + assert.Equal(t, tag.ID, foundLoc.ID) } -func TestLabelRepositoryGetAll(t *testing.T) { - useLabels(t, 10) +func TestTagRepositoryGetAll(t *testing.T) { + useTags(t, 10) - all, err := tRepos.Labels.GetAll(context.Background(), tGroup.ID) + all, err := tRepos.Tags.GetAll(context.Background(), tGroup.ID) require.NoError(t, err) assert.Len(t, all, 10) } -func TestLabelRepository_Create(t *testing.T) { - loc, err := tRepos.Labels.Create(context.Background(), tGroup.ID, labelFactory()) +func TestTagRepository_Create(t *testing.T) { + loc, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory()) require.NoError(t, err) // Get by ID - foundLoc, err := tRepos.Labels.GetOne(context.Background(), loc.ID) + foundLoc, err := tRepos.Tags.GetOne(context.Background(), loc.ID) require.NoError(t, err) assert.Equal(t, loc.ID, foundLoc.ID) - err = tRepos.Labels.delete(context.Background(), loc.ID) + err = tRepos.Tags.delete(context.Background(), loc.ID) require.NoError(t, err) } -func TestLabelRepository_Update(t *testing.T) { - loc, err := tRepos.Labels.Create(context.Background(), tGroup.ID, labelFactory()) +func TestTagsRepository_Update(t *testing.T) { + loc, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory()) require.NoError(t, err) - updateData := LabelUpdate{ + updateData := TagUpdate{ ID: loc.ID, Name: fk.Str(10), Description: fk.Str(100), } - update, err := tRepos.Labels.UpdateByGroup(context.Background(), tGroup.ID, updateData) + update, err := tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateData) require.NoError(t, err) - foundLoc, err := tRepos.Labels.GetOne(context.Background(), loc.ID) + foundLoc, err := tRepos.Tags.GetOne(context.Background(), loc.ID) require.NoError(t, err) assert.Equal(t, update.ID, foundLoc.ID) assert.Equal(t, update.Name, foundLoc.Name) assert.Equal(t, update.Description, foundLoc.Description) - err = tRepos.Labels.delete(context.Background(), loc.ID) + err = tRepos.Tags.delete(context.Background(), loc.ID) require.NoError(t, err) } -func TestLabelRepository_Delete(t *testing.T) { - loc, err := tRepos.Labels.Create(context.Background(), tGroup.ID, labelFactory()) +func TestTagRepository_Delete(t *testing.T) { + loc, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory()) require.NoError(t, err) - err = tRepos.Labels.delete(context.Background(), loc.ID) + err = tRepos.Tags.delete(context.Background(), loc.ID) require.NoError(t, err) - _, err = tRepos.Labels.GetOne(context.Background(), loc.ID) + _, err = tRepos.Tags.GetOne(context.Background(), loc.ID) require.Error(t, err) } diff --git a/backend/internal/data/repo/repo_wipe_integration_test.go b/backend/internal/data/repo/repo_wipe_integration_test.go index 30a0fb95..9cb46ae1 100644 --- a/backend/internal/data/repo/repo_wipe_integration_test.go +++ b/backend/internal/data/repo/repo_wipe_integration_test.go @@ -13,7 +13,7 @@ import ( // TestWipeInventory_Integration tests the complete wipe inventory flow func TestWipeInventory_Integration(t *testing.T) { - // Create test data: locations, labels, items with maintenance + // Create test data: locations, tags, items with maintenance // 1. Create locations loc1, err := tRepos.Locations.Create(context.Background(), tGroup.ID, LocationCreate{ @@ -28,16 +28,16 @@ func TestWipeInventory_Integration(t *testing.T) { }) require.NoError(t, err) - // 2. Create labels - label1, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ + // 2. Create tags + tag1, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ Name: "Test Electronics", - Description: "Electronics label", + Description: "Electronics tag", }) require.NoError(t, err) - label2, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ + tag2, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ Name: "Test Tools", - Description: "Tools label", + Description: "Tools tag", }) require.NoError(t, err) @@ -46,7 +46,7 @@ func TestWipeInventory_Integration(t *testing.T) { Name: "Test Laptop", Description: "Work laptop", LocationID: loc1.ID, - LabelIDs: []uuid.UUID{label1.ID}, + TagIDs: []uuid.UUID{tag1.ID}, }) require.NoError(t, err) @@ -54,7 +54,7 @@ func TestWipeInventory_Integration(t *testing.T) { Name: "Test Drill", Description: "Power drill", LocationID: loc2.ID, - LabelIDs: []uuid.UUID{label2.ID}, + TagIDs: []uuid.UUID{tag2.ID}, }) require.NoError(t, err) @@ -62,7 +62,7 @@ func TestWipeInventory_Integration(t *testing.T) { Name: "Test Monitor", Description: "Computer monitor", LocationID: loc1.ID, - LabelIDs: []uuid.UUID{label1.ID}, + TagIDs: []uuid.UUID{tag1.ID}, }) require.NoError(t, err) @@ -119,13 +119,13 @@ func TestWipeInventory_Integration(t *testing.T) { maint1After, err := tRepos.MaintEntry.GetMaintenanceByItemID(context.Background(), tGroup.ID, item1.ID, MaintenanceFilters{}) require.NoError(t, err) assert.Empty(t, maint1After, "Item 1 maintenance records should be deleted") - - // 10. Verify labels are deleted - _, err = tRepos.Labels.GetOneByGroup(context.Background(), tGroup.ID, label1.ID) - require.Error(t, err, "Label 1 should be deleted") - - _, err = tRepos.Labels.GetOneByGroup(context.Background(), tGroup.ID, label2.ID) - require.Error(t, err, "Label 2 should be deleted") + + // 10. Verify tags are deleted + _, err = tRepos.Tags.GetOneByGroup(context.Background(), tGroup.ID, tag1.ID) + require.Error(t, err, "Tag 1 should be deleted") + + _, err = tRepos.Tags.GetOneByGroup(context.Background(), tGroup.ID, tag2.ID) + require.Error(t, err, "Tag 2 should be deleted") // 11. Verify locations are deleted _, err = tRepos.Locations.Get(context.Background(), loc1.ID) @@ -144,9 +144,9 @@ func TestWipeInventory_SelectiveWipe(t *testing.T) { }) require.NoError(t, err) - label, err := tRepos.Labels.Create(context.Background(), tGroup.ID, LabelCreate{ + tag, err := tRepos.Tags.Create(context.Background(), tGroup.ID, TagCreate{ Name: "Test Important", - Description: "Important label", + Description: "Important tag", }) require.NoError(t, err) @@ -154,7 +154,7 @@ func TestWipeInventory_SelectiveWipe(t *testing.T) { Name: "Test Computer", Description: "Desktop computer", LocationID: loc.ID, - LabelIDs: []uuid.UUID{label.ID}, + TagIDs: []uuid.UUID{tag.ID}, }) require.NoError(t, err) @@ -165,8 +165,8 @@ func TestWipeInventory_SelectiveWipe(t *testing.T) { Cost: 0, }) require.NoError(t, err) - - // Test: Wipe only items (keep labels and locations) + + // Test: Wipe only items (keep tags and locations) deleted, err := tRepos.Items.WipeInventory(context.Background(), tGroup.ID, false, false, false) require.NoError(t, err) assert.Greater(t, deleted, 0, "Should have deleted at least items") @@ -180,15 +180,15 @@ func TestWipeInventory_SelectiveWipe(t *testing.T) { require.NoError(t, err) assert.Empty(t, maintList, "Maintenance should be cascade deleted") - // Verify label still exists - _, err = tRepos.Labels.GetOneByGroup(context.Background(), tGroup.ID, label.ID) - require.NoError(t, err, "Label should still exist") - + // Verify tag still exists + _, err = tRepos.Tags.GetOneByGroup(context.Background(), tGroup.ID, tag.ID) + require.NoError(t, err, "Tag should still exist") + // Verify location still exists _, err = tRepos.Locations.Get(context.Background(), loc.ID) require.NoError(t, err, "Location should still exist") // Cleanup - _ = tRepos.Labels.DeleteByGroup(context.Background(), tGroup.ID, label.ID) + _ = tRepos.Tags.DeleteByGroup(context.Background(), tGroup.ID, tag.ID) _ = tRepos.Locations.delete(context.Background(), loc.ID) } diff --git a/backend/internal/data/repo/repos_all.go b/backend/internal/data/repo/repos_all.go index 6109d743..e961822c 100644 --- a/backend/internal/data/repo/repos_all.go +++ b/backend/internal/data/repo/repos_all.go @@ -13,7 +13,7 @@ type AllRepos struct { AuthTokens *TokenRepository Groups *GroupRepository Locations *LocationRepository - Labels *LabelRepository + Tags *TagRepository Items *ItemsRepository ItemTemplates *ItemTemplatesRepository Attachments *AttachmentRepo @@ -28,7 +28,7 @@ func New(db *ent.Client, bus *eventbus.EventBus, storage config.Storage, pubSubC AuthTokens: &TokenRepository{db}, Groups: NewGroupRepository(db), Locations: &LocationRepository{db, bus}, - Labels: &LabelRepository{db, bus}, + Tags: &TagRepository{db, bus}, Items: &ItemsRepository{db, bus, attachments}, ItemTemplates: &ItemTemplatesRepository{db, bus}, Attachments: attachments,