A continuation of HomeBox the inventory and organization system built for the Home User
feat: better tags
Matthew Kilgoree27b3e4b79c6
diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.goindex 8d6789db..c2938f7e 100644--- a/backend/app/api/static/docs/docs.go+++ b/backend/app/api/static/docs/docs.go@@ -3678,6 +3678,10 @@ const docTemplate = `{}]},+ "icon": {+ "description": "Icon holds the value of the \"icon\" field.",+ "type": "string"+ },"id": {"description": "ID of the ent.","type": "string"@@ -3695,6 +3699,13 @@ const docTemplate = `{"ent.TagEdges": {"type": "object","properties": {+ "children": {+ "description": "Children holds the value of the children edge.",+ "type": "array",+ "items": {+ "$ref": "#/definitions/ent.Tag"+ }+ },"group": {"description": "Group holds the value of the group edge.","allOf": [@@ -3709,6 +3720,14 @@ const docTemplate = `{"items": {"$ref": "#/definitions/ent.Item"}+ },+ "parent": {+ "description": "Parent holds the value of the parent edge.",+ "allOf": [+ {+ "$ref": "#/definitions/ent.Tag"+ }+ ]}}},@@ -5065,12 +5084,22 @@ const docTemplate = `{"type": "string","maxLength": 255,"minLength": 1+ },+ "parentId": {+ "type": "string",+ "x-nullable": true}}},"repo.TagOut": {"type": "object","properties": {+ "children": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/repo.TagSummary"+ }+ },"color": {"type": "string"},@@ -5086,6 +5115,13 @@ const docTemplate = `{"name": {"type": "string"},+ "parent": {+ "$ref": "#/definitions/repo.TagSummary"+ },+ "parentId": {+ "type": "string",+ "x-nullable": true+ },"updatedAt": {"type": "string"}@@ -5109,6 +5145,10 @@ const docTemplate = `{"name": {"type": "string"},+ "parentId": {+ "type": "string",+ "x-nullable": true+ },"updatedAt": {"type": "string"}diff --git a/backend/app/api/static/docs/openapi-3.json b/backend/app/api/static/docs/openapi-3.jsonindex 6cdb869e..ca0c97a0 100644--- a/backend/app/api/static/docs/openapi-3.json+++ b/backend/app/api/static/docs/openapi-3.json@@ -3875,6 +3875,10 @@}]},+ "icon": {+ "description": "Icon holds the value of the \"icon\" field.",+ "type": "string"+ },"id": {"description": "ID of the ent.","type": "string"@@ -3892,6 +3896,13 @@"ent.TagEdges": {"type": "object","properties": {+ "children": {+ "description": "Children holds the value of the children edge.",+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/ent.Tag"+ }+ },"group": {"description": "Group holds the value of the group edge.","allOf": [@@ -3906,6 +3917,14 @@"items": {"$ref": "#/components/schemas/ent.Item"}+ },+ "parent": {+ "description": "Parent holds the value of the parent edge.",+ "allOf": [+ {+ "$ref": "#/components/schemas/ent.Tag"+ }+ ]}}},@@ -5262,12 +5281,22 @@"type": "string","maxLength": 255,"minLength": 1+ },+ "parentId": {+ "type": "string",+ "nullable": true}}},"repo.TagOut": {"type": "object","properties": {+ "children": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/repo.TagSummary"+ }+ },"color": {"type": "string"},@@ -5283,6 +5312,13 @@"name": {"type": "string"},+ "parent": {+ "$ref": "#/components/schemas/repo.TagSummary"+ },+ "parentId": {+ "type": "string",+ "nullable": true+ },"updatedAt": {"type": "string"}@@ -5306,6 +5342,10 @@"name": {"type": "string"},+ "parentId": {+ "type": "string",+ "nullable": true+ },"updatedAt": {"type": "string"}diff --git a/backend/app/api/static/docs/openapi-3.yaml b/backend/app/api/static/docs/openapi-3.yamlindex 079cac0d..30cd8bdd 100644--- a/backend/app/api/static/docs/openapi-3.yaml+++ b/backend/app/api/static/docs/openapi-3.yaml@@ -2399,6 +2399,9 @@ components:The values are being populated by the TagQuery when eager-loading is set.allOf:- $ref: "#/components/schemas/ent.TagEdges"+ icon:+ description: Icon holds the value of the "icon" field.+ type: stringid:description: ID of the ent.type: string@@ -2411,6 +2414,11 @@ components:ent.TagEdges:type: objectproperties:+ children:+ description: Children holds the value of the children edge.+ type: array+ items:+ $ref: "#/components/schemas/ent.Tag"group:description: Group holds the value of the group edge.allOf:@@ -2420,6 +2428,10 @@ components:type: arrayitems:$ref: "#/components/schemas/ent.Item"+ parent:+ description: Parent holds the value of the parent edge.+ allOf:+ - $ref: "#/components/schemas/ent.Tag"ent.TemplateField:type: objectproperties:@@ -3354,9 +3366,16 @@ components:type: stringmaxLength: 255minLength: 1+ parentId:+ type: string+ nullable: truerepo.TagOut:type: objectproperties:+ children:+ type: array+ items:+ $ref: "#/components/schemas/repo.TagSummary"color:type: stringcreatedAt:@@ -3367,6 +3386,11 @@ components:type: stringname:type: string+ parent:+ $ref: "#/components/schemas/repo.TagSummary"+ parentId:+ type: string+ nullable: trueupdatedAt:type: stringrepo.TagSummary:@@ -3382,6 +3406,9 @@ components:type: stringname:type: string+ parentId:+ type: string+ nullable: trueupdatedAt:type: stringrepo.TemplateField:diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.jsonindex 2b64e355..9ba2171d 100644--- a/backend/app/api/static/docs/swagger.json+++ b/backend/app/api/static/docs/swagger.json@@ -3676,6 +3676,10 @@}]},+ "icon": {+ "description": "Icon holds the value of the \"icon\" field.",+ "type": "string"+ },"id": {"description": "ID of the ent.","type": "string"@@ -3693,6 +3697,13 @@"ent.TagEdges": {"type": "object","properties": {+ "children": {+ "description": "Children holds the value of the children edge.",+ "type": "array",+ "items": {+ "$ref": "#/definitions/ent.Tag"+ }+ },"group": {"description": "Group holds the value of the group edge.","allOf": [@@ -3707,6 +3718,14 @@"items": {"$ref": "#/definitions/ent.Item"}+ },+ "parent": {+ "description": "Parent holds the value of the parent edge.",+ "allOf": [+ {+ "$ref": "#/definitions/ent.Tag"+ }+ ]}}},@@ -5063,12 +5082,22 @@"type": "string","maxLength": 255,"minLength": 1+ },+ "parentId": {+ "type": "string",+ "x-nullable": true}}},"repo.TagOut": {"type": "object","properties": {+ "children": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/repo.TagSummary"+ }+ },"color": {"type": "string"},@@ -5084,6 +5113,13 @@"name": {"type": "string"},+ "parent": {+ "$ref": "#/definitions/repo.TagSummary"+ },+ "parentId": {+ "type": "string",+ "x-nullable": true+ },"updatedAt": {"type": "string"}@@ -5107,6 +5143,10 @@"name": {"type": "string"},+ "parentId": {+ "type": "string",+ "x-nullable": true+ },"updatedAt": {"type": "string"}diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yamlindex e113de4f..b23114bd 100644--- a/backend/app/api/static/docs/swagger.yaml+++ b/backend/app/api/static/docs/swagger.yaml@@ -651,6 +651,9 @@ definitions:description: |-Edges holds the relations/edges for other nodes in the graph.The values are being populated by the TagQuery when eager-loading is set.+ icon:+ description: Icon holds the value of the "icon" field.+ type: stringid:description: ID of the ent.type: string@@ -663,6 +666,11 @@ definitions:type: objectent.TagEdges:properties:+ children:+ description: Children holds the value of the children edge.+ items:+ $ref: '#/definitions/ent.Tag'+ type: arraygroup:allOf:- $ref: '#/definitions/ent.Group'@@ -672,6 +680,10 @@ definitions:items:$ref: '#/definitions/ent.Item'type: array+ parent:+ allOf:+ - $ref: '#/definitions/ent.Tag'+ description: Parent holds the value of the parent edge.type: objectent.TemplateField:properties:@@ -1602,11 +1614,18 @@ definitions:maxLength: 255minLength: 1type: string+ parentId:+ type: string+ x-nullable: truerequired:- nametype: objectrepo.TagOut:properties:+ children:+ items:+ $ref: '#/definitions/repo.TagSummary'+ type: arraycolor:type: stringcreatedAt:@@ -1617,6 +1636,11 @@ definitions:type: stringname:type: string+ parent:+ $ref: '#/definitions/repo.TagSummary'+ parentId:+ type: string+ x-nullable: trueupdatedAt:type: stringtype: object@@ -1632,6 +1656,9 @@ definitions:type: stringname:type: string+ parentId:+ type: string+ x-nullable: trueupdatedAt:type: stringtype: objectdiff --git a/backend/internal/data/ent/client.go b/backend/internal/data/ent/client.goindex 8774b2a0..21ecfdbb 100644--- a/backend/internal/data/ent/client.go+++ b/backend/internal/data/ent/client.go@@ -2429,6 +2429,38 @@ func (c *TagClient) QueryItems(_m *Tag) *ItemQuery {return query}+// QueryParent queries the parent edge of a Tag.+func (c *TagClient) QueryParent(_m *Tag) *TagQuery {+ query := (&TagClient{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(tag.Table, tag.FieldID),+ sqlgraph.Edge(sqlgraph.M2O, true, tag.ParentTable, tag.ParentColumn),+ )+ fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)+ return fromV, nil+ }+ return query+}++// QueryChildren queries the children edge of a Tag.+func (c *TagClient) QueryChildren(_m *Tag) *TagQuery {+ query := (&TagClient{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(tag.Table, tag.FieldID),+ sqlgraph.Edge(sqlgraph.O2M, false, tag.ChildrenTable, tag.ChildrenColumn),+ )+ 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.Tagdiff --git a/backend/internal/data/ent/migrate/schema.go b/backend/internal/data/ent/migrate/schema.goindex 06231edf..d13e1156 100644--- a/backend/internal/data/ent/migrate/schema.go+++ b/backend/internal/data/ent/migrate/schema.go@@ -413,7 +413,9 @@ var ({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: "icon", Type: field.TypeString, Nullable: true, Size: 255},{Name: "group_tags", Type: field.TypeUUID},+ {Name: "tag_children", Type: field.TypeUUID, Nullable: true},}// TagsTable holds the schema information for the "tags" table.TagsTable = &schema.Table{@@ -423,10 +425,16 @@ var (ForeignKeys: []*schema.ForeignKey{{Symbol: "tags_groups_tags",- Columns: []*schema.Column{TagsColumns[6]},+ Columns: []*schema.Column{TagsColumns[7]},RefColumns: []*schema.Column{GroupsColumns[0]},OnDelete: schema.Cascade,},+ {+ Symbol: "tags_tags_children",+ Columns: []*schema.Column{TagsColumns[8]},+ RefColumns: []*schema.Column{TagsColumns[0]},+ OnDelete: schema.SetNull,+ },},}// TemplateFieldsColumns holds the columns for the "template_fields" table.@@ -575,6 +583,7 @@ func init() {NotifiersTable.ForeignKeys[0].RefTable = GroupsTableNotifiersTable.ForeignKeys[1].RefTable = UsersTableTagsTable.ForeignKeys[0].RefTable = GroupsTable+ TagsTable.ForeignKeys[1].RefTable = TagsTableTemplateFieldsTable.ForeignKeys[0].RefTable = ItemTemplatesTableTagItemsTable.ForeignKeys[0].RefTable = TagsTableTagItemsTable.ForeignKeys[1].RefTable = ItemsTablediff --git a/backend/internal/data/ent/mutation.go b/backend/internal/data/ent/mutation.goindex 1d5d3768..7b00ded1 100644--- a/backend/internal/data/ent/mutation.go+++ b/backend/internal/data/ent/mutation.go@@ -11118,23 +11118,29 @@ func (m *NotifierMutation) ResetEdge(name string) error {// 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+ op Op+ typ string+ id *uuid.UUID+ created_at *time.Time+ updated_at *time.Time+ name *string+ description *string+ color *string+ icon *string+ clearedFields map[string]struct{}+ group *uuid.UUID+ clearedgroup bool+ items map[uuid.UUID]struct{}+ removeditems map[uuid.UUID]struct{}+ cleareditems bool+ parent *uuid.UUID+ clearedparent bool+ children map[uuid.UUID]struct{}+ removedchildren map[uuid.UUID]struct{}+ clearedchildren bool+ done bool+ oldValue func(context.Context) (*Tag, error)+ predicates []predicate.Tag}var _ ent.Mutation = (*TagMutation)(nil)@@ -11447,6 +11453,55 @@ func (m *TagMutation) ResetColor() {delete(m.clearedFields, tag.FieldColor)}+// SetIcon sets the "icon" field.+func (m *TagMutation) SetIcon(s string) {+ m.icon = &s+}++// Icon returns the value of the "icon" field in the mutation.+func (m *TagMutation) Icon() (r string, exists bool) {+ v := m.icon+ if v == nil {+ return+ }+ return *v, true+}++// OldIcon returns the old "icon" 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) OldIcon(ctx context.Context) (v string, err error) {+ if !m.op.Is(OpUpdateOne) {+ return v, errors.New("OldIcon is only allowed on UpdateOne operations")+ }+ if m.id == nil || m.oldValue == nil {+ return v, errors.New("OldIcon requires an ID field in the mutation")+ }+ oldValue, err := m.oldValue(ctx)+ if err != nil {+ return v, fmt.Errorf("querying old value for OldIcon: %w", err)+ }+ return oldValue.Icon, nil+}++// ClearIcon clears the value of the "icon" field.+func (m *TagMutation) ClearIcon() {+ m.icon = nil+ m.clearedFields[tag.FieldIcon] = struct{}{}+}++// IconCleared returns if the "icon" field was cleared in this mutation.+func (m *TagMutation) IconCleared() bool {+ _, ok := m.clearedFields[tag.FieldIcon]+ return ok+}++// ResetIcon resets all changes to the "icon" field.+func (m *TagMutation) ResetIcon() {+ m.icon = nil+ delete(m.clearedFields, tag.FieldIcon)+}+// SetGroupID sets the "group" edge to the Group entity by id.func (m *TagMutation) SetGroupID(id uuid.UUID) {m.group = &id@@ -11540,6 +11595,99 @@ func (m *TagMutation) ResetItems() {m.removeditems = nil}+// SetParentID sets the "parent" edge to the Tag entity by id.+func (m *TagMutation) SetParentID(id uuid.UUID) {+ m.parent = &id+}++// ClearParent clears the "parent" edge to the Tag entity.+func (m *TagMutation) ClearParent() {+ m.clearedparent = true+}++// ParentCleared reports if the "parent" edge to the Tag entity was cleared.+func (m *TagMutation) ParentCleared() bool {+ return m.clearedparent+}++// ParentID returns the "parent" edge ID in the mutation.+func (m *TagMutation) ParentID() (id uuid.UUID, exists bool) {+ if m.parent != nil {+ return *m.parent, true+ }+ return+}++// ParentIDs returns the "parent" edge IDs in the mutation.+// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use+// ParentID instead. It exists only for internal usage by the builders.+func (m *TagMutation) ParentIDs() (ids []uuid.UUID) {+ if id := m.parent; id != nil {+ ids = append(ids, *id)+ }+ return+}++// ResetParent resets all changes to the "parent" edge.+func (m *TagMutation) ResetParent() {+ m.parent = nil+ m.clearedparent = false+}++// AddChildIDs adds the "children" edge to the Tag entity by ids.+func (m *TagMutation) AddChildIDs(ids ...uuid.UUID) {+ if m.children == nil {+ m.children = make(map[uuid.UUID]struct{})+ }+ for i := range ids {+ m.children[ids[i]] = struct{}{}+ }+}++// ClearChildren clears the "children" edge to the Tag entity.+func (m *TagMutation) ClearChildren() {+ m.clearedchildren = true+}++// ChildrenCleared reports if the "children" edge to the Tag entity was cleared.+func (m *TagMutation) ChildrenCleared() bool {+ return m.clearedchildren+}++// RemoveChildIDs removes the "children" edge to the Tag entity by IDs.+func (m *TagMutation) RemoveChildIDs(ids ...uuid.UUID) {+ if m.removedchildren == nil {+ m.removedchildren = make(map[uuid.UUID]struct{})+ }+ for i := range ids {+ delete(m.children, ids[i])+ m.removedchildren[ids[i]] = struct{}{}+ }+}++// RemovedChildren returns the removed IDs of the "children" edge to the Tag entity.+func (m *TagMutation) RemovedChildrenIDs() (ids []uuid.UUID) {+ for id := range m.removedchildren {+ ids = append(ids, id)+ }+ return+}++// ChildrenIDs returns the "children" edge IDs in the mutation.+func (m *TagMutation) ChildrenIDs() (ids []uuid.UUID) {+ for id := range m.children {+ ids = append(ids, id)+ }+ return+}++// ResetChildren resets all changes to the "children" edge.+func (m *TagMutation) ResetChildren() {+ m.children = nil+ m.clearedchildren = false+ m.removedchildren = nil+}+// Where appends a list predicates to the TagMutation builder.func (m *TagMutation) Where(ps ...predicate.Tag) {m.predicates = append(m.predicates, ps...)@@ -11574,7 +11722,7 @@ func (m *TagMutation) Type() string {// order to get all numeric fields that were incremented/decremented, call// AddedFields().func (m *TagMutation) Fields() []string {- fields := make([]string, 0, 5)+ fields := make([]string, 0, 6)if m.created_at != nil {fields = append(fields, tag.FieldCreatedAt)}@@ -11590,6 +11738,9 @@ func (m *TagMutation) Fields() []string {if m.color != nil {fields = append(fields, tag.FieldColor)}+ if m.icon != nil {+ fields = append(fields, tag.FieldIcon)+ }return fields}@@ -11608,6 +11759,8 @@ func (m *TagMutation) Field(name string) (ent.Value, bool) {return m.Description()case tag.FieldColor:return m.Color()+ case tag.FieldIcon:+ return m.Icon()}return nil, false}@@ -11627,6 +11780,8 @@ func (m *TagMutation) OldField(ctx context.Context, name string) (ent.Value, errreturn m.OldDescription(ctx)case tag.FieldColor:return m.OldColor(ctx)+ case tag.FieldIcon:+ return m.OldIcon(ctx)}return nil, fmt.Errorf("unknown Tag field %s", name)}@@ -11671,6 +11826,13 @@ func (m *TagMutation) SetField(name string, value ent.Value) error {}m.SetColor(v)return nil+ case tag.FieldIcon:+ v, ok := value.(string)+ if !ok {+ return fmt.Errorf("unexpected type %T for field %s", value, name)+ }+ m.SetIcon(v)+ return nil}return fmt.Errorf("unknown Tag field %s", name)}@@ -11707,6 +11869,9 @@ func (m *TagMutation) ClearedFields() []string {if m.FieldCleared(tag.FieldColor) {fields = append(fields, tag.FieldColor)}+ if m.FieldCleared(tag.FieldIcon) {+ fields = append(fields, tag.FieldIcon)+ }return fields}@@ -11727,6 +11892,9 @@ func (m *TagMutation) ClearField(name string) error {case tag.FieldColor:m.ClearColor()return nil+ case tag.FieldIcon:+ m.ClearIcon()+ return nil}return fmt.Errorf("unknown Tag nullable field %s", name)}@@ -11750,19 +11918,28 @@ func (m *TagMutation) ResetField(name string) error {case tag.FieldColor:m.ResetColor()return nil+ case tag.FieldIcon:+ m.ResetIcon()+ 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)+ edges := make([]string, 0, 4)if m.group != nil {edges = append(edges, tag.EdgeGroup)}if m.items != nil {edges = append(edges, tag.EdgeItems)}+ if m.parent != nil {+ edges = append(edges, tag.EdgeParent)+ }+ if m.children != nil {+ edges = append(edges, tag.EdgeChildren)+ }return edges}@@ -11780,16 +11957,29 @@ func (m *TagMutation) AddedIDs(name string) []ent.Value {ids = append(ids, id)}return ids+ case tag.EdgeParent:+ if id := m.parent; id != nil {+ return []ent.Value{*id}+ }+ case tag.EdgeChildren:+ ids := make([]ent.Value, 0, len(m.children))+ for id := range m.children {+ 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)+ edges := make([]string, 0, 4)if m.removeditems != nil {edges = append(edges, tag.EdgeItems)}+ if m.removedchildren != nil {+ edges = append(edges, tag.EdgeChildren)+ }return edges}@@ -11803,19 +11993,31 @@ func (m *TagMutation) RemovedIDs(name string) []ent.Value {ids = append(ids, id)}return ids+ case tag.EdgeChildren:+ ids := make([]ent.Value, 0, len(m.removedchildren))+ for id := range m.removedchildren {+ 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)+ edges := make([]string, 0, 4)if m.clearedgroup {edges = append(edges, tag.EdgeGroup)}if m.cleareditems {edges = append(edges, tag.EdgeItems)}+ if m.clearedparent {+ edges = append(edges, tag.EdgeParent)+ }+ if m.clearedchildren {+ edges = append(edges, tag.EdgeChildren)+ }return edges}@@ -11827,6 +12029,10 @@ func (m *TagMutation) EdgeCleared(name string) bool {return m.clearedgroupcase tag.EdgeItems:return m.cleareditems+ case tag.EdgeParent:+ return m.clearedparent+ case tag.EdgeChildren:+ return m.clearedchildren}return false}@@ -11838,6 +12044,9 @@ func (m *TagMutation) ClearEdge(name string) error {case tag.EdgeGroup:m.ClearGroup()return nil+ case tag.EdgeParent:+ m.ClearParent()+ return nil}return fmt.Errorf("unknown Tag unique edge %s", name)}@@ -11852,6 +12061,12 @@ func (m *TagMutation) ResetEdge(name string) error {case tag.EdgeItems:m.ResetItems()return nil+ case tag.EdgeParent:+ m.ResetParent()+ return nil+ case tag.EdgeChildren:+ m.ResetChildren()+ return nil}return fmt.Errorf("unknown Tag edge %s", name)}diff --git a/backend/internal/data/ent/runtime.go b/backend/internal/data/ent/runtime.goindex eac7edc5..4571f088 100644--- a/backend/internal/data/ent/runtime.go+++ b/backend/internal/data/ent/runtime.go@@ -593,6 +593,10 @@ func init() {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)+ // tagDescIcon is the schema descriptor for icon field.+ tagDescIcon := tagFields[1].Descriptor()+ // tag.IconValidator is a validator for the "icon" field. It is called by the builders before save.+ tag.IconValidator = tagDescIcon.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.diff --git a/backend/internal/data/ent/schema/tag.go b/backend/internal/data/ent/schema/tag.goindex 5853aad0..63cecf19 100644--- a/backend/internal/data/ent/schema/tag.go+++ b/backend/internal/data/ent/schema/tag.go@@ -26,6 +26,9 @@ func (Tag) Fields() []ent.Field {field.String("color").MaxLen(255).Optional(),+ field.String("icon").+ MaxLen(255).+ Optional(),}}@@ -33,5 +36,8 @@ func (Tag) Fields() []ent.Field {func (Tag) Edges() []ent.Edge {return []ent.Edge{edge.To("items", Item.Type),+ edge.To("children", Tag.Type).+ From("parent").+ Unique(),}}diff --git a/backend/internal/data/ent/tag.go b/backend/internal/data/ent/tag.goindex 8be402d1..e641ce45 100644--- a/backend/internal/data/ent/tag.go+++ b/backend/internal/data/ent/tag.go@@ -29,10 +29,13 @@ type Tag struct {Description string `json:"description,omitempty"`// Color holds the value of the "color" field.Color string `json:"color,omitempty"`+ // Icon holds the value of the "icon" field.+ Icon string `json:"icon,omitempty"`// Edges holds the relations/edges for other nodes in the graph.// The values are being populated by the TagQuery when eager-loading is set.Edges TagEdges `json:"edges"`group_tags *uuid.UUID+ tag_children *uuid.UUIDselectValues sql.SelectValues}@@ -42,9 +45,13 @@ type TagEdges struct {Group *Group `json:"group,omitempty"`// Items holds the value of the items edge.Items []*Item `json:"items,omitempty"`+ // Parent holds the value of the parent edge.+ Parent *Tag `json:"parent,omitempty"`+ // Children holds the value of the children edge.+ Children []*Tag `json:"children,omitempty"`// loadedTypes holds the information for reporting if a// type was loaded (or requested) in eager-loading or not.- loadedTypes [2]bool+ loadedTypes [4]bool}// GroupOrErr returns the Group value or an error if the edge@@ -67,12 +74,32 @@ func (e TagEdges) ItemsOrErr() ([]*Item, error) {return nil, &NotLoadedError{edge: "items"}}+// ParentOrErr returns the Parent value or an error if the edge+// was not loaded in eager-loading, or loaded but was not found.+func (e TagEdges) ParentOrErr() (*Tag, error) {+ if e.Parent != nil {+ return e.Parent, nil+ } else if e.loadedTypes[2] {+ return nil, &NotFoundError{label: tag.Label}+ }+ return nil, &NotLoadedError{edge: "parent"}+}++// ChildrenOrErr returns the Children value or an error if the edge+// was not loaded in eager-loading.+func (e TagEdges) ChildrenOrErr() ([]*Tag, error) {+ if e.loadedTypes[3] {+ return e.Children, nil+ }+ return nil, &NotLoadedError{edge: "children"}+}+// scanValues returns the types for scanning values from sql.Rows.func (*Tag) scanValues(columns []string) ([]any, error) {values := make([]any, len(columns))for i := range columns {switch columns[i] {- case tag.FieldName, tag.FieldDescription, tag.FieldColor:+ case tag.FieldName, tag.FieldDescription, tag.FieldColor, tag.FieldIcon:values[i] = new(sql.NullString)case tag.FieldCreatedAt, tag.FieldUpdatedAt:values[i] = new(sql.NullTime)@@ -80,6 +107,8 @@ func (*Tag) scanValues(columns []string) ([]any, error) {values[i] = new(uuid.UUID)case tag.ForeignKeys[0]: // group_tagsvalues[i] = &sql.NullScanner{S: new(uuid.UUID)}+ case tag.ForeignKeys[1]: // tag_children+ values[i] = &sql.NullScanner{S: new(uuid.UUID)}default:values[i] = new(sql.UnknownType)}@@ -131,6 +160,12 @@ func (_m *Tag) assignValues(columns []string, values []any) error {} else if value.Valid {_m.Color = value.String}+ case tag.FieldIcon:+ if value, ok := values[i].(*sql.NullString); !ok {+ return fmt.Errorf("unexpected type %T for field icon", values[i])+ } else if value.Valid {+ _m.Icon = value.String+ }case tag.ForeignKeys[0]:if value, ok := values[i].(*sql.NullScanner); !ok {return fmt.Errorf("unexpected type %T for field group_tags", values[i])@@ -138,6 +173,13 @@ func (_m *Tag) assignValues(columns []string, values []any) error {_m.group_tags = new(uuid.UUID)*_m.group_tags = *value.S.(*uuid.UUID)}+ case tag.ForeignKeys[1]:+ if value, ok := values[i].(*sql.NullScanner); !ok {+ return fmt.Errorf("unexpected type %T for field tag_children", values[i])+ } else if value.Valid {+ _m.tag_children = new(uuid.UUID)+ *_m.tag_children = *value.S.(*uuid.UUID)+ }default:_m.selectValues.Set(columns[i], values[i])}@@ -161,6 +203,16 @@ func (_m *Tag) QueryItems() *ItemQuery {return NewTagClient(_m.config).QueryItems(_m)}+// QueryParent queries the "parent" edge of the Tag entity.+func (_m *Tag) QueryParent() *TagQuery {+ return NewTagClient(_m.config).QueryParent(_m)+}++// QueryChildren queries the "children" edge of the Tag entity.+func (_m *Tag) QueryChildren() *TagQuery {+ return NewTagClient(_m.config).QueryChildren(_m)+}+// 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.@@ -198,6 +250,9 @@ func (_m *Tag) String() string {builder.WriteString(", ")builder.WriteString("color=")builder.WriteString(_m.Color)+ builder.WriteString(", ")+ builder.WriteString("icon=")+ builder.WriteString(_m.Icon)builder.WriteByte(')')return builder.String()}diff --git a/backend/internal/data/ent/tag/tag.go b/backend/internal/data/ent/tag/tag.goindex c6a2a2c6..ef3fa0dc 100644--- a/backend/internal/data/ent/tag/tag.go+++ b/backend/internal/data/ent/tag/tag.go@@ -25,10 +25,16 @@ const (FieldDescription = "description"// FieldColor holds the string denoting the color field in the database.FieldColor = "color"+ // FieldIcon holds the string denoting the icon field in the database.+ FieldIcon = "icon"// EdgeGroup holds the string denoting the group edge name in mutations.EdgeGroup = "group"// EdgeItems holds the string denoting the items edge name in mutations.EdgeItems = "items"+ // EdgeParent holds the string denoting the parent edge name in mutations.+ EdgeParent = "parent"+ // EdgeChildren holds the string denoting the children edge name in mutations.+ EdgeChildren = "children"// Table holds the table name of the tag in the database.Table = "tags"// GroupTable is the table that holds the group relation/edge.@@ -43,6 +49,14 @@ const (// 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"+ // ParentTable is the table that holds the parent relation/edge.+ ParentTable = "tags"+ // ParentColumn is the table column denoting the parent relation/edge.+ ParentColumn = "tag_children"+ // ChildrenTable is the table that holds the children relation/edge.+ ChildrenTable = "tags"+ // ChildrenColumn is the table column denoting the children relation/edge.+ ChildrenColumn = "tag_children")// Columns holds all SQL columns for tag fields.@@ -53,12 +67,14 @@ var Columns = []string{FieldName,FieldDescription,FieldColor,+ FieldIcon,}// 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_tags",+ "tag_children",}var (@@ -95,6 +111,8 @@ var (DescriptionValidator func(string) error// ColorValidator is a validator for the "color" field. It is called by the builders before save.ColorValidator func(string) error+ // IconValidator is a validator for the "icon" field. It is called by the builders before save.+ IconValidator func(string) error// DefaultID holds the default value on creation for the "id" field.DefaultID func() uuid.UUID)@@ -132,6 +150,11 @@ func ByColor(opts ...sql.OrderTermOption) OrderOption {return sql.OrderByField(FieldColor, opts...).ToFunc()}+// ByIcon orders the results by the icon field.+func ByIcon(opts ...sql.OrderTermOption) OrderOption {+ return sql.OrderByField(FieldIcon, opts...).ToFunc()+}+// ByGroupField orders the results by group field.func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {return func(s *sql.Selector) {@@ -152,6 +175,27 @@ func ByItems(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {sqlgraph.OrderByNeighborTerms(s, newItemsStep(), append([]sql.OrderTerm{term}, terms...)...)}}++// ByParentField orders the results by parent field.+func ByParentField(field string, opts ...sql.OrderTermOption) OrderOption {+ return func(s *sql.Selector) {+ sqlgraph.OrderByNeighborTerms(s, newParentStep(), sql.OrderByField(field, opts...))+ }+}++// ByChildrenCount orders the results by children count.+func ByChildrenCount(opts ...sql.OrderTermOption) OrderOption {+ return func(s *sql.Selector) {+ sqlgraph.OrderByNeighborsCount(s, newChildrenStep(), opts...)+ }+}++// ByChildren orders the results by children terms.+func ByChildren(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {+ return func(s *sql.Selector) {+ sqlgraph.OrderByNeighborTerms(s, newChildrenStep(), append([]sql.OrderTerm{term}, terms...)...)+ }+}func newGroupStep() *sqlgraph.Step {return sqlgraph.NewStep(sqlgraph.From(Table, FieldID),@@ -166,3 +210,17 @@ func newItemsStep() *sqlgraph.Step {sqlgraph.Edge(sqlgraph.M2M, false, ItemsTable, ItemsPrimaryKey...),)}+func newParentStep() *sqlgraph.Step {+ return sqlgraph.NewStep(+ sqlgraph.From(Table, FieldID),+ sqlgraph.To(Table, FieldID),+ sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn),+ )+}+func newChildrenStep() *sqlgraph.Step {+ return sqlgraph.NewStep(+ sqlgraph.From(Table, FieldID),+ sqlgraph.To(Table, FieldID),+ sqlgraph.Edge(sqlgraph.O2M, false, ChildrenTable, ChildrenColumn),+ )+}diff --git a/backend/internal/data/ent/tag/where.go b/backend/internal/data/ent/tag/where.goindex 775a03a8..dd8c4e88 100644--- a/backend/internal/data/ent/tag/where.go+++ b/backend/internal/data/ent/tag/where.go@@ -81,6 +81,11 @@ func Color(v string) predicate.Tag {return predicate.Tag(sql.FieldEQ(FieldColor, v))}+// Icon applies equality check predicate on the "icon" field. It's identical to IconEQ.+func Icon(v string) predicate.Tag {+ return predicate.Tag(sql.FieldEQ(FieldIcon, 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))@@ -376,6 +381,81 @@ func ColorContainsFold(v string) predicate.Tag {return predicate.Tag(sql.FieldContainsFold(FieldColor, v))}+// IconEQ applies the EQ predicate on the "icon" field.+func IconEQ(v string) predicate.Tag {+ return predicate.Tag(sql.FieldEQ(FieldIcon, v))+}++// IconNEQ applies the NEQ predicate on the "icon" field.+func IconNEQ(v string) predicate.Tag {+ return predicate.Tag(sql.FieldNEQ(FieldIcon, v))+}++// IconIn applies the In predicate on the "icon" field.+func IconIn(vs ...string) predicate.Tag {+ return predicate.Tag(sql.FieldIn(FieldIcon, vs...))+}++// IconNotIn applies the NotIn predicate on the "icon" field.+func IconNotIn(vs ...string) predicate.Tag {+ return predicate.Tag(sql.FieldNotIn(FieldIcon, vs...))+}++// IconGT applies the GT predicate on the "icon" field.+func IconGT(v string) predicate.Tag {+ return predicate.Tag(sql.FieldGT(FieldIcon, v))+}++// IconGTE applies the GTE predicate on the "icon" field.+func IconGTE(v string) predicate.Tag {+ return predicate.Tag(sql.FieldGTE(FieldIcon, v))+}++// IconLT applies the LT predicate on the "icon" field.+func IconLT(v string) predicate.Tag {+ return predicate.Tag(sql.FieldLT(FieldIcon, v))+}++// IconLTE applies the LTE predicate on the "icon" field.+func IconLTE(v string) predicate.Tag {+ return predicate.Tag(sql.FieldLTE(FieldIcon, v))+}++// IconContains applies the Contains predicate on the "icon" field.+func IconContains(v string) predicate.Tag {+ return predicate.Tag(sql.FieldContains(FieldIcon, v))+}++// IconHasPrefix applies the HasPrefix predicate on the "icon" field.+func IconHasPrefix(v string) predicate.Tag {+ return predicate.Tag(sql.FieldHasPrefix(FieldIcon, v))+}++// IconHasSuffix applies the HasSuffix predicate on the "icon" field.+func IconHasSuffix(v string) predicate.Tag {+ return predicate.Tag(sql.FieldHasSuffix(FieldIcon, v))+}++// IconIsNil applies the IsNil predicate on the "icon" field.+func IconIsNil() predicate.Tag {+ return predicate.Tag(sql.FieldIsNull(FieldIcon))+}++// IconNotNil applies the NotNil predicate on the "icon" field.+func IconNotNil() predicate.Tag {+ return predicate.Tag(sql.FieldNotNull(FieldIcon))+}++// IconEqualFold applies the EqualFold predicate on the "icon" field.+func IconEqualFold(v string) predicate.Tag {+ return predicate.Tag(sql.FieldEqualFold(FieldIcon, v))+}++// IconContainsFold applies the ContainsFold predicate on the "icon" field.+func IconContainsFold(v string) predicate.Tag {+ return predicate.Tag(sql.FieldContainsFold(FieldIcon, v))+}+// HasGroup applies the HasEdge predicate on the "group" edge.func HasGroup() predicate.Tag {return predicate.Tag(func(s *sql.Selector) {@@ -422,6 +502,52 @@ func HasItemsWith(preds ...predicate.Item) predicate.Tag {})}+// HasParent applies the HasEdge predicate on the "parent" edge.+func HasParent() predicate.Tag {+ return predicate.Tag(func(s *sql.Selector) {+ step := sqlgraph.NewStep(+ sqlgraph.From(Table, FieldID),+ sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn),+ )+ sqlgraph.HasNeighbors(s, step)+ })+}++// HasParentWith applies the HasEdge predicate on the "parent" edge with a given conditions (other predicates).+func HasParentWith(preds ...predicate.Tag) predicate.Tag {+ return predicate.Tag(func(s *sql.Selector) {+ step := newParentStep()+ sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {+ for _, p := range preds {+ p(s)+ }+ })+ })+}++// HasChildren applies the HasEdge predicate on the "children" edge.+func HasChildren() predicate.Tag {+ return predicate.Tag(func(s *sql.Selector) {+ step := sqlgraph.NewStep(+ sqlgraph.From(Table, FieldID),+ sqlgraph.Edge(sqlgraph.O2M, false, ChildrenTable, ChildrenColumn),+ )+ sqlgraph.HasNeighbors(s, step)+ })+}++// HasChildrenWith applies the HasEdge predicate on the "children" edge with a given conditions (other predicates).+func HasChildrenWith(preds ...predicate.Tag) predicate.Tag {+ return predicate.Tag(func(s *sql.Selector) {+ step := newChildrenStep()+ 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...))diff --git a/backend/internal/data/ent/tag_create.go b/backend/internal/data/ent/tag_create.goindex bac61933..ea256601 100644--- a/backend/internal/data/ent/tag_create.go+++ b/backend/internal/data/ent/tag_create.go@@ -85,6 +85,20 @@ func (_c *TagCreate) SetNillableColor(v *string) *TagCreate {return _c}+// SetIcon sets the "icon" field.+func (_c *TagCreate) SetIcon(v string) *TagCreate {+ _c.mutation.SetIcon(v)+ return _c+}++// SetNillableIcon sets the "icon" field if the given value is not nil.+func (_c *TagCreate) SetNillableIcon(v *string) *TagCreate {+ if v != nil {+ _c.SetIcon(*v)+ }+ return _c+}+// SetID sets the "id" field.func (_c *TagCreate) SetID(v uuid.UUID) *TagCreate {_c.mutation.SetID(v)@@ -125,6 +139,40 @@ func (_c *TagCreate) AddItems(v ...*Item) *TagCreate {return _c.AddItemIDs(ids...)}+// SetParentID sets the "parent" edge to the Tag entity by ID.+func (_c *TagCreate) SetParentID(id uuid.UUID) *TagCreate {+ _c.mutation.SetParentID(id)+ return _c+}++// SetNillableParentID sets the "parent" edge to the Tag entity by ID if the given value is not nil.+func (_c *TagCreate) SetNillableParentID(id *uuid.UUID) *TagCreate {+ if id != nil {+ _c = _c.SetParentID(*id)+ }+ return _c+}++// SetParent sets the "parent" edge to the Tag entity.+func (_c *TagCreate) SetParent(v *Tag) *TagCreate {+ return _c.SetParentID(v.ID)+}++// AddChildIDs adds the "children" edge to the Tag entity by IDs.+func (_c *TagCreate) AddChildIDs(ids ...uuid.UUID) *TagCreate {+ _c.mutation.AddChildIDs(ids...)+ return _c+}++// AddChildren adds the "children" edges to the Tag entity.+func (_c *TagCreate) AddChildren(v ...*Tag) *TagCreate {+ ids := make([]uuid.UUID, len(v))+ for i := range v {+ ids[i] = v[i].ID+ }+ return _c.AddChildIDs(ids...)+}+// Mutation returns the TagMutation object of the builder.func (_c *TagCreate) Mutation() *TagMutation {return _c.mutation@@ -200,6 +248,11 @@ func (_c *TagCreate) check() error {return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Tag.color": %w`, err)}}}+ if v, ok := _c.mutation.Icon(); ok {+ if err := tag.IconValidator(v); err != nil {+ return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Tag.icon": %w`, err)}+ }+ }if len(_c.mutation.GroupIDs()) == 0 {return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Tag.group"`)}}@@ -258,6 +311,10 @@ func (_c *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) {_spec.SetField(tag.FieldColor, field.TypeString, value)_node.Color = value}+ if value, ok := _c.mutation.Icon(); ok {+ _spec.SetField(tag.FieldIcon, field.TypeString, value)+ _node.Icon = value+ }if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 {edge := &sqlgraph.EdgeSpec{Rel: sqlgraph.M2O,@@ -291,6 +348,39 @@ func (_c *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) {}_spec.Edges = append(_spec.Edges, edge)}+ if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.M2O,+ Inverse: true,+ Table: tag.ParentTable,+ Columns: []string{tag.ParentColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _node.tag_children = &nodes[0]+ _spec.Edges = append(_spec.Edges, edge)+ }+ if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.O2M,+ Inverse: false,+ Table: tag.ChildrenTable,+ Columns: []string{tag.ChildrenColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _spec.Edges = append(_spec.Edges, edge)+ }return _node, _spec}diff --git a/backend/internal/data/ent/tag_query.go b/backend/internal/data/ent/tag_query.goindex efa7ada3..27c7c58e 100644--- a/backend/internal/data/ent/tag_query.go+++ b/backend/internal/data/ent/tag_query.go@@ -22,13 +22,15 @@ import (// TagQuery is the builder for querying Tag entities.type TagQuery struct {config- ctx *QueryContext- order []tag.OrderOption- inters []Interceptor- predicates []predicate.Tag- withGroup *GroupQuery- withItems *ItemQuery- withFKs bool+ ctx *QueryContext+ order []tag.OrderOption+ inters []Interceptor+ predicates []predicate.Tag+ withGroup *GroupQuery+ withItems *ItemQuery+ withParent *TagQuery+ withChildren *TagQuery+ withFKs bool// intermediate query (i.e. traversal path).sql *sql.Selectorpath func(context.Context) (*sql.Selector, error)@@ -109,6 +111,50 @@ func (_q *TagQuery) QueryItems() *ItemQuery {return query}+// QueryParent chains the current query on the "parent" edge.+func (_q *TagQuery) QueryParent() *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+ }+ selector := _q.sqlQuery(ctx)+ if err := selector.Err(); err != nil {+ return nil, err+ }+ step := sqlgraph.NewStep(+ sqlgraph.From(tag.Table, tag.FieldID, selector),+ sqlgraph.To(tag.Table, tag.FieldID),+ sqlgraph.Edge(sqlgraph.M2O, true, tag.ParentTable, tag.ParentColumn),+ )+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)+ return fromU, nil+ }+ return query+}++// QueryChildren chains the current query on the "children" edge.+func (_q *TagQuery) QueryChildren() *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+ }+ selector := _q.sqlQuery(ctx)+ if err := selector.Err(); err != nil {+ return nil, err+ }+ step := sqlgraph.NewStep(+ sqlgraph.From(tag.Table, tag.FieldID, selector),+ sqlgraph.To(tag.Table, tag.FieldID),+ sqlgraph.Edge(sqlgraph.O2M, false, tag.ChildrenTable, tag.ChildrenColumn),+ )+ fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)+ return fromU, nil+ }+ return query+}+// 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) {@@ -296,13 +342,15 @@ func (_q *TagQuery) Clone() *TagQuery {return nil}return &TagQuery{- config: _q.config,- ctx: _q.ctx.Clone(),- order: append([]tag.OrderOption{}, _q.order...),- inters: append([]Interceptor{}, _q.inters...),- predicates: append([]predicate.Tag{}, _q.predicates...),- withGroup: _q.withGroup.Clone(),- withItems: _q.withItems.Clone(),+ config: _q.config,+ ctx: _q.ctx.Clone(),+ order: append([]tag.OrderOption{}, _q.order...),+ inters: append([]Interceptor{}, _q.inters...),+ predicates: append([]predicate.Tag{}, _q.predicates...),+ withGroup: _q.withGroup.Clone(),+ withItems: _q.withItems.Clone(),+ withParent: _q.withParent.Clone(),+ withChildren: _q.withChildren.Clone(),// clone intermediate query.sql: _q.sql.Clone(),path: _q.path,@@ -331,6 +379,28 @@ func (_q *TagQuery) WithItems(opts ...func(*ItemQuery)) *TagQuery {return _q}+// WithParent tells the query-builder to eager-load the nodes that are connected to+// the "parent" edge. The optional arguments are used to configure the query builder of the edge.+func (_q *TagQuery) WithParent(opts ...func(*TagQuery)) *TagQuery {+ query := (&TagClient{config: _q.config}).Query()+ for _, opt := range opts {+ opt(query)+ }+ _q.withParent = query+ return _q+}++// WithChildren tells the query-builder to eager-load the nodes that are connected to+// the "children" edge. The optional arguments are used to configure the query builder of the edge.+func (_q *TagQuery) WithChildren(opts ...func(*TagQuery)) *TagQuery {+ query := (&TagClient{config: _q.config}).Query()+ for _, opt := range opts {+ opt(query)+ }+ _q.withChildren = query+ return _q+}+// GroupBy is used to group vertices by one or more fields/columns.// It is often used with aggregate functions, like: count, max, mean, min, sum.//@@ -410,12 +480,14 @@ func (_q *TagQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Tag, errnodes = []*Tag{}withFKs = _q.withFKs_spec = _q.querySpec()- loadedTypes = [2]bool{+ loadedTypes = [4]bool{_q.withGroup != nil,_q.withItems != nil,+ _q.withParent != nil,+ _q.withChildren != nil,})- if _q.withGroup != nil {+ if _q.withGroup != nil || _q.withParent != nil {withFKs = true}if withFKs {@@ -452,6 +524,19 @@ func (_q *TagQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Tag, errreturn nil, err}}+ if query := _q.withParent; query != nil {+ if err := _q.loadParent(ctx, query, nodes, nil,+ func(n *Tag, e *Tag) { n.Edges.Parent = e }); err != nil {+ return nil, err+ }+ }+ if query := _q.withChildren; query != nil {+ if err := _q.loadChildren(ctx, query, nodes,+ func(n *Tag) { n.Edges.Children = []*Tag{} },+ func(n *Tag, e *Tag) { n.Edges.Children = append(n.Edges.Children, e) }); err != nil {+ return nil, err+ }+ }return nodes, nil}@@ -548,6 +633,69 @@ func (_q *TagQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []*Ta}return nil}+func (_q *TagQuery) loadParent(ctx context.Context, query *TagQuery, nodes []*Tag, init func(*Tag), assign func(*Tag, *Tag)) error {+ ids := make([]uuid.UUID, 0, len(nodes))+ nodeids := make(map[uuid.UUID][]*Tag)+ for i := range nodes {+ if nodes[i].tag_children == nil {+ continue+ }+ fk := *nodes[i].tag_children+ if _, ok := nodeids[fk]; !ok {+ ids = append(ids, fk)+ }+ nodeids[fk] = append(nodeids[fk], nodes[i])+ }+ if len(ids) == 0 {+ return nil+ }+ query.Where(tag.IDIn(ids...))+ neighbors, err := query.All(ctx)+ if err != nil {+ return err+ }+ for _, n := range neighbors {+ nodes, ok := nodeids[n.ID]+ if !ok {+ return fmt.Errorf(`unexpected foreign-key "tag_children" returned %v`, n.ID)+ }+ for i := range nodes {+ assign(nodes[i], n)+ }+ }+ return nil+}+func (_q *TagQuery) loadChildren(ctx context.Context, query *TagQuery, nodes []*Tag, init func(*Tag), assign func(*Tag, *Tag)) error {+ fks := make([]driver.Value, 0, len(nodes))+ nodeids := make(map[uuid.UUID]*Tag)+ for i := range nodes {+ fks = append(fks, nodes[i].ID)+ nodeids[nodes[i].ID] = nodes[i]+ if init != nil {+ init(nodes[i])+ }+ }+ query.withFKs = true+ query.Where(predicate.Tag(func(s *sql.Selector) {+ s.Where(sql.InValues(s.C(tag.ChildrenColumn), fks...))+ }))+ neighbors, err := query.All(ctx)+ if err != nil {+ return err+ }+ for _, n := range neighbors {+ fk := n.tag_children+ if fk == nil {+ return fmt.Errorf(`foreign-key "tag_children" is nil for node %v`, n.ID)+ }+ node, ok := nodeids[*fk]+ if !ok {+ return fmt.Errorf(`unexpected referenced foreign-key "tag_children" returned %v for node %v`, *fk, n.ID)+ }+ assign(node, n)+ }+ return nil+}func (_q *TagQuery) sqlCount(ctx context.Context) (int, error) {_spec := _q.querySpec()diff --git a/backend/internal/data/ent/tag_update.go b/backend/internal/data/ent/tag_update.goindex 51879f59..211f08a7 100644--- a/backend/internal/data/ent/tag_update.go+++ b/backend/internal/data/ent/tag_update.go@@ -91,6 +91,26 @@ func (_u *TagUpdate) ClearColor() *TagUpdate {return _u}+// SetIcon sets the "icon" field.+func (_u *TagUpdate) SetIcon(v string) *TagUpdate {+ _u.mutation.SetIcon(v)+ return _u+}++// SetNillableIcon sets the "icon" field if the given value is not nil.+func (_u *TagUpdate) SetNillableIcon(v *string) *TagUpdate {+ if v != nil {+ _u.SetIcon(*v)+ }+ return _u+}++// ClearIcon clears the value of the "icon" field.+func (_u *TagUpdate) ClearIcon() *TagUpdate {+ _u.mutation.ClearIcon()+ return _u+}+// SetGroupID sets the "group" edge to the Group entity by ID.func (_u *TagUpdate) SetGroupID(id uuid.UUID) *TagUpdate {_u.mutation.SetGroupID(id)@@ -117,6 +137,40 @@ func (_u *TagUpdate) AddItems(v ...*Item) *TagUpdate {return _u.AddItemIDs(ids...)}+// SetParentID sets the "parent" edge to the Tag entity by ID.+func (_u *TagUpdate) SetParentID(id uuid.UUID) *TagUpdate {+ _u.mutation.SetParentID(id)+ return _u+}++// SetNillableParentID sets the "parent" edge to the Tag entity by ID if the given value is not nil.+func (_u *TagUpdate) SetNillableParentID(id *uuid.UUID) *TagUpdate {+ if id != nil {+ _u = _u.SetParentID(*id)+ }+ return _u+}++// SetParent sets the "parent" edge to the Tag entity.+func (_u *TagUpdate) SetParent(v *Tag) *TagUpdate {+ return _u.SetParentID(v.ID)+}++// AddChildIDs adds the "children" edge to the Tag entity by IDs.+func (_u *TagUpdate) AddChildIDs(ids ...uuid.UUID) *TagUpdate {+ _u.mutation.AddChildIDs(ids...)+ return _u+}++// AddChildren adds the "children" edges to the Tag entity.+func (_u *TagUpdate) AddChildren(v ...*Tag) *TagUpdate {+ ids := make([]uuid.UUID, len(v))+ for i := range v {+ ids[i] = v[i].ID+ }+ return _u.AddChildIDs(ids...)+}+// Mutation returns the TagMutation object of the builder.func (_u *TagUpdate) Mutation() *TagMutation {return _u.mutation@@ -149,6 +203,33 @@ func (_u *TagUpdate) RemoveItems(v ...*Item) *TagUpdate {return _u.RemoveItemIDs(ids...)}+// ClearParent clears the "parent" edge to the Tag entity.+func (_u *TagUpdate) ClearParent() *TagUpdate {+ _u.mutation.ClearParent()+ return _u+}++// ClearChildren clears all "children" edges to the Tag entity.+func (_u *TagUpdate) ClearChildren() *TagUpdate {+ _u.mutation.ClearChildren()+ return _u+}++// RemoveChildIDs removes the "children" edge to Tag entities by IDs.+func (_u *TagUpdate) RemoveChildIDs(ids ...uuid.UUID) *TagUpdate {+ _u.mutation.RemoveChildIDs(ids...)+ return _u+}++// RemoveChildren removes "children" edges to Tag entities.+func (_u *TagUpdate) RemoveChildren(v ...*Tag) *TagUpdate {+ ids := make([]uuid.UUID, len(v))+ for i := range v {+ ids[i] = v[i].ID+ }+ return _u.RemoveChildIDs(ids...)+}+// Save executes the query and returns the number of nodes affected by the update operation.func (_u *TagUpdate) Save(ctx context.Context) (int, error) {_u.defaults()@@ -202,6 +283,11 @@ func (_u *TagUpdate) check() error {return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Tag.color": %w`, err)}}}+ if v, ok := _u.mutation.Icon(); ok {+ if err := tag.IconValidator(v); err != nil {+ return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Tag.icon": %w`, err)}+ }+ }if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {return errors.New(`ent: clearing a required unique edge "Tag.group"`)}@@ -238,6 +324,12 @@ func (_u *TagUpdate) sqlSave(ctx context.Context) (_node int, err error) {if _u.mutation.ColorCleared() {_spec.ClearField(tag.FieldColor, field.TypeString)}+ if value, ok := _u.mutation.Icon(); ok {+ _spec.SetField(tag.FieldIcon, field.TypeString, value)+ }+ if _u.mutation.IconCleared() {+ _spec.ClearField(tag.FieldIcon, field.TypeString)+ }if _u.mutation.GroupCleared() {edge := &sqlgraph.EdgeSpec{Rel: sqlgraph.M2O,@@ -312,6 +404,80 @@ func (_u *TagUpdate) sqlSave(ctx context.Context) (_node int, err error) {}_spec.Edges.Add = append(_spec.Edges.Add, edge)}+ if _u.mutation.ParentCleared() {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.M2O,+ Inverse: true,+ Table: tag.ParentTable,+ Columns: []string{tag.ParentColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)+ }+ if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.M2O,+ Inverse: true,+ Table: tag.ParentTable,+ Columns: []string{tag.ParentColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _spec.Edges.Add = append(_spec.Edges.Add, edge)+ }+ if _u.mutation.ChildrenCleared() {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.O2M,+ Inverse: false,+ Table: tag.ChildrenTable,+ Columns: []string{tag.ChildrenColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)+ }+ if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.O2M,+ Inverse: false,+ Table: tag.ChildrenTable,+ Columns: []string{tag.ChildrenColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)+ }+ if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.O2M,+ Inverse: false,+ Table: tag.ChildrenTable,+ Columns: []string{tag.ChildrenColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _spec.Edges.Add = append(_spec.Edges.Add, edge)+ }if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {if _, ok := err.(*sqlgraph.NotFoundError); ok {err = &NotFoundError{tag.Label}@@ -392,6 +558,26 @@ func (_u *TagUpdateOne) ClearColor() *TagUpdateOne {return _u}+// SetIcon sets the "icon" field.+func (_u *TagUpdateOne) SetIcon(v string) *TagUpdateOne {+ _u.mutation.SetIcon(v)+ return _u+}++// SetNillableIcon sets the "icon" field if the given value is not nil.+func (_u *TagUpdateOne) SetNillableIcon(v *string) *TagUpdateOne {+ if v != nil {+ _u.SetIcon(*v)+ }+ return _u+}++// ClearIcon clears the value of the "icon" field.+func (_u *TagUpdateOne) ClearIcon() *TagUpdateOne {+ _u.mutation.ClearIcon()+ return _u+}+// SetGroupID sets the "group" edge to the Group entity by ID.func (_u *TagUpdateOne) SetGroupID(id uuid.UUID) *TagUpdateOne {_u.mutation.SetGroupID(id)@@ -418,6 +604,40 @@ func (_u *TagUpdateOne) AddItems(v ...*Item) *TagUpdateOne {return _u.AddItemIDs(ids...)}+// SetParentID sets the "parent" edge to the Tag entity by ID.+func (_u *TagUpdateOne) SetParentID(id uuid.UUID) *TagUpdateOne {+ _u.mutation.SetParentID(id)+ return _u+}++// SetNillableParentID sets the "parent" edge to the Tag entity by ID if the given value is not nil.+func (_u *TagUpdateOne) SetNillableParentID(id *uuid.UUID) *TagUpdateOne {+ if id != nil {+ _u = _u.SetParentID(*id)+ }+ return _u+}++// SetParent sets the "parent" edge to the Tag entity.+func (_u *TagUpdateOne) SetParent(v *Tag) *TagUpdateOne {+ return _u.SetParentID(v.ID)+}++// AddChildIDs adds the "children" edge to the Tag entity by IDs.+func (_u *TagUpdateOne) AddChildIDs(ids ...uuid.UUID) *TagUpdateOne {+ _u.mutation.AddChildIDs(ids...)+ return _u+}++// AddChildren adds the "children" edges to the Tag entity.+func (_u *TagUpdateOne) AddChildren(v ...*Tag) *TagUpdateOne {+ ids := make([]uuid.UUID, len(v))+ for i := range v {+ ids[i] = v[i].ID+ }+ return _u.AddChildIDs(ids...)+}+// Mutation returns the TagMutation object of the builder.func (_u *TagUpdateOne) Mutation() *TagMutation {return _u.mutation@@ -450,6 +670,33 @@ func (_u *TagUpdateOne) RemoveItems(v ...*Item) *TagUpdateOne {return _u.RemoveItemIDs(ids...)}+// ClearParent clears the "parent" edge to the Tag entity.+func (_u *TagUpdateOne) ClearParent() *TagUpdateOne {+ _u.mutation.ClearParent()+ return _u+}++// ClearChildren clears all "children" edges to the Tag entity.+func (_u *TagUpdateOne) ClearChildren() *TagUpdateOne {+ _u.mutation.ClearChildren()+ return _u+}++// RemoveChildIDs removes the "children" edge to Tag entities by IDs.+func (_u *TagUpdateOne) RemoveChildIDs(ids ...uuid.UUID) *TagUpdateOne {+ _u.mutation.RemoveChildIDs(ids...)+ return _u+}++// RemoveChildren removes "children" edges to Tag entities.+func (_u *TagUpdateOne) RemoveChildren(v ...*Tag) *TagUpdateOne {+ ids := make([]uuid.UUID, len(v))+ for i := range v {+ ids[i] = v[i].ID+ }+ return _u.RemoveChildIDs(ids...)+}+// Where appends a list predicates to the TagUpdate builder.func (_u *TagUpdateOne) Where(ps ...predicate.Tag) *TagUpdateOne {_u.mutation.Where(ps...)@@ -516,6 +763,11 @@ func (_u *TagUpdateOne) check() error {return &ValidationError{Name: "color", err: fmt.Errorf(`ent: validator failed for field "Tag.color": %w`, err)}}}+ if v, ok := _u.mutation.Icon(); ok {+ if err := tag.IconValidator(v); err != nil {+ return &ValidationError{Name: "icon", err: fmt.Errorf(`ent: validator failed for field "Tag.icon": %w`, err)}+ }+ }if _u.mutation.GroupCleared() && len(_u.mutation.GroupIDs()) > 0 {return errors.New(`ent: clearing a required unique edge "Tag.group"`)}@@ -569,6 +821,12 @@ func (_u *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) {if _u.mutation.ColorCleared() {_spec.ClearField(tag.FieldColor, field.TypeString)}+ if value, ok := _u.mutation.Icon(); ok {+ _spec.SetField(tag.FieldIcon, field.TypeString, value)+ }+ if _u.mutation.IconCleared() {+ _spec.ClearField(tag.FieldIcon, field.TypeString)+ }if _u.mutation.GroupCleared() {edge := &sqlgraph.EdgeSpec{Rel: sqlgraph.M2O,@@ -643,6 +901,80 @@ func (_u *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) {}_spec.Edges.Add = append(_spec.Edges.Add, edge)}+ if _u.mutation.ParentCleared() {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.M2O,+ Inverse: true,+ Table: tag.ParentTable,+ Columns: []string{tag.ParentColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)+ }+ if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.M2O,+ Inverse: true,+ Table: tag.ParentTable,+ Columns: []string{tag.ParentColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _spec.Edges.Add = append(_spec.Edges.Add, edge)+ }+ if _u.mutation.ChildrenCleared() {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.O2M,+ Inverse: false,+ Table: tag.ChildrenTable,+ Columns: []string{tag.ChildrenColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)+ }+ if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.O2M,+ Inverse: false,+ Table: tag.ChildrenTable,+ Columns: []string{tag.ChildrenColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _spec.Edges.Clear = append(_spec.Edges.Clear, edge)+ }+ if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {+ edge := &sqlgraph.EdgeSpec{+ Rel: sqlgraph.O2M,+ Inverse: false,+ Table: tag.ChildrenTable,+ Columns: []string{tag.ChildrenColumn},+ Bidi: false,+ Target: &sqlgraph.EdgeTarget{+ IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID),+ },+ }+ for _, k := range nodes {+ edge.Target.Nodes = append(edge.Target.Nodes, k)+ }+ _spec.Edges.Add = append(_spec.Edges.Add, edge)+ }_node = &Tag{config: _u.config}_spec.Assign = _node.assignValues_spec.ScanValues = _node.scanValuesdiff --git a/backend/internal/data/migrations/postgres/20260215000000_add_tag_children.sql b/backend/internal/data/migrations/postgres/20260215000000_add_tag_children.sqlnew file mode 100644index 00000000..7c62a4e2--- /dev/null+++ b/backend/internal/data/migrations/postgres/20260215000000_add_tag_children.sql@@ -0,0 +1,4 @@+-- +goose Up+ALTER TABLE tags ADD COLUMN icon varchar(255) NULL;+ALTER TABLE tags ADD COLUMN tag_children uuid REFERENCES tags(id) ON DELETE SET NULL;+diff --git a/backend/internal/data/migrations/sqlite3/20260215000000_add_tag_children.sql b/backend/internal/data/migrations/sqlite3/20260215000000_add_tag_children.sqlnew file mode 100644index 00000000..e5af277e--- /dev/null+++ b/backend/internal/data/migrations/sqlite3/20260215000000_add_tag_children.sql@@ -0,0 +1,3 @@+-- +goose Up+ALTER TABLE tags ADD COLUMN icon varchar(255) NULL;+ALTER TABLE tags ADD COLUMN tag_children uuid REFERENCES tags(id) ON DELETE SET NULL;diff --git a/backend/internal/data/repo/repo_labels.go b/backend/internal/data/repo/repo_labels.godeleted file mode 100644index 450110cc..00000000--- a/backend/internal/data/repo/repo_labels.go+++ /dev/null@@ -1,159 +0,0 @@-package repo--import (- "context"- "time"-- "github.com/google/uuid"- "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/predicate"- "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag"-)--type TagRepository struct {- db *ent.Client- bus *eventbus.EventBus-}--type (- TagCreate struct {- Name string `json:"name" validate:"required,min=1,max=255"`- Description string `json:"description" validate:"max=1000"`- Color string `json:"color"`- }-- 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"`- }-- TagSummary struct {- ID uuid.UUID `json:"id"`- Name string `json:"name"`- Description string `json:"description"`- Color string `json:"color"`- CreatedAt time.Time `json:"createdAt"`- UpdatedAt time.Time `json:"updatedAt"`- }-- TagOut struct {- TagSummary- }-)--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 (- mapTagOutErr = mapTErrFunc(mapTagOut)- mapTagsOut = mapTEachErrFunc(mapTagSummary)-)--func mapTagOut(tag *ent.Tag) TagOut {- return TagOut{- TagSummary: mapTagSummary(tag),- }-}--func (r *TagRepository) publishMutationEvent(gid uuid.UUID) {- if r.bus != nil {- r.bus.Publish(eventbus.EventTagMutation, eventbus.GroupMutationEvent{GID: gid})- }-}--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 *TagRepository) GetOne(ctx context.Context, id uuid.UUID) (TagOut, error) {- return r.getOne(ctx, tag.ID(id))-}--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 *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 *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 TagOut{}, err- }-- tag.Edges.Group = &ent.Group{ID: groupID} // bootstrap group ID- r.publishMutationEvent(groupID)- return mapTagOut(tag), err-}--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.Tag.Update().- Where(where...).- SetName(data.Name).- SetDescription(data.Description).- SetColor(data.Color).- Save(ctx)-}--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 TagOut{}, err- }-- r.publishMutationEvent(gid)- return r.GetOne(ctx, data.ID)-}--// 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 *TagRepository) DeleteByGroup(ctx context.Context, gid, id uuid.UUID) error {- _, err := r.db.Tag.Delete().- Where(- tag.ID(id),- tag.HasGroupWith(group.ID(gid)),- ).Exec(ctx)- if err != nil {- return err- }-- r.publishMutationEvent(gid)-- return nil-}diff --git a/backend/internal/data/repo/repo_labels_test.go b/backend/internal/data/repo/repo_labels_test.godeleted file mode 100644index 4b5a400c..00000000--- a/backend/internal/data/repo/repo_labels_test.go+++ /dev/null@@ -1,103 +0,0 @@-package repo--import (- "context"- "testing"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"-)--func tagFactory() TagCreate {- return TagCreate{- Name: fk.Str(10),- Description: fk.Str(100),- }-}--func useTags(t *testing.T, len int) []TagOut {- t.Helper()-- tags := make([]TagOut, len)- for i := 0; i < len; i++ {- itm := tagFactory()-- item, err := tRepos.Tags.Create(context.Background(), tGroup.ID, itm)- require.NoError(t, err)- tags[i] = item- }-- t.Cleanup(func() {- for _, item := range tags {- _ = tRepos.Tags.delete(context.Background(), item.ID)- }- })-- return tags-}--func TestTagRepository_Get(t *testing.T) {- tags := useTags(t, 1)- tag := tags[0]-- // Get by ID- foundLoc, err := tRepos.Tags.GetOne(context.Background(), tag.ID)- require.NoError(t, err)- assert.Equal(t, tag.ID, foundLoc.ID)-}--func TestTagRepositoryGetAll(t *testing.T) {- useTags(t, 10)-- all, err := tRepos.Tags.GetAll(context.Background(), tGroup.ID)- require.NoError(t, err)- assert.Len(t, all, 10)-}--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.Tags.GetOne(context.Background(), loc.ID)- require.NoError(t, err)- assert.Equal(t, loc.ID, foundLoc.ID)-- err = tRepos.Tags.delete(context.Background(), loc.ID)- require.NoError(t, err)-}--func TestTagsRepository_Update(t *testing.T) {- loc, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())- require.NoError(t, err)-- updateData := TagUpdate{- ID: loc.ID,- Name: fk.Str(10),- Description: fk.Str(100),- }-- update, err := tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateData)- require.NoError(t, err)-- 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.Tags.delete(context.Background(), loc.ID)- require.NoError(t, err)-}--func TestTagRepository_Delete(t *testing.T) {- loc, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())- require.NoError(t, err)-- err = tRepos.Tags.delete(context.Background(), loc.ID)- require.NoError(t, err)-- _, err = tRepos.Tags.GetOne(context.Background(), loc.ID)- require.Error(t, err)-}diff --git a/backend/internal/data/repo/repo_tags.go b/backend/internal/data/repo/repo_tags.gonew file mode 100644index 00000000..0c21f2a6--- /dev/null+++ b/backend/internal/data/repo/repo_tags.go@@ -0,0 +1,350 @@+package repo++import (+ "context"+ "fmt"+ "time"++ "github.com/google/uuid"+ "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/predicate"+ "github.com/sysadminsmedia/homebox/backend/internal/data/ent/tag"+)++type TagRepository struct {+ db *ent.Client+ bus *eventbus.EventBus+}++type (+ TagCreate struct {+ Name string `json:"name" validate:"required,min=1,max=255"`+ ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`+ Description string `json:"description" validate:"max=1000"`+ Color string `json:"color"`+ Icon string `json:"icon" validate:"max=255"`+ }++ TagUpdate struct {+ ID uuid.UUID `json:"id"`+ ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`+ Name string `json:"name" validate:"required,min=1,max=255"`+ Description string `json:"description" validate:"max=1000"`+ Color string `json:"color"`+ Icon string `json:"icon" validate:"max=255"`+ }++ TagSummary struct {+ ID uuid.UUID `json:"id"`+ ParentID uuid.UUID `json:"parentId" extensions:"x-nullable"`+ Name string `json:"name"`+ Description string `json:"description"`+ Color string `json:"color"`+ Icon string `json:"icon"`+ CreatedAt time.Time `json:"createdAt"`+ UpdatedAt time.Time `json:"updatedAt"`+ }++ TagOut struct {+ TagSummary+ Parent *TagSummary `json:"parent,omitempty"`+ Children []TagSummary `json:"children"`+ }+)++func mapTagSummary(tag *ent.Tag) TagSummary {+ var parentID uuid.UUID+ if tag.Edges.Parent != nil {+ parentID = tag.Edges.Parent.ID+ }++ return TagSummary{+ ID: tag.ID,+ ParentID: parentID,+ Name: tag.Name,+ Description: tag.Description,+ Color: tag.Color,+ Icon: tag.Icon,+ CreatedAt: tag.CreatedAt,+ UpdatedAt: tag.UpdatedAt,+ }+}++var (+ mapTagOutErr = mapTErrFunc(mapTagOut)+ mapTagsOut = mapTEachErrFunc(mapTagSummary)+)++func mapTagOut(tag *ent.Tag) TagOut {+ var parent *TagSummary+ if tag.Edges.Parent != nil {+ p := mapTagSummary(tag.Edges.Parent)+ parent = &p+ }++ children := make([]TagSummary, 0)+ if tag.Edges.Children != nil {+ for _, c := range tag.Edges.Children {+ children = append(children, mapTagSummary(c))+ }+ }++ return TagOut{+ TagSummary: mapTagSummary(tag),+ Parent: parent,+ Children: children,+ }+}++func (r *TagRepository) publishMutationEvent(gid uuid.UUID) {+ if r.bus != nil {+ r.bus.Publish(eventbus.EventTagMutation, eventbus.GroupMutationEvent{GID: gid})+ }+}++func (r *TagRepository) getOne(ctx context.Context, where ...predicate.Tag) (TagOut, error) {+ return mapTagOutErr(r.db.Tag.Query().+ Where(where...).+ WithGroup().+ WithParent().+ WithChildren().+ Only(ctx),+ )+}++func (r *TagRepository) GetOne(ctx context.Context, id uuid.UUID) (TagOut, error) {+ return r.getOne(ctx, tag.ID(id))+}++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 *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().+ WithParent().+ All(ctx),+ )+}++func (r *TagRepository) getSubtreeDepth(ctx context.Context, id uuid.UUID) (int, error) {+ query := `+ WITH RECURSIVE tag_tree(id, depth) AS (+ SELECT id, 1 as depth+ FROM tags+ WHERE id = $1+ UNION ALL+ SELECT t.id, tt.depth + 1+ FROM tags t+ JOIN tag_tree tt ON t.tag_children = tt.id+ )+ SELECT MAX(depth) FROM tag_tree;+ `+ // Since we want the depth of the subtree *relative to the root*,+ // the query above calculates depth from root (1) downwards.+ // The MAX(depth) will be the height of the tree rooted at 'id'.++ rows, err := r.db.Sql().QueryContext(ctx, query, id)+ if err != nil {+ return 0, err+ }+ defer func() { _ = rows.Close() }()++ if rows.Next() {+ var maxDepth int+ if err := rows.Scan(&maxDepth); err != nil {+ return 0, err+ }+ return maxDepth, nil+ }+ return 0, nil+}++func (r *TagRepository) checkDepth(ctx context.Context, parentID uuid.UUID) (int, error) {+ if parentID == uuid.Nil {+ return 0, nil+ }++ query := `+ WITH RECURSIVE tag_parents(id, parent_id, depth) AS (+ SELECT id, tag_children, 1+ FROM tags+ WHERE id = $1+ UNION ALL+ SELECT t.id, t.tag_children, tp.depth + 1+ FROM tags t+ JOIN tag_parents tp ON t.id = tp.parent_id+ )+ SELECT MAX(depth) FROM tag_parents;+ `+ rows, err := r.db.Sql().QueryContext(ctx, query, parentID)+ if err != nil {+ return 0, err+ }+ defer func() { _ = rows.Close() }()++ if rows.Next() {+ var depth int+ if err := rows.Scan(&depth); err != nil {+ return 0, err+ }+ return depth, nil+ }++ return 0, nil+}++// checkCycle checks if targetID is an ancestor of startID.+// This is used when moving startID to be a child of targetID.+// If targetID is already a child/descendant of startID, then making startID a child of targetID creates a cycle.+func (r *TagRepository) checkCycle(ctx context.Context, movingID, proposedParentID uuid.UUID) (bool, error) {+ if movingID == proposedParentID {+ return true, nil+ }++ query := `+ WITH RECURSIVE ancestors(id, parent_id) AS (+ SELECT id, tag_children+ FROM tags+ WHERE id = $1+ UNION ALL+ SELECT t.id, t.tag_children+ FROM tags t+ JOIN ancestors a ON t.id = a.parent_id+ )+ SELECT 1 FROM ancestors WHERE id = $2 LIMIT 1;+ `++ rows, err := r.db.Sql().QueryContext(ctx, query, proposedParentID, movingID)+ if err != nil {+ return false, err+ }+ defer func() { _ = rows.Close() }()++ if rows.Next() {+ return true, nil+ }+ return false, nil+}++func (r *TagRepository) Create(ctx context.Context, groupID uuid.UUID, data TagCreate) (TagOut, error) {+ if data.ParentID != uuid.Nil {+ parentDepth, err := r.checkDepth(ctx, data.ParentID)+ if err != nil {+ return TagOut{}, err+ }+ // New item has depth 1.+ if parentDepth+1 > 5 {+ return TagOut{}, fmt.Errorf("max depth of 5 exceeded")+ }+ }++ q := r.db.Tag.Create().+ SetName(data.Name).+ SetDescription(data.Description).+ SetColor(data.Color).+ SetIcon(data.Icon).+ SetGroupID(groupID)++ if data.ParentID != uuid.Nil {+ q.SetParentID(data.ParentID)+ }++ createdTag, err := q.Save(ctx)+ if err != nil {+ return TagOut{}, err+ }++ if data.ParentID != uuid.Nil {+ createdTag.Edges.Parent = &ent.Tag{ID: data.ParentID}+ }++ createdTag.Edges.Group = &ent.Group{ID: groupID} // bootstrap group ID+ r.publishMutationEvent(groupID)+ return mapTagOut(createdTag), err+}++func (r *TagRepository) update(ctx context.Context, data TagUpdate, where ...predicate.Tag) (int, error) {+ if len(where) == 0 {+ panic("empty where not supported empty")+ }++ if data.ParentID != uuid.Nil {+ // 1. Check Cycle using CTE+ isCycle, err := r.checkCycle(ctx, data.ID, data.ParentID)+ if err != nil {+ return 0, err+ }+ if isCycle {+ return 0, fmt.Errorf("cycle detected")+ }++ // 2. Check Depth using CTEs+ // Depth of the new parent (how far down from root is the parent?)+ parentDepth, err := r.checkDepth(ctx, data.ParentID)+ if err != nil {+ return 0, err+ }++ // Depth of the subtree moving (how tall is the tree we are moving?)+ mySubtreeDepth, err := r.getSubtreeDepth(ctx, data.ID)+ if err != nil {+ return 0, err+ }++ if parentDepth+mySubtreeDepth > 5 {+ return 0, fmt.Errorf("max depth of 5 exceeded")+ }+ }++ q := r.db.Tag.Update().+ Where(where...).+ SetName(data.Name).+ SetDescription(data.Description).+ SetColor(data.Color).+ SetIcon(data.Icon)++ if data.ParentID != uuid.Nil {+ q.SetParentID(data.ParentID)+ } else {+ q.ClearParent()+ }++ return q.Save(ctx)+}++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 TagOut{}, err+ }++ r.publishMutationEvent(gid)+ return r.GetOne(ctx, data.ID)+}++// 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 *TagRepository) DeleteByGroup(ctx context.Context, gid, id uuid.UUID) error {+ _, err := r.db.Tag.Delete().+ Where(+ tag.ID(id),+ tag.HasGroupWith(group.ID(gid)),+ ).Exec(ctx)+ if err != nil {+ return err+ }++ r.publishMutationEvent(gid)++ return nil+}diff --git a/backend/internal/data/repo/repo_tags_test.go b/backend/internal/data/repo/repo_tags_test.gonew file mode 100644index 00000000..4dacd068--- /dev/null+++ b/backend/internal/data/repo/repo_tags_test.go@@ -0,0 +1,322 @@+package repo++import (+ "context"+ "testing"++ "github.com/google/uuid"+ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++func tagFactory() TagCreate {+ return TagCreate{+ Name: fk.Str(10),+ Description: fk.Str(100),+ }+}++func useTags(t *testing.T, len int) []TagOut {+ t.Helper()++ tags := make([]TagOut, len)+ for i := 0; i < len; i++ {+ itm := tagFactory()++ item, err := tRepos.Tags.Create(context.Background(), tGroup.ID, itm)+ require.NoError(t, err)+ tags[i] = item+ }++ t.Cleanup(func() {+ for _, item := range tags {+ _ = tRepos.Tags.delete(context.Background(), item.ID)+ }+ })++ return tags+}++func TestTagRepository_Get(t *testing.T) {+ tags := useTags(t, 1)+ tag := tags[0]++ // Get by ID+ foundLoc, err := tRepos.Tags.GetOne(context.Background(), tag.ID)+ require.NoError(t, err)+ assert.Equal(t, tag.ID, foundLoc.ID)+}++func TestTagRepositoryGetAll(t *testing.T) {+ useTags(t, 10)++ all, err := tRepos.Tags.GetAll(context.Background(), tGroup.ID)+ require.NoError(t, err)+ assert.Len(t, all, 10)+}++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.Tags.GetOne(context.Background(), loc.ID)+ require.NoError(t, err)+ assert.Equal(t, loc.ID, foundLoc.ID)++ err = tRepos.Tags.delete(context.Background(), loc.ID)+ require.NoError(t, err)+}++func TestTagsRepository_Update(t *testing.T) {+ loc, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())+ require.NoError(t, err)++ updateData := TagUpdate{+ ID: loc.ID,+ Name: fk.Str(10),+ Description: fk.Str(100),+ }++ update, err := tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateData)+ require.NoError(t, err)++ 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.Tags.delete(context.Background(), loc.ID)+ require.NoError(t, err)+}++func TestTagRepository_Delete(t *testing.T) {+ loc, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())+ require.NoError(t, err)++ err = tRepos.Tags.delete(context.Background(), loc.ID)+ require.NoError(t, err)++ _, err = tRepos.Tags.GetOne(context.Background(), loc.ID)+ require.Error(t, err)+}++func TestTagRepository_ParentChild(t *testing.T) {+ parent := tagFactory()+ parentTag, err := tRepos.Tags.Create(context.Background(), tGroup.ID, parent)+ require.NoError(t, err)++ child := tagFactory()+ child.ParentID = parentTag.ID+ childTag, err := tRepos.Tags.Create(context.Background(), tGroup.ID, child)+ require.NoError(t, err)++ assert.Equal(t, parentTag.ID, childTag.Parent.ID)++ // Fetch parent and check children+ foundParent, err := tRepos.Tags.GetOne(context.Background(), parentTag.ID)+ require.NoError(t, err)+ assert.Len(t, foundParent.Children, 1)+ assert.Equal(t, childTag.ID, foundParent.Children[0].ID)++ // Fetch child and check parent+ foundChild, err := tRepos.Tags.GetOne(context.Background(), childTag.ID)+ require.NoError(t, err)+ assert.NotNil(t, foundChild.Parent)+ assert.Equal(t, parentTag.ID, foundChild.Parent.ID)++ // Update child to remove parent+ updateData := TagUpdate{+ ID: childTag.ID,+ Name: childTag.Name,+ Description: childTag.Description,+ ParentID: uuid.Nil,+ }+ updatedChild, err := tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateData)+ require.NoError(t, err)+ assert.Nil(t, updatedChild.Parent)++ // Fetch parent again, should have no children+ foundParent, err = tRepos.Tags.GetOne(context.Background(), parentTag.ID)+ require.NoError(t, err)+ assert.Len(t, foundParent.Children, 0)+}++func TestTagRepository_MaxDepth(t *testing.T) {+ tags := make([]TagOut, 6)+ var prevID uuid.UUID++ // Create 5 levels+ for i := 0; i < 5; i++ {+ tCreate := tagFactory()+ tCreate.ParentID = prevID+ created, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tCreate)+ require.NoError(t, err)+ tags[i] = created+ prevID = created.ID+ }++ // Try to create 6th level+ tCreate := tagFactory()+ tCreate.ParentID = prevID+ _, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tCreate)+ require.Error(t, err)+ assert.Contains(t, err.Error(), "max depth of 5 exceeded")++ // Cleanup+ for _, item := range tags {+ if item.ID != uuid.Nil {+ _ = tRepos.Tags.delete(context.Background(), item.ID)+ }+ }+}++func TestTagRepository_MoveSubtreeMaxDepth(t *testing.T) {+ // Create two chains: A->B->C (depth 3) and D->E (depth 2)+ // Try to move D under C -> A->B->C->D->E (depth 5). OK.+ // Try to move D under C, but D has children making it too deep.++ // Chain 1: A -> B -> C+ tagA, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())+ require.NoError(t, err)++ tagBOrig := tagFactory()+ tagBOrig.ParentID = tagA.ID+ tagB, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagBOrig)+ require.NoError(t, err)++ tagCOrig := tagFactory()+ tagCOrig.ParentID = tagB.ID+ tagC, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagCOrig)+ require.NoError(t, err)++ // Chain 2: D -> E+ tagD, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())+ require.NoError(t, err)++ tagEOrig := tagFactory()+ tagEOrig.ParentID = tagD.ID+ tagE, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagEOrig)+ require.NoError(t, err)++ // Move D under C. Result depth: 3 (C) + 2 (D->E) = 5. Should succeed.+ updateD := TagUpdate{+ ID: tagD.ID,+ Name: tagD.Name,+ Description: tagD.Description,+ ParentID: tagC.ID,+ }+ _, err = tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateD)+ require.NoError(t, err)++ // Reset D to root for next test+ updateD.ParentID = uuid.Nil+ _, err = tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateD)+ require.NoError(t, err)++ // Add F to E -> D -> E -> F (depth 3)+ tagFOrig := tagFactory()+ tagFOrig.ParentID = tagE.ID+ tagF, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFOrig)+ require.NoError(t, err)++ // Move D under C. Result depth: 3 (C) + 3 (D->E->F) = 6. Should Fail.+ updateD.ParentID = tagC.ID+ _, err = tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateD)+ require.Error(t, err)+ assert.Contains(t, err.Error(), "max depth of 5 exceeded")++ // Cleanup+ _ = tRepos.Tags.delete(context.Background(), tagF.ID)+ _ = tRepos.Tags.delete(context.Background(), tagE.ID)+ _ = tRepos.Tags.delete(context.Background(), tagD.ID)+ _ = tRepos.Tags.delete(context.Background(), tagC.ID)+ _ = tRepos.Tags.delete(context.Background(), tagB.ID)+ _ = tRepos.Tags.delete(context.Background(), tagA.ID)+}++func TestTagRepository_CycleDetection(t *testing.T) {+ // A -> B+ // Try to set A's parent to B. Cycle.++ tagA, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())+ require.NoError(t, err)++ tagBOrig := tagFactory()+ tagBOrig.ParentID = tagA.ID+ tagB, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagBOrig)+ require.NoError(t, err)++ updateA := TagUpdate{+ ID: tagA.ID,+ Name: tagA.Name,+ Description: tagA.Description,+ ParentID: tagB.ID,+ }+ _, err = tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateA)+ require.Error(t, err)+ assert.Contains(t, err.Error(), "cycle detected")++ _ = tRepos.Tags.delete(context.Background(), tagB.ID)+ _ = tRepos.Tags.delete(context.Background(), tagA.ID)+}++func TestTagRepository_Create_NoParent(t *testing.T) {+ // Create a tag without a parent+ tagData := tagFactory()+ tagData.ParentID = uuid.Nil // Explicitly set to nil, though factory defaults to it++ createdTag, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagData)+ require.NoError(t, err)++ assert.Equal(t, tagData.Name, createdTag.Name)+ assert.Nil(t, createdTag.Parent)+ assert.Equal(t, uuid.Nil, createdTag.ParentID)++ // Verify persistence+ foundTag, err := tRepos.Tags.GetOne(context.Background(), createdTag.ID)+ require.NoError(t, err)+ assert.Nil(t, foundTag.Parent)+ assert.Equal(t, uuid.Nil, foundTag.ParentID)++ _ = tRepos.Tags.delete(context.Background(), createdTag.ID)+}++func TestTagRepository_Update_RemoveParent(t *testing.T) {+ // 1. Create Parent+ parent, err := tRepos.Tags.Create(context.Background(), tGroup.ID, tagFactory())+ require.NoError(t, err)++ // 2. Create Child+ childData := tagFactory()+ childData.ParentID = parent.ID+ child, err := tRepos.Tags.Create(context.Background(), tGroup.ID, childData)+ require.NoError(t, err)++ assert.NotNil(t, child.Parent)+ assert.Equal(t, parent.ID, child.Parent.ID)++ // 3. Update Child to remove parent+ updateData := TagUpdate{+ ID: child.ID,+ Name: child.Name,+ Description: child.Description,+ ParentID: uuid.Nil, // Remove parent+ }+ updatedChild, err := tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateData)+ require.NoError(t, err)++ assert.Nil(t, updatedChild.Parent)+ assert.Equal(t, uuid.Nil, updatedChild.ParentID)++ // 4. Verify persistence+ foundChild, err := tRepos.Tags.GetOne(context.Background(), child.ID)+ require.NoError(t, err)+ assert.Nil(t, foundChild.Parent)+ assert.Equal(t, uuid.Nil, foundChild.ParentID)++ _ = tRepos.Tags.delete(context.Background(), child.ID)+ _ = tRepos.Tags.delete(context.Background(), parent.ID)+}diff --git a/docs/public/api/openapi-3.0.json b/docs/public/api/openapi-3.0.jsonindex 6cdb869e..ca0c97a0 100644--- a/docs/public/api/openapi-3.0.json+++ b/docs/public/api/openapi-3.0.json@@ -3875,6 +3875,10 @@}]},+ "icon": {+ "description": "Icon holds the value of the \"icon\" field.",+ "type": "string"+ },"id": {"description": "ID of the ent.","type": "string"@@ -3892,6 +3896,13 @@"ent.TagEdges": {"type": "object","properties": {+ "children": {+ "description": "Children holds the value of the children edge.",+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/ent.Tag"+ }+ },"group": {"description": "Group holds the value of the group edge.","allOf": [@@ -3906,6 +3917,14 @@"items": {"$ref": "#/components/schemas/ent.Item"}+ },+ "parent": {+ "description": "Parent holds the value of the parent edge.",+ "allOf": [+ {+ "$ref": "#/components/schemas/ent.Tag"+ }+ ]}}},@@ -5262,12 +5281,22 @@"type": "string","maxLength": 255,"minLength": 1+ },+ "parentId": {+ "type": "string",+ "nullable": true}}},"repo.TagOut": {"type": "object","properties": {+ "children": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/repo.TagSummary"+ }+ },"color": {"type": "string"},@@ -5283,6 +5312,13 @@"name": {"type": "string"},+ "parent": {+ "$ref": "#/components/schemas/repo.TagSummary"+ },+ "parentId": {+ "type": "string",+ "nullable": true+ },"updatedAt": {"type": "string"}@@ -5306,6 +5342,10 @@"name": {"type": "string"},+ "parentId": {+ "type": "string",+ "nullable": true+ },"updatedAt": {"type": "string"}diff --git a/docs/public/api/openapi-3.0.yaml b/docs/public/api/openapi-3.0.yamlindex 079cac0d..30cd8bdd 100644--- a/docs/public/api/openapi-3.0.yaml+++ b/docs/public/api/openapi-3.0.yaml@@ -2399,6 +2399,9 @@ components:The values are being populated by the TagQuery when eager-loading is set.allOf:- $ref: "#/components/schemas/ent.TagEdges"+ icon:+ description: Icon holds the value of the "icon" field.+ type: stringid:description: ID of the ent.type: string@@ -2411,6 +2414,11 @@ components:ent.TagEdges:type: objectproperties:+ children:+ description: Children holds the value of the children edge.+ type: array+ items:+ $ref: "#/components/schemas/ent.Tag"group:description: Group holds the value of the group edge.allOf:@@ -2420,6 +2428,10 @@ components:type: arrayitems:$ref: "#/components/schemas/ent.Item"+ parent:+ description: Parent holds the value of the parent edge.+ allOf:+ - $ref: "#/components/schemas/ent.Tag"ent.TemplateField:type: objectproperties:@@ -3354,9 +3366,16 @@ components:type: stringmaxLength: 255minLength: 1+ parentId:+ type: string+ nullable: truerepo.TagOut:type: objectproperties:+ children:+ type: array+ items:+ $ref: "#/components/schemas/repo.TagSummary"color:type: stringcreatedAt:@@ -3367,6 +3386,11 @@ components:type: stringname:type: string+ parent:+ $ref: "#/components/schemas/repo.TagSummary"+ parentId:+ type: string+ nullable: trueupdatedAt:type: stringrepo.TagSummary:@@ -3382,6 +3406,9 @@ components:type: stringname:type: string+ parentId:+ type: string+ nullable: trueupdatedAt:type: stringrepo.TemplateField:diff --git a/docs/public/api/swagger-2.0.json b/docs/public/api/swagger-2.0.jsonindex 2b64e355..9ba2171d 100644--- a/docs/public/api/swagger-2.0.json+++ b/docs/public/api/swagger-2.0.json@@ -3676,6 +3676,10 @@}]},+ "icon": {+ "description": "Icon holds the value of the \"icon\" field.",+ "type": "string"+ },"id": {"description": "ID of the ent.","type": "string"@@ -3693,6 +3697,13 @@"ent.TagEdges": {"type": "object","properties": {+ "children": {+ "description": "Children holds the value of the children edge.",+ "type": "array",+ "items": {+ "$ref": "#/definitions/ent.Tag"+ }+ },"group": {"description": "Group holds the value of the group edge.","allOf": [@@ -3707,6 +3718,14 @@"items": {"$ref": "#/definitions/ent.Item"}+ },+ "parent": {+ "description": "Parent holds the value of the parent edge.",+ "allOf": [+ {+ "$ref": "#/definitions/ent.Tag"+ }+ ]}}},@@ -5063,12 +5082,22 @@"type": "string","maxLength": 255,"minLength": 1+ },+ "parentId": {+ "type": "string",+ "x-nullable": true}}},"repo.TagOut": {"type": "object","properties": {+ "children": {+ "type": "array",+ "items": {+ "$ref": "#/definitions/repo.TagSummary"+ }+ },"color": {"type": "string"},@@ -5084,6 +5113,13 @@"name": {"type": "string"},+ "parent": {+ "$ref": "#/definitions/repo.TagSummary"+ },+ "parentId": {+ "type": "string",+ "x-nullable": true+ },"updatedAt": {"type": "string"}@@ -5107,6 +5143,10 @@"name": {"type": "string"},+ "parentId": {+ "type": "string",+ "x-nullable": true+ },"updatedAt": {"type": "string"}diff --git a/docs/public/api/swagger-2.0.yaml b/docs/public/api/swagger-2.0.yamlindex e113de4f..b23114bd 100644--- a/docs/public/api/swagger-2.0.yaml+++ b/docs/public/api/swagger-2.0.yaml@@ -651,6 +651,9 @@ definitions:description: |-Edges holds the relations/edges for other nodes in the graph.The values are being populated by the TagQuery when eager-loading is set.+ icon:+ description: Icon holds the value of the "icon" field.+ type: stringid:description: ID of the ent.type: string@@ -663,6 +666,11 @@ definitions:type: objectent.TagEdges:properties:+ children:+ description: Children holds the value of the children edge.+ items:+ $ref: '#/definitions/ent.Tag'+ type: arraygroup:allOf:- $ref: '#/definitions/ent.Group'@@ -672,6 +680,10 @@ definitions:items:$ref: '#/definitions/ent.Item'type: array+ parent:+ allOf:+ - $ref: '#/definitions/ent.Tag'+ description: Parent holds the value of the parent edge.type: objectent.TemplateField:properties:@@ -1602,11 +1614,18 @@ definitions:maxLength: 255minLength: 1type: string+ parentId:+ type: string+ x-nullable: truerequired:- nametype: objectrepo.TagOut:properties:+ children:+ items:+ $ref: '#/definitions/repo.TagSummary'+ type: arraycolor:type: stringcreatedAt:@@ -1617,6 +1636,11 @@ definitions:type: stringname:type: string+ parent:+ $ref: '#/definitions/repo.TagSummary'+ parentId:+ type: string+ x-nullable: trueupdatedAt:type: stringtype: object@@ -1632,6 +1656,9 @@ definitions:type: stringname:type: string+ parentId:+ type: string+ x-nullable: trueupdatedAt:type: stringtype: objectdiff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.tsindex c64915eb..b4c7915d 100644--- a/frontend/lib/api/types/data-contracts.ts+++ b/frontend/lib/api/types/data-contracts.ts@@ -464,6 +464,8 @@ export interface EntTag {* The values are being populated by the TagQuery when eager-loading is set.*/edges: EntTagEdges;+ /** Icon holds the value of the "icon" field. */+ icon: string;/** ID of the ent. */id: string;/** Name holds the value of the "name" field. */@@ -473,10 +475,14 @@ export interface EntTag {}export interface EntTagEdges {+ /** Children holds the value of the children edge. */+ children: EntTag[];/** Group holds the value of the group edge. */group: EntGroup;/** Items holds the value of the items edge. */items: EntItem[];+ /** Parent holds the value of the parent edge. */+ parent: EntTag;}export interface EntTemplateField {@@ -994,14 +1000,18 @@ export interface TagCreate {* @maxLength 255*/name: string;+ parentId?: string | null;}export interface TagOut {+ children: TagSummary[];color: string;createdAt: Date | string;description: string;id: string;name: string;+ parent: TagSummary;+ parentId?: string | null;updatedAt: Date | string;}@@ -1011,6 +1021,7 @@ export interface TagSummary {description: string;id: string;name: string;+ parentId?: string | null;updatedAt: Date | string;}