diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 2b695bc5..fff300f0 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -2145,6 +2145,9 @@ "purchaseFrom": { "type": "string" }, + "purchaseFrom": { + "type": "string" + }, "purchasePrice": { "type": "string", "example": "0" diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index dbb31e6c..9c6b02e6 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -170,6 +170,8 @@ definitions: x-omitempty: true purchaseFrom: type: string + purchaseMethod: + type: string purchasePrice: example: "0" type: string diff --git a/backend/internal/core/services/reporting/io_sheet.go b/backend/internal/core/services/reporting/io_sheet.go index 08676bd0..681739aa 100644 --- a/backend/internal/core/services/reporting/io_sheet.go +++ b/backend/internal/core/services/reporting/io_sheet.go @@ -202,9 +202,10 @@ func (s *IOSheet) ReadItems(ctx context.Context, items []repo.ItemOut, GID uuid. Insured: item.Insured, Archived: item.Archived, - PurchasePrice: item.PurchasePrice, - PurchaseFrom: item.PurchaseFrom, - PurchaseTime: item.PurchaseTime, + PurchasePrice: item.PurchasePrice, + PurchaseMethod: item.PurchaseMethod, + PurchaseFrom: item.PurchaseFrom, + PurchaseTime: item.PurchaseTime, Manufacturer: item.Manufacturer, ModelNumber: item.ModelNumber, diff --git a/backend/internal/core/services/service_items.go b/backend/internal/core/services/service_items.go index d6f1896c..bfeacf6c 100644 --- a/backend/internal/core/services/service_items.go +++ b/backend/internal/core/services/service_items.go @@ -298,6 +298,7 @@ func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data io.Re Archived: row.Archived, PurchasePrice: row.PurchasePrice, + PurchaseFrom: row.PurchaseMethod, PurchaseFrom: row.PurchaseFrom, PurchaseTime: row.PurchaseTime, diff --git a/backend/internal/data/ent/schema/item.go b/backend/internal/data/ent/schema/item.go index 43f4859f..a20d88ed 100644 --- a/backend/internal/data/ent/schema/item.go +++ b/backend/internal/data/ent/schema/item.go @@ -76,6 +76,8 @@ func (Item) Fields() []ent.Field { // ------------------------------------ // item purchase + field.String("purchase_method"). + Optional(), field.Time("purchase_time"). Optional(), field.String("purchase_from"). diff --git a/backend/internal/data/migrations/migrations/20220929052825_init.sql b/backend/internal/data/migrations/migrations/20220929052825_init.sql index 579d559d..cabbe8f6 100644 --- a/backend/internal/data/migrations/migrations/20220929052825_init.sql +++ b/backend/internal/data/migrations/migrations/20220929052825_init.sql @@ -17,7 +17,7 @@ CREATE INDEX `documenttoken_token` ON `document_tokens` (`token`); -- create "groups" table CREATE TABLE `groups` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `currency` text NOT NULL DEFAULT 'usd', PRIMARY KEY (`id`)); -- create "items" table -CREATE TABLE `items` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `description` text NULL, `import_ref` text NULL, `notes` text NULL, `quantity` integer NOT NULL DEFAULT 1, `insured` bool NOT NULL DEFAULT false, `serial_number` text NULL, `model_number` text NULL, `manufacturer` text NULL, `lifetime_warranty` bool NOT NULL DEFAULT false, `warranty_expires` datetime NULL, `warranty_details` text NULL, `purchase_time` datetime NULL, `purchase_from` text NULL, `purchase_price` real NOT NULL DEFAULT 0, `sold_time` datetime NULL, `sold_to` text NULL, `sold_price` real NOT NULL DEFAULT 0, `sold_notes` text NULL, `group_items` uuid NOT NULL, `location_items` uuid NULL, PRIMARY KEY (`id`), CONSTRAINT `items_groups_items` FOREIGN KEY (`group_items`) REFERENCES `groups` (`id`) ON DELETE CASCADE, CONSTRAINT `items_locations_items` FOREIGN KEY (`location_items`) REFERENCES `locations` (`id`) ON DELETE CASCADE); +CREATE TABLE `items` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `description` text NULL, `import_ref` text NULL, `notes` text NULL, `quantity` integer NOT NULL DEFAULT 1, `insured` bool NOT NULL DEFAULT false, `serial_number` text NULL, `model_number` text NULL, `manufacturer` text NULL, `lifetime_warranty` bool NOT NULL DEFAULT false, `warranty_expires` datetime NULL, `warranty_details` text NULL, `purchase_method` text NULL, `purchase_time` datetime NULL, `purchase_from` text NULL, `purchase_price` real NOT NULL DEFAULT 0, `sold_time` datetime NULL, `sold_to` text NULL, `sold_price` real NOT NULL DEFAULT 0, `sold_notes` text NULL, `group_items` uuid NOT NULL, `location_items` uuid NULL, PRIMARY KEY (`id`), CONSTRAINT `items_groups_items` FOREIGN KEY (`group_items`) REFERENCES `groups` (`id`) ON DELETE CASCADE, CONSTRAINT `items_locations_items` FOREIGN KEY (`location_items`) REFERENCES `locations` (`id`) ON DELETE CASCADE); -- create index "item_name" to table: "items" CREATE INDEX `item_name` ON `items` (`name`); -- create index "item_manufacturer" to table: "items" diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index c714e229..58490d30 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -91,9 +91,10 @@ type ( WarrantyDetails string `json:"warrantyDetails"` // Purchase - PurchaseTime types.Date `json:"purchaseTime"` - PurchaseFrom string `json:"purchaseFrom"` - PurchasePrice float64 `json:"purchasePrice,string"` + PurchaseMethod string `json:"purchaseMethod"` + PurchaseTime types.Date `json:"purchaseTime"` + PurchaseFrom string `json:"purchaseFrom"` + PurchasePrice float64 `json:"purchasePrice,string"` // Sold SoldTime types.Date `json:"soldTime"` @@ -147,8 +148,9 @@ type ( WarrantyDetails string `json:"warrantyDetails"` // Purchase - PurchaseTime types.Date `json:"purchaseTime"` - PurchaseFrom string `json:"purchaseFrom"` + PurchaseMethod string `json:"purchaseMethod"` + PurchaseTime types.Date `json:"purchaseTime"` + PurchaseFrom string `json:"purchaseFrom"` // Sold SoldTime types.Date `json:"soldTime"` @@ -261,8 +263,9 @@ func mapItemOut(item *ent.Item) ItemOut { Manufacturer: item.Manufacturer, // Purchase - PurchaseTime: types.DateFromTime(item.PurchaseTime), - PurchaseFrom: item.PurchaseFrom, + PurchaseMethod: item.PurchaseMethod + PurchaseTime: types.DateFromTime(item.PurchaseTime), + PurchaseFrom: item.PurchaseFrom, // Sold SoldTime: types.DateFromTime(item.SoldTime), @@ -594,6 +597,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data SetManufacturer(data.Manufacturer). SetArchived(data.Archived). SetPurchaseTime(data.PurchaseTime.Time()). + SetPurchaseMethod(data.PurchaseMethod). SetPurchaseFrom(data.PurchaseFrom). SetPurchasePrice(data.PurchasePrice). SetSoldTime(data.SoldTime.Time()). diff --git a/backend/internal/data/repo/repo_items_test.go b/backend/internal/data/repo/repo_items_test.go index 870bcd0c..9d824c23 100644 --- a/backend/internal/data/repo/repo_items_test.go +++ b/backend/internal/data/repo/repo_items_test.go @@ -236,6 +236,7 @@ func TestItemsRepository_Update(t *testing.T) { ModelNumber: fk.Str(10), Manufacturer: fk.Str(10), PurchaseTime: types.DateFromTime(time.Now()), + PurchaseMethod: fk.Str(10), PurchaseFrom: fk.Str(10), PurchasePrice: 300.99, SoldTime: types.DateFromTime(time.Now()), @@ -262,6 +263,7 @@ func TestItemsRepository_Update(t *testing.T) { assert.Equal(t, updateData.Manufacturer, got.Manufacturer) // assert.Equal(t, updateData.PurchaseTime, got.PurchaseTime) assert.Equal(t, updateData.PurchaseFrom, got.PurchaseFrom) + assert.Equal(t, updateData.PurchaseMethod, got.PurchaseMethod) assert.InDelta(t, updateData.PurchasePrice, got.PurchasePrice, 0.01) // assert.Equal(t, updateData.SoldTime, got.SoldTime) assert.Equal(t, updateData.SoldTo, got.SoldTo) diff --git a/docs/docs/api/openapi-2.0.json b/docs/docs/api/openapi-2.0.json index d517beac..e6506800 100644 --- a/docs/docs/api/openapi-2.0.json +++ b/docs/docs/api/openapi-2.0.json @@ -2140,6 +2140,9 @@ "x-nullable": true, "x-omitempty": true }, + "purchaseMethod": { + "type": "string" + }, "purchaseFrom": { "type": "string" }, diff --git a/docs/en/import-csv.md b/docs/en/import-csv.md index 03fe2852..a910f465 100644 --- a/docs/en/import-csv.md +++ b/docs/en/import-csv.md @@ -63,6 +63,7 @@ Specifying import refs also allows you to update existing items via the CSV impo | HB.model_number | String | Model of the item | | HB.manufacturer | String | Manufacturer of the item | | HB.notes | String (1000) | General notes about the product | +| HB.purchase_method | String | Method of how the item was purchased | | HB.purchase_from | String | Name of the place the item was purchased from | | HB.purchase_price | Float64 | | | HB.purchase_time | Date | Date the item was purchased | diff --git a/frontend/lib/api/__test__/user/stats.test.ts b/frontend/lib/api/__test__/user/stats.test.ts index 51f4e2e1..dafc99ef 100644 --- a/frontend/lib/api/__test__/user/stats.test.ts +++ b/frontend/lib/api/__test__/user/stats.test.ts @@ -16,6 +16,7 @@ type ImportObj = { [`HB.manufacturer`]: string; [`HB.notes`]: string; [`HB.purchase_price`]: number; + [`HB.purchase_method`]: string; [`HB.purchase_from`]: string; [`HB.purchase_time`]: string; [`HB.lifetime_warranty`]: boolean; @@ -62,6 +63,7 @@ function importFileGenerator(entries: number): ImportObj[] { [`HB.manufacturer`]: faker.string.alphanumeric(5), [`HB.notes`]: "", [`HB.purchase_from`]: faker.person.fullName(), + [`HB.purchase_method`]: faker.string.alphanumeric(5), [`HB.purchase_price`]: faker.number.int(100), [`HB.purchase_time`]: faker.date.past().toDateString(), [`HB.lifetime_warranty`]: half > i,