From b8cee37fdcb553d8ab702a19c1f1a1622dd08c9a Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sun, 11 Sep 2022 21:07:51 -0800 Subject: [PATCH] WIP item update client side actions --- Taskfile.yml | 23 ++- backend/app/api/docs/docs.go | 86 +++++++++++ backend/app/api/docs/swagger.json | 86 +++++++++++ backend/app/api/docs/swagger.yaml | 59 ++++++++ backend/app/api/v1/v1_ctrl_items.go | 5 +- backend/pkgs/server/request.go | 2 +- frontend/components/Base/Details.vue | 6 +- frontend/components/Form/DatePicker.vue | 5 + frontend/components/Form/Multiselect.vue | 33 ++--- frontend/components/Form/Select.vue | 14 +- frontend/components/Item/Card.vue | 4 +- frontend/components/Item/CreateModal.vue | 7 +- frontend/components/global/DateTime.vue | 52 +++++++ frontend/composables/use-preferences.ts | 2 + frontend/composables/utils.ts | 22 +++ frontend/lib/api/base/base-api.ts | 22 +++ frontend/lib/api/classes/items.ts | 17 ++- frontend/lib/api/types/data-contracts.ts | 36 +++++ frontend/pages/item/[id]/edit.vue | 180 ++++++++++++++++++----- frontend/pages/item/[id]/index.vue | 27 +++- 20 files changed, 595 insertions(+), 93 deletions(-) create mode 100644 frontend/components/global/DateTime.vue create mode 100644 frontend/composables/utils.ts diff --git a/Taskfile.yml b/Taskfile.yml index ad23351..722d647 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,7 +5,6 @@ tasks: cmds: - | cd backend && ent generate ./ent/schema \ - --template=ent/schema/templates/stringer.tmpl \ --template=ent/schema/templates/has_id.tmpl - cd backend/app/api/ && swag fmt - cd backend/app/api/ && swag init --dir=./,../../internal,../../pkgs @@ -17,18 +16,12 @@ tasks: --path ./backend/app/api/docs/swagger.json \ --output ./frontend/lib/api/types - # Output cleanup for the generated types - # 1. Remove the prefix `Types` from each type generated - # 2. Remove the ?: from the type definition since types are not properly annotated in the swagger.json - python3 ./scripts/process-types.py ./frontend/lib/api/types/data-contracts.ts api: cmds: - task: generate - cd backend && go run ./app/api/ {{.CLI_ARGS}} silent: false - sources: - - ./backend/**/*.go api:build: cmds: @@ -40,6 +33,10 @@ tasks: - cd backend && go test ./app/api/ silent: true + api:watch: + cmds: + - cd backend && gotestsum --watch ./... + api:coverage: cmds: - cd backend && go test -race -coverprofile=coverage.out -covermode=atomic ./app/... ./internal/... ./pkgs/... -v -cover @@ -53,12 +50,12 @@ tasks: - cd frontend && pnpm run test:ci silent: true - docker:build: + frontend:watch: + desc: Starts the vitest test runner in watch mode cmds: - - cd backend && docker-compose up --build - silent: true + - cd frontend && pnpm vitest --watch - generate:types: + frontend: + desc: Run frontend development server cmds: - - cd backend && go run ./app/generator - silent: true + - cd frontend && pnpm dev diff --git a/backend/app/api/docs/docs.go b/backend/app/api/docs/docs.go index 9442e2d..5222143 100644 --- a/backend/app/api/docs/docs.go +++ b/backend/app/api/docs/docs.go @@ -175,6 +175,15 @@ const docTemplate = `{ "name": "id", "in": "path", "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/types.ItemUpdate" + } } ], "responses": { @@ -1053,6 +1062,83 @@ const docTemplate = `{ } } }, + "types.ItemUpdate": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "insured": { + "type": "boolean" + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, + "locationId": { + "description": "Edges", + "type": "string" + }, + "manufacturer": { + "type": "string" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "notes": { + "description": "Extras", + "type": "string" + }, + "purchaseFrom": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "purchaseTime": { + "description": "Purchase", + "type": "string" + }, + "quantity": { + "type": "integer" + }, + "serialNumber": { + "description": "Identifications", + "type": "string" + }, + "soldNotes": { + "type": "string" + }, + "soldPrice": { + "type": "number" + }, + "soldTime": { + "description": "Sold", + "type": "string" + }, + "soldTo": { + "type": "string" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" + } + } + }, "types.LabelCreate": { "type": "object", "properties": { diff --git a/backend/app/api/docs/swagger.json b/backend/app/api/docs/swagger.json index 7e5b242..b75149f 100644 --- a/backend/app/api/docs/swagger.json +++ b/backend/app/api/docs/swagger.json @@ -167,6 +167,15 @@ "name": "id", "in": "path", "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/types.ItemUpdate" + } } ], "responses": { @@ -1045,6 +1054,83 @@ } } }, + "types.ItemUpdate": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "id": { + "type": "string" + }, + "insured": { + "type": "boolean" + }, + "labelIds": { + "type": "array", + "items": { + "type": "string" + } + }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, + "locationId": { + "description": "Edges", + "type": "string" + }, + "manufacturer": { + "type": "string" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "notes": { + "description": "Extras", + "type": "string" + }, + "purchaseFrom": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "purchaseTime": { + "description": "Purchase", + "type": "string" + }, + "quantity": { + "type": "integer" + }, + "serialNumber": { + "description": "Identifications", + "type": "string" + }, + "soldNotes": { + "type": "string" + }, + "soldPrice": { + "type": "number" + }, + "soldTime": { + "description": "Sold", + "type": "string" + }, + "soldTo": { + "type": "string" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" + } + } + }, "types.LabelCreate": { "type": "object", "properties": { diff --git a/backend/app/api/docs/swagger.yaml b/backend/app/api/docs/swagger.yaml index ad01ccb..bac550f 100644 --- a/backend/app/api/docs/swagger.yaml +++ b/backend/app/api/docs/swagger.yaml @@ -179,6 +179,59 @@ definitions: warrantyExpires: type: string type: object + types.ItemUpdate: + properties: + description: + type: string + id: + type: string + insured: + type: boolean + labelIds: + items: + type: string + type: array + lifetimeWarranty: + description: Warranty + type: boolean + locationId: + description: Edges + type: string + manufacturer: + type: string + modelNumber: + type: string + name: + type: string + notes: + description: Extras + type: string + purchaseFrom: + type: string + purchasePrice: + type: number + purchaseTime: + description: Purchase + type: string + quantity: + type: integer + serialNumber: + description: Identifications + type: string + soldNotes: + type: string + soldPrice: + type: number + soldTime: + description: Sold + type: string + soldTo: + type: string + warrantyDetails: + type: string + warrantyExpires: + type: string + type: object types.LabelCreate: properties: color: @@ -415,6 +468,12 @@ paths: name: id required: true type: string + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/types.ItemUpdate' produces: - application/json responses: diff --git a/backend/app/api/v1/v1_ctrl_items.go b/backend/app/api/v1/v1_ctrl_items.go index 3c3132f..23a0d92 100644 --- a/backend/app/api/v1/v1_ctrl_items.go +++ b/backend/app/api/v1/v1_ctrl_items.go @@ -64,7 +64,7 @@ func (ctrl *V1Controller) HandleItemsCreate() http.HandlerFunc { // @Summary deletes a item // @Tags Items // @Produce json -// @Param id path string true "Item ID" +// @Param id path string true "Item ID" // @Success 204 // @Router /v1/items/{id} [DELETE] // @Security Bearer @@ -90,7 +90,7 @@ func (ctrl *V1Controller) HandleItemDelete() http.HandlerFunc { // @Tags Items // @Produce json // @Param id path string true "Item ID" -// @Success 200 {object} types.ItemOut +// @Success 200 {object} types.ItemOut // @Router /v1/items/{id} [GET] // @Security Bearer func (ctrl *V1Controller) HandleItemGet() http.HandlerFunc { @@ -115,6 +115,7 @@ func (ctrl *V1Controller) HandleItemGet() http.HandlerFunc { // @Tags Items // @Produce json // @Param id path string true "Item ID" +// @Param payload body types.ItemUpdate true "Item Data" // @Success 200 {object} types.ItemOut // @Router /v1/items/{id} [PUT] // @Security Bearer diff --git a/backend/pkgs/server/request.go b/backend/pkgs/server/request.go index c4b30a4..ffb76d1 100644 --- a/backend/pkgs/server/request.go +++ b/backend/pkgs/server/request.go @@ -9,7 +9,7 @@ import ( // body is decoded into the provided value. func Decode(r *http.Request, val interface{}) error { decoder := json.NewDecoder(r.Body) - decoder.DisallowUnknownFields() + // decoder.DisallowUnknownFields() if err := decoder.Decode(val); err != nil { return err } diff --git a/frontend/components/Base/Details.vue b/frontend/components/Base/Details.vue index ca1225b..27d41f8 100644 --- a/frontend/components/Base/Details.vue +++ b/frontend/components/Base/Details.vue @@ -15,7 +15,7 @@ {{ dKey }}