diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index c6cd328..c6bb1f9 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -167,6 +167,33 @@ func (ctrl *V1Controller) HandleItemUpdate() errchain.HandlerFunc { return adapters.ActionID("id", fn, http.StatusOK) } + +// HandleItemPatch godocs +// +// @Summary Update Item +// @Tags Items +// @Produce json +// @Param id path string true "Item ID" +// @Param payload body repo.ItemPatch true "Item Data" +// @Success 200 {object} repo.ItemOut +// @Router /v1/items/{id} [Patch] +// @Security Bearer +func (ctrl *V1Controller) HandleItemPatch() errchain.HandlerFunc { + fn := func(r *http.Request, ID uuid.UUID, body repo.ItemPatch) (repo.ItemOut, error) { + auth := services.NewContext(r.Context()) + + body.ID = ID + err := ctrl.repo.Items.Patch(auth, auth.GID, ID, body) + if err != nil { + return repo.ItemOut{}, err + } + + return ctrl.repo.Items.GetOneByGroup(auth, auth.GID, ID) + } + + return adapters.ActionID("id", fn, http.StatusOK) +} + // HandleGetAllCustomFieldNames godocs // // @Summary Get All Custom Field Names diff --git a/backend/app/api/routes.go b/backend/app/api/routes.go index affc79f..abf14fd 100644 --- a/backend/app/api/routes.go +++ b/backend/app/api/routes.go @@ -113,6 +113,7 @@ func (a *app) mountRoutes(r *chi.Mux, chain *errchain.ErrChain, repos *repo.AllR r.Get(v1Base("/items/{id}"), chain.ToHandlerFunc(v1Ctrl.HandleItemGet(), userMW...)) r.Put(v1Base("/items/{id}"), chain.ToHandlerFunc(v1Ctrl.HandleItemUpdate(), userMW...)) + r.Patch(v1Base("/items/{id}"), chain.ToHandlerFunc(v1Ctrl.HandleItemPatch(), userMW...)) r.Delete(v1Base("/items/{id}"), chain.ToHandlerFunc(v1Ctrl.HandleItemDelete(), userMW...)) r.Post(v1Base("/items/{id}/attachments"), chain.ToHandlerFunc(v1Ctrl.HandleItemAttachmentCreate(), userMW...)) diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.go index 7c7da2d..30ee544 100644 --- a/backend/app/api/static/docs/docs.go +++ b/backend/app/api/static/docs/docs.go @@ -635,6 +635,46 @@ const docTemplate = `{ "description": "No Content" } } + }, + "patch": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Update Item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemPatch" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } } }, "/v1/items/{id}/attachments": { @@ -2042,6 +2082,19 @@ const docTemplate = `{ } } }, + "repo.ItemPatch": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "quantity": { + "type": "integer", + "x-nullable": true, + "x-omitempty": true + } + } + }, "repo.ItemSummary": { "type": "object", "properties": { diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.json index 818dfe6..3c390f2 100644 --- a/backend/app/api/static/docs/swagger.json +++ b/backend/app/api/static/docs/swagger.json @@ -627,6 +627,46 @@ "description": "No Content" } } + }, + "patch": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "Items" + ], + "summary": "Update Item", + "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Item Data", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/repo.ItemPatch" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/repo.ItemOut" + } + } + } } }, "/v1/items/{id}/attachments": { @@ -2034,6 +2074,19 @@ } } }, + "repo.ItemPatch": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "quantity": { + "type": "integer", + "x-nullable": true, + "x-omitempty": true + } + } + }, "repo.ItemSummary": { "type": "object", "properties": { diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yaml index cc6c467..e77257a 100644 --- a/backend/app/api/static/docs/swagger.yaml +++ b/backend/app/api/static/docs/swagger.yaml @@ -191,6 +191,15 @@ definitions: warrantyExpires: type: string type: object + repo.ItemPatch: + properties: + id: + type: string + quantity: + type: integer + x-nullable: true + x-omitempty: true + type: object repo.ItemSummary: properties: archived: @@ -992,6 +1001,31 @@ paths: summary: Get Item tags: - Items + patch: + parameters: + - description: Item ID + in: path + name: id + required: true + type: string + - description: Item Data + in: body + name: payload + required: true + schema: + $ref: '#/definitions/repo.ItemPatch' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/repo.ItemOut' + security: + - Bearer: [] + summary: Update Item + tags: + - Items put: parameters: - description: Item ID diff --git a/backend/internal/data/repo/repo_items.go b/backend/internal/data/repo/repo_items.go index 3e263cc..3f3c11b 100644 --- a/backend/internal/data/repo/repo_items.go +++ b/backend/internal/data/repo/repo_items.go @@ -104,7 +104,7 @@ type ( ItemPatch struct { ID uuid.UUID `json:"id"` Quantity *int `json:"quantity,omitempty" extensions:"x-nullable,x-omitempty"` - ImportRef *string `json:"importRef,omitempty" extensions:"x-nullable,x-omitempty"` + ImportRef *string `json:"-,omitempty" extensions:"x-nullable,x-omitempty"` } ItemSummary struct {