A continuation of HomeBox the inventory and organization system built for the Home User
fix: coderabbit issues
Matthew Kilgore790f44aa003d
diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.goindex c2938f7e..224a594b 100644--- a/backend/app/api/static/docs/docs.go+++ b/backend/app/api/static/docs/docs.go@@ -5080,6 +5080,10 @@ const docTemplate = `{"type": "string","maxLength": 1000},+ "icon": {+ "type": "string",+ "maxLength": 255+ },"name": {"type": "string","maxLength": 255,@@ -5109,6 +5113,9 @@ const docTemplate = `{"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},@@ -5116,7 +5123,12 @@ const docTemplate = `{"type": "string"},"parent": {- "$ref": "#/definitions/repo.TagSummary"+ "allOf": [+ {+ "$ref": "#/definitions/repo.TagSummary"+ }+ ],+ "x-nullable": true},"parentId": {"type": "string",@@ -5139,6 +5151,9 @@ const docTemplate = `{"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},diff --git a/backend/app/api/static/docs/openapi-3.json b/backend/app/api/static/docs/openapi-3.jsonindex ca0c97a0..b063a146 100644--- a/backend/app/api/static/docs/openapi-3.json+++ b/backend/app/api/static/docs/openapi-3.json@@ -5277,6 +5277,10 @@"type": "string","maxLength": 1000},+ "icon": {+ "type": "string",+ "maxLength": 255+ },"name": {"type": "string","maxLength": 255,@@ -5306,6 +5310,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},@@ -5313,7 +5320,12 @@"type": "string"},"parent": {- "$ref": "#/components/schemas/repo.TagSummary"+ "allOf": [+ {+ "$ref": "#/components/schemas/repo.TagSummary"+ }+ ],+ "nullable": true},"parentId": {"type": "string",@@ -5336,6 +5348,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},diff --git a/backend/app/api/static/docs/openapi-3.yaml b/backend/app/api/static/docs/openapi-3.yamlindex 30cd8bdd..870a2e80 100644--- a/backend/app/api/static/docs/openapi-3.yaml+++ b/backend/app/api/static/docs/openapi-3.yaml@@ -3362,6 +3362,9 @@ components:description:type: stringmaxLength: 1000+ icon:+ type: string+ maxLength: 255name:type: stringmaxLength: 255@@ -3382,12 +3385,16 @@ components:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:type: stringparent:- $ref: "#/components/schemas/repo.TagSummary"+ allOf:+ - $ref: "#/components/schemas/repo.TagSummary"+ nullable: trueparentId:type: stringnullable: true@@ -3402,6 +3409,8 @@ components:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.jsonindex 9ba2171d..6061246e 100644--- a/backend/app/api/static/docs/swagger.json+++ b/backend/app/api/static/docs/swagger.json@@ -5078,6 +5078,10 @@"type": "string","maxLength": 1000},+ "icon": {+ "type": "string",+ "maxLength": 255+ },"name": {"type": "string","maxLength": 255,@@ -5107,6 +5111,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},@@ -5114,7 +5121,12 @@"type": "string"},"parent": {- "$ref": "#/definitions/repo.TagSummary"+ "allOf": [+ {+ "$ref": "#/definitions/repo.TagSummary"+ }+ ],+ "x-nullable": true},"parentId": {"type": "string",@@ -5137,6 +5149,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yamlindex b23114bd..bdc44cb8 100644--- a/backend/app/api/static/docs/swagger.yaml+++ b/backend/app/api/static/docs/swagger.yaml@@ -1610,6 +1610,9 @@ definitions:description:maxLength: 1000type: string+ icon:+ maxLength: 255+ type: stringname:maxLength: 255minLength: 1@@ -1632,12 +1635,16 @@ definitions:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:type: stringparent:- $ref: '#/definitions/repo.TagSummary'+ allOf:+ - $ref: '#/definitions/repo.TagSummary'+ x-nullable: trueparentId:type: stringx-nullable: true@@ -1652,6 +1659,8 @@ definitions:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:diff --git a/backend/internal/data/repo/repo_tags.go b/backend/internal/data/repo/repo_tags.goindex 0c21f2a6..b18becca 100644--- a/backend/internal/data/repo/repo_tags.go+++ b/backend/internal/data/repo/repo_tags.go@@ -49,7 +49,7 @@ type (TagOut struct {TagSummary- Parent *TagSummary `json:"parent,omitempty"`+ Parent *TagSummary `json:"parent,omitempty" extensions:"x-nullable"`Children []TagSummary `json:"children"`})@@ -87,7 +87,9 @@ func mapTagOut(tag *ent.Tag) TagOut {children := make([]TagSummary, 0)if tag.Edges.Children != nil {for _, c := range tag.Edges.Children {- children = append(children, mapTagSummary(c))+ summary := mapTagSummary(c)+ summary.ParentID = tag.ID+ children = append(children, summary)}}@@ -114,12 +116,12 @@ func (r *TagRepository) getOne(ctx context.Context, where ...predicate.Tag) (Tag)}-func (r *TagRepository) GetOne(ctx context.Context, id uuid.UUID) (TagOut, error) {- return r.getOne(ctx, tag.ID(id))+func (r *TagRepository) GetOne(ctx context.Context, gid uuid.UUID, id uuid.UUID) (TagOut, error) {+ return r.getOne(ctx, tag.ID(id), tag.HasGroupWith(group.ID(gid)))}-func (r *TagRepository) GetOneByGroup(ctx context.Context, gid, ld uuid.UUID) (TagOut, error) {- return r.getOne(ctx, tag.ID(ld), tag.HasGroupWith(group.ID(gid)))+func (r *TagRepository) GetOneByGroup(ctx context.Context, gid, id uuid.UUID) (TagOut, error) {+ return r.getOne(ctx, tag.ID(id), tag.HasGroupWith(group.ID(gid)))}func (r *TagRepository) GetAll(ctx context.Context, groupID uuid.UUID) ([]TagSummary, error) {@@ -260,13 +262,14 @@ func (r *TagRepository) Create(ctx context.Context, groupID uuid.UUID, data TagCreturn TagOut{}, err}- if data.ParentID != uuid.Nil {- createdTag.Edges.Parent = &ent.Tag{ID: data.ParentID}+ // Re-fetch the tag to get fully populated edges (Parent, Children)+ freshTag, err := r.getOne(ctx, tag.ID(createdTag.ID), tag.HasGroupWith(group.ID(groupID)))+ if err != nil {+ return TagOut{}, err}- createdTag.Edges.Group = &ent.Group{ID: groupID} // bootstrap group IDr.publishMutationEvent(groupID)- return mapTagOut(createdTag), err+ return freshTag, nil}func (r *TagRepository) update(ctx context.Context, data TagUpdate, where ...predicate.Tag) (int, error) {@@ -319,13 +322,17 @@ func (r *TagRepository) update(ctx context.Context, data TagUpdate, where ...pre}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)))+ affected, err := r.update(ctx, data, tag.ID(data.ID), tag.HasGroupWith(group.ID(gid)))if err != nil {return TagOut{}, err}+ if affected == 0 {+ return TagOut{}, fmt.Errorf("tag not found or does not belong to group")+ }+r.publishMutationEvent(gid)- return r.GetOne(ctx, data.ID)+ return r.GetOne(ctx, gid, data.ID)}// delete removes the tag from the database. This should only be used whendiff --git a/backend/internal/data/repo/repo_tags_test.go b/backend/internal/data/repo/repo_tags_test.goindex 4dacd068..6eb91574 100644--- a/backend/internal/data/repo/repo_tags_test.go+++ b/backend/internal/data/repo/repo_tags_test.go@@ -42,7 +42,7 @@ func TestTagRepository_Get(t *testing.T) {tag := tags[0]// Get by ID- foundLoc, err := tRepos.Tags.GetOne(context.Background(), tag.ID)+ foundLoc, err := tRepos.Tags.GetOne(context.Background(), tGroup.ID, tag.ID)require.NoError(t, err)assert.Equal(t, tag.ID, foundLoc.ID)}@@ -60,7 +60,7 @@ func TestTagRepository_Create(t *testing.T) {require.NoError(t, err)// Get by ID- foundLoc, err := tRepos.Tags.GetOne(context.Background(), loc.ID)+ foundLoc, err := tRepos.Tags.GetOne(context.Background(), tGroup.ID, loc.ID)require.NoError(t, err)assert.Equal(t, loc.ID, foundLoc.ID)@@ -81,7 +81,7 @@ func TestTagsRepository_Update(t *testing.T) {update, err := tRepos.Tags.UpdateByGroup(context.Background(), tGroup.ID, updateData)require.NoError(t, err)- foundLoc, err := tRepos.Tags.GetOne(context.Background(), loc.ID)+ foundLoc, err := tRepos.Tags.GetOne(context.Background(), tGroup.ID, loc.ID)require.NoError(t, err)assert.Equal(t, update.ID, foundLoc.ID)@@ -99,7 +99,7 @@ func TestTagRepository_Delete(t *testing.T) {err = tRepos.Tags.delete(context.Background(), loc.ID)require.NoError(t, err)- _, err = tRepos.Tags.GetOne(context.Background(), loc.ID)+ _, err = tRepos.Tags.GetOne(context.Background(), tGroup.ID, loc.ID)require.Error(t, err)}@@ -116,13 +116,13 @@ func TestTagRepository_ParentChild(t *testing.T) {assert.Equal(t, parentTag.ID, childTag.Parent.ID)// Fetch parent and check children- foundParent, err := tRepos.Tags.GetOne(context.Background(), parentTag.ID)+ foundParent, err := tRepos.Tags.GetOne(context.Background(), tGroup.ID, 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)+ foundChild, err := tRepos.Tags.GetOne(context.Background(), tGroup.ID, childTag.ID)require.NoError(t, err)assert.NotNil(t, foundChild.Parent)assert.Equal(t, parentTag.ID, foundChild.Parent.ID)@@ -139,7 +139,7 @@ func TestTagRepository_ParentChild(t *testing.T) {assert.Nil(t, updatedChild.Parent)// Fetch parent again, should have no children- foundParent, err = tRepos.Tags.GetOne(context.Background(), parentTag.ID)+ foundParent, err = tRepos.Tags.GetOne(context.Background(), tGroup.ID, parentTag.ID)require.NoError(t, err)assert.Len(t, foundParent.Children, 0)}@@ -276,7 +276,7 @@ func TestTagRepository_Create_NoParent(t *testing.T) {assert.Equal(t, uuid.Nil, createdTag.ParentID)// Verify persistence- foundTag, err := tRepos.Tags.GetOne(context.Background(), createdTag.ID)+ foundTag, err := tRepos.Tags.GetOne(context.Background(), tGroup.ID, createdTag.ID)require.NoError(t, err)assert.Nil(t, foundTag.Parent)assert.Equal(t, uuid.Nil, foundTag.ParentID)@@ -312,7 +312,7 @@ func TestTagRepository_Update_RemoveParent(t *testing.T) {assert.Equal(t, uuid.Nil, updatedChild.ParentID)// 4. Verify persistence- foundChild, err := tRepos.Tags.GetOne(context.Background(), child.ID)+ foundChild, err := tRepos.Tags.GetOne(context.Background(), tGroup.ID, child.ID)require.NoError(t, err)assert.Nil(t, foundChild.Parent)assert.Equal(t, uuid.Nil, foundChild.ParentID)diff --git a/docs/public/api/openapi-3.0.json b/docs/public/api/openapi-3.0.jsonindex ca0c97a0..b063a146 100644--- a/docs/public/api/openapi-3.0.json+++ b/docs/public/api/openapi-3.0.json@@ -5277,6 +5277,10 @@"type": "string","maxLength": 1000},+ "icon": {+ "type": "string",+ "maxLength": 255+ },"name": {"type": "string","maxLength": 255,@@ -5306,6 +5310,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},@@ -5313,7 +5320,12 @@"type": "string"},"parent": {- "$ref": "#/components/schemas/repo.TagSummary"+ "allOf": [+ {+ "$ref": "#/components/schemas/repo.TagSummary"+ }+ ],+ "nullable": true},"parentId": {"type": "string",@@ -5336,6 +5348,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},diff --git a/docs/public/api/openapi-3.0.yaml b/docs/public/api/openapi-3.0.yamlindex 30cd8bdd..870a2e80 100644--- a/docs/public/api/openapi-3.0.yaml+++ b/docs/public/api/openapi-3.0.yaml@@ -3362,6 +3362,9 @@ components:description:type: stringmaxLength: 1000+ icon:+ type: string+ maxLength: 255name:type: stringmaxLength: 255@@ -3382,12 +3385,16 @@ components:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:type: stringparent:- $ref: "#/components/schemas/repo.TagSummary"+ allOf:+ - $ref: "#/components/schemas/repo.TagSummary"+ nullable: trueparentId:type: stringnullable: true@@ -3402,6 +3409,8 @@ components:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:diff --git a/docs/public/api/swagger-2.0.json b/docs/public/api/swagger-2.0.jsonindex 9ba2171d..6061246e 100644--- a/docs/public/api/swagger-2.0.json+++ b/docs/public/api/swagger-2.0.json@@ -5078,6 +5078,10 @@"type": "string","maxLength": 1000},+ "icon": {+ "type": "string",+ "maxLength": 255+ },"name": {"type": "string","maxLength": 255,@@ -5107,6 +5111,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},@@ -5114,7 +5121,12 @@"type": "string"},"parent": {- "$ref": "#/definitions/repo.TagSummary"+ "allOf": [+ {+ "$ref": "#/definitions/repo.TagSummary"+ }+ ],+ "x-nullable": true},"parentId": {"type": "string",@@ -5137,6 +5149,9 @@"description": {"type": "string"},+ "icon": {+ "type": "string"+ },"id": {"type": "string"},diff --git a/docs/public/api/swagger-2.0.yaml b/docs/public/api/swagger-2.0.yamlindex b23114bd..bdc44cb8 100644--- a/docs/public/api/swagger-2.0.yaml+++ b/docs/public/api/swagger-2.0.yaml@@ -1610,6 +1610,9 @@ definitions:description:maxLength: 1000type: string+ icon:+ maxLength: 255+ type: stringname:maxLength: 255minLength: 1@@ -1632,12 +1635,16 @@ definitions:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:type: stringparent:- $ref: '#/definitions/repo.TagSummary'+ allOf:+ - $ref: '#/definitions/repo.TagSummary'+ x-nullable: trueparentId:type: stringx-nullable: true@@ -1652,6 +1659,8 @@ definitions:type: stringdescription:type: string+ icon:+ type: stringid:type: stringname:diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.tsindex b4c7915d..afd3fce6 100644--- a/frontend/lib/api/types/data-contracts.ts+++ b/frontend/lib/api/types/data-contracts.ts@@ -995,6 +995,8 @@ export interface TagCreate {color: string;/** @maxLength 1000 */description: string;+ /** @maxLength 255 */+ icon: string;/*** @minLength 1* @maxLength 255@@ -1008,9 +1010,10 @@ export interface TagOut {color: string;createdAt: Date | string;description: string;+ icon: string;id: string;name: string;- parent: TagSummary;+ parent?: TagSummary | null;parentId?: string | null;updatedAt: Date | string;}@@ -1019,6 +1022,7 @@ export interface TagSummary {color: string;createdAt: Date | string;description: string;+ icon: string;id: string;name: string;parentId?: string | null;