diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index b43333a..732600f 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -47,15 +47,24 @@ func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc { return i } + getBool := func(s string) bool { + b, err := strconv.ParseBool(s) + if err != nil { + return false + } + return b + } + extractQuery := func(r *http.Request) repo.ItemQuery { params := r.URL.Query() return repo.ItemQuery{ - Page: intOrNegativeOne(params.Get("page")), - PageSize: intOrNegativeOne(params.Get("perPage")), - Search: params.Get("q"), - LocationIDs: uuidList(params, "locations"), - LabelIDs: uuidList(params, "labels"), + Page: intOrNegativeOne(params.Get("page")), + PageSize: intOrNegativeOne(params.Get("perPage")), + Search: params.Get("q"), + LocationIDs: uuidList(params, "locations"), + LabelIDs: uuidList(params, "labels"), + IncludeArchived: getBool(params.Get("includeArchived")), } } diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 7cad594..7d19c80 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -1274,6 +1274,9 @@ const docTemplate = `{ "repo.ItemOut": { "type": "object", "properties": { + "archived": { + "type": "boolean" + }, "attachments": { "type": "array", "items": { @@ -1383,6 +1386,9 @@ const docTemplate = `{ "repo.ItemSummary": { "type": "object", "properties": { + "archived": { + "type": "boolean" + }, "createdAt": { "type": "string" }, @@ -1421,6 +1427,9 @@ const docTemplate = `{ "repo.ItemUpdate": { "type": "object", "properties": { + "archived": { + "type": "boolean" + }, "description": { "type": "string" }, diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index b5e97e8..64bbf41 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -1266,6 +1266,9 @@ "repo.ItemOut": { "type": "object", "properties": { + "archived": { + "type": "boolean" + }, "attachments": { "type": "array", "items": { @@ -1375,6 +1378,9 @@ "repo.ItemSummary": { "type": "object", "properties": { + "archived": { + "type": "boolean" + }, "createdAt": { "type": "string" }, @@ -1413,6 +1419,9 @@ "repo.ItemUpdate": { "type": "object", "properties": { + "archived": { + "type": "boolean" + }, "description": { "type": "string" }, diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index d2cf02a..eb80be3 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -85,6 +85,8 @@ definitions: type: object repo.ItemOut: properties: + archived: + type: boolean attachments: items: $ref: '#/definitions/repo.ItemAttachment' @@ -161,6 +163,8 @@ definitions: type: object repo.ItemSummary: properties: + archived: + type: boolean createdAt: type: string description: @@ -187,6 +191,8 @@ definitions: type: object repo.ItemUpdate: properties: + archived: + type: boolean description: type: string fields: diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 8eefb5f..6861ef3 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -20,12 +20,13 @@ type ItemsRepository struct { type ( ItemQuery struct { - Page int - PageSize int - Search string `json:"search"` - LocationIDs []uuid.UUID `json:"locationIds"` - LabelIDs []uuid.UUID `json:"labelIds"` - SortBy string `json:"sortBy"` + Page int + PageSize int + Search string `json:"search"` + LocationIDs []uuid.UUID `json:"locationIds"` + LabelIDs []uuid.UUID `json:"labelIds"` + SortBy string `json:"sortBy"` + IncludeArchived bool `json:"includeArchived"` } ItemField struct { @@ -55,6 +56,7 @@ type ( Description string `json:"description"` Quantity int `json:"quantity"` Insured bool `json:"insured"` + Archived bool `json:"archived"` // Edges LocationID uuid.UUID `json:"locationId"` @@ -93,6 +95,7 @@ type ( Description string `json:"description"` Quantity int `json:"quantity"` Insured bool `json:"insured"` + Archived bool `json:"archived"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` @@ -157,6 +160,7 @@ func mapItemSummary(item *ent.Item) ItemSummary { Quantity: item.Quantity, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, + Archived: item.Archived, // Edges Location: location, @@ -276,7 +280,21 @@ func (e *ItemsRepository) GetOneByGroup(ctx context.Context, gid, id uuid.UUID) // QueryByGroup returns a list of items that belong to a specific group based on the provided query. func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q ItemQuery) (PaginationResult[ItemSummary], error) { - qb := e.db.Item.Query().Where(item.HasGroupWith(group.ID(gid))) + qb := e.db.Item.Query().Where( + item.HasGroupWith(group.ID(gid)), + ) + + if q.IncludeArchived { + println("include archived") + qb = qb.Where( + item.Or( + item.Archived(true), + item.Archived(false), + ), + ) + } else { + qb = qb.Where(item.Archived(false)) + } if len(q.LabelIDs) > 0 { labels := make([]predicate.Item, 0, len(q.LabelIDs)) @@ -384,6 +402,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, gid uuid.UUID, data SetSerialNumber(data.SerialNumber). SetModelNumber(data.ModelNumber). SetManufacturer(data.Manufacturer). + SetArchived(data.Archived). SetPurchaseTime(data.PurchaseTime). SetPurchaseFrom(data.PurchaseFrom). SetPurchasePrice(data.PurchasePrice). diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index e1bc8dd..e4304e3 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -63,6 +63,7 @@ export interface ItemField { } export interface ItemOut { + archived: boolean; attachments: ItemAttachment[]; children: ItemSummary[]; createdAt: Date; @@ -107,6 +108,7 @@ export interface ItemOut { } export interface ItemSummary { + archived: boolean; createdAt: Date; description: string; id: string; @@ -121,6 +123,7 @@ export interface ItemSummary { } export interface ItemUpdate { + archived: boolean; description: string; fields: ItemField[]; id: string;