From fb0898aa711d51d983f9bee24a95946602fba8c0 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Mon, 12 Sep 2022 14:26:18 -0800 Subject: [PATCH] finish types for basic items editor --- backend/app/api/docs/docs.go | 18 ++- backend/app/api/docs/swagger.json | 18 ++- backend/app/api/docs/swagger.yaml | 18 ++- backend/internal/repo/repo_items.go | 4 +- backend/internal/services/mappers/items.go | 5 + backend/internal/types/item_types.go | 8 +- frontend/components/Form/Checkbox.vue | 35 ++++++ frontend/components/Form/DatePicker.vue | 2 - frontend/components/Form/TextArea.vue | 21 +++- frontend/composables/utils.ts | 13 ++ frontend/lib/api/base/base-api.ts | 4 - frontend/lib/api/types/data-contracts.ts | 24 +++- frontend/pages/home.vue | 1 - frontend/pages/item/[id]/edit.vue | 133 ++++++++++++++++++--- frontend/pages/item/[id]/index.vue | 15 ++- 15 files changed, 259 insertions(+), 60 deletions(-) create mode 100644 frontend/components/Form/Checkbox.vue diff --git a/backend/app/api/docs/docs.go b/backend/app/api/docs/docs.go index 5222143..b0b3d51 100644 --- a/backend/app/api/docs/docs.go +++ b/backend/app/api/docs/docs.go @@ -942,7 +942,8 @@ const docTemplate = `{ "type": "string" }, "purchasePrice": { - "type": "number" + "type": "string", + "example": "0" }, "purchaseTime": { "description": "Purchase", @@ -959,7 +960,8 @@ const docTemplate = `{ "type": "string" }, "soldPrice": { - "type": "number" + "type": "string", + "example": "0" }, "soldTime": { "description": "Sold", @@ -1025,7 +1027,8 @@ const docTemplate = `{ "type": "string" }, "purchasePrice": { - "type": "number" + "type": "string", + "example": "0" }, "purchaseTime": { "description": "Purchase", @@ -1042,7 +1045,8 @@ const docTemplate = `{ "type": "string" }, "soldPrice": { - "type": "number" + "type": "string", + "example": "0" }, "soldTime": { "description": "Sold", @@ -1105,7 +1109,8 @@ const docTemplate = `{ "type": "string" }, "purchasePrice": { - "type": "number" + "type": "string", + "example": "0" }, "purchaseTime": { "description": "Purchase", @@ -1122,7 +1127,8 @@ const docTemplate = `{ "type": "string" }, "soldPrice": { - "type": "number" + "type": "string", + "example": "0" }, "soldTime": { "description": "Sold", diff --git a/backend/app/api/docs/swagger.json b/backend/app/api/docs/swagger.json index b75149f..f69bd9c 100644 --- a/backend/app/api/docs/swagger.json +++ b/backend/app/api/docs/swagger.json @@ -934,7 +934,8 @@ "type": "string" }, "purchasePrice": { - "type": "number" + "type": "string", + "example": "0" }, "purchaseTime": { "description": "Purchase", @@ -951,7 +952,8 @@ "type": "string" }, "soldPrice": { - "type": "number" + "type": "string", + "example": "0" }, "soldTime": { "description": "Sold", @@ -1017,7 +1019,8 @@ "type": "string" }, "purchasePrice": { - "type": "number" + "type": "string", + "example": "0" }, "purchaseTime": { "description": "Purchase", @@ -1034,7 +1037,8 @@ "type": "string" }, "soldPrice": { - "type": "number" + "type": "string", + "example": "0" }, "soldTime": { "description": "Sold", @@ -1097,7 +1101,8 @@ "type": "string" }, "purchasePrice": { - "type": "number" + "type": "string", + "example": "0" }, "purchaseTime": { "description": "Purchase", @@ -1114,7 +1119,8 @@ "type": "string" }, "soldPrice": { - "type": "number" + "type": "string", + "example": "0" }, "soldTime": { "description": "Sold", diff --git a/backend/app/api/docs/swagger.yaml b/backend/app/api/docs/swagger.yaml index bac550f..f75f365 100644 --- a/backend/app/api/docs/swagger.yaml +++ b/backend/app/api/docs/swagger.yaml @@ -97,7 +97,8 @@ definitions: purchaseFrom: type: string purchasePrice: - type: number + example: "0" + type: string purchaseTime: description: Purchase type: string @@ -109,7 +110,8 @@ definitions: soldNotes: type: string soldPrice: - type: number + example: "0" + type: string soldTime: description: Sold type: string @@ -154,7 +156,8 @@ definitions: purchaseFrom: type: string purchasePrice: - type: number + example: "0" + type: string purchaseTime: description: Purchase type: string @@ -166,7 +169,8 @@ definitions: soldNotes: type: string soldPrice: - type: number + example: "0" + type: string soldTime: description: Sold type: string @@ -209,7 +213,8 @@ definitions: purchaseFrom: type: string purchasePrice: - type: number + example: "0" + type: string purchaseTime: description: Purchase type: string @@ -221,7 +226,8 @@ definitions: soldNotes: type: string soldPrice: - type: number + example: "0" + type: string soldTime: description: Sold type: string diff --git a/backend/internal/repo/repo_items.go b/backend/internal/repo/repo_items.go index 0d2e0e5..8a95a22 100644 --- a/backend/internal/repo/repo_items.go +++ b/backend/internal/repo/repo_items.go @@ -76,8 +76,10 @@ func (e *ItemsRepository) Update(ctx context.Context, data types.ItemUpdate) (*e SetSoldNotes(data.SoldNotes). SetNotes(data.Notes). SetLifetimeWarranty(data.LifetimeWarranty). + SetInsured(data.Insured). SetWarrantyExpires(data.WarrantyExpires). - SetWarrantyDetails(data.WarrantyDetails) + SetWarrantyDetails(data.WarrantyDetails). + SetQuantity(data.Quantity) currentLabels, err := e.db.Item.Query().Where(item.ID(data.ID)).QueryLabel().All(ctx) if err != nil { diff --git a/backend/internal/services/mappers/items.go b/backend/internal/services/mappers/items.go index 4e4201c..7698c86 100644 --- a/backend/internal/services/mappers/items.go +++ b/backend/internal/services/mappers/items.go @@ -39,6 +39,11 @@ func ToItemSummary(item *ent.Item) *types.ItemSummary { Quantity: item.Quantity, Insured: item.Insured, + // Warranty + LifetimeWarranty: item.LifetimeWarranty, + WarrantyExpires: item.WarrantyExpires, + WarrantyDetails: item.WarrantyDetails, + // Edges Location: location, Labels: labels, diff --git a/backend/internal/types/item_types.go b/backend/internal/types/item_types.go index 86908f3..36bc8ff 100644 --- a/backend/internal/types/item_types.go +++ b/backend/internal/types/item_types.go @@ -39,12 +39,12 @@ type ItemUpdate struct { // Purchase PurchaseTime time.Time `json:"purchaseTime"` PurchaseFrom string `json:"purchaseFrom"` - PurchasePrice float64 `json:"purchasePrice"` + PurchasePrice float64 `json:"purchasePrice,string"` // Sold SoldTime time.Time `json:"soldTime"` SoldTo string `json:"soldTo"` - SoldPrice float64 `json:"soldPrice"` + SoldPrice float64 `json:"soldPrice,string"` SoldNotes string `json:"soldNotes"` // Extras @@ -78,12 +78,12 @@ type ItemSummary struct { // Purchase PurchaseTime time.Time `json:"purchaseTime"` PurchaseFrom string `json:"purchaseFrom"` - PurchasePrice float64 `json:"purchasePrice"` + PurchasePrice float64 `json:"purchasePrice,string"` // Sold SoldTime time.Time `json:"soldTime"` SoldTo string `json:"soldTo"` - SoldPrice float64 `json:"soldPrice"` + SoldPrice float64 `json:"soldPrice,string"` SoldNotes string `json:"soldNotes"` // Extras diff --git a/frontend/components/Form/Checkbox.vue b/frontend/components/Form/Checkbox.vue new file mode 100644 index 0000000..d1cf6ff --- /dev/null +++ b/frontend/components/Form/Checkbox.vue @@ -0,0 +1,35 @@ + + + diff --git a/frontend/components/Form/DatePicker.vue b/frontend/components/Form/DatePicker.vue index 088b5f3..113ffe9 100644 --- a/frontend/components/Form/DatePicker.vue +++ b/frontend/components/Form/DatePicker.vue @@ -96,9 +96,7 @@ }); function select(e: MouseEvent, day: Date) { - console.log(day); selected.value = day; - console.log(selected.value); // @ts-ignore - this is a vue3 bug e.target.blur(); resetTime(); diff --git a/frontend/components/Form/TextArea.vue b/frontend/components/Form/TextArea.vue index f753a07..1157f11 100644 --- a/frontend/components/Form/TextArea.vue +++ b/frontend/components/Form/TextArea.vue @@ -1,9 +1,9 @@