mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 08:10:28 +00:00
new patch API endpoint
This commit is contained in:
parent
f71905db3b
commit
2ba1bda3fa
6 changed files with 169 additions and 1 deletions
|
@ -167,6 +167,33 @@ func (ctrl *V1Controller) HandleItemUpdate() errchain.HandlerFunc {
|
||||||
return adapters.ActionID("id", fn, http.StatusOK)
|
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
|
// HandleGetAllCustomFieldNames godocs
|
||||||
//
|
//
|
||||||
// @Summary Get All Custom Field Names
|
// @Summary Get All Custom Field Names
|
||||||
|
|
|
@ -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.Get(v1Base("/items/{id}"), chain.ToHandlerFunc(v1Ctrl.HandleItemGet(), userMW...))
|
||||||
r.Put(v1Base("/items/{id}"), chain.ToHandlerFunc(v1Ctrl.HandleItemUpdate(), 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.Delete(v1Base("/items/{id}"), chain.ToHandlerFunc(v1Ctrl.HandleItemDelete(), userMW...))
|
||||||
|
|
||||||
r.Post(v1Base("/items/{id}/attachments"), chain.ToHandlerFunc(v1Ctrl.HandleItemAttachmentCreate(), userMW...))
|
r.Post(v1Base("/items/{id}/attachments"), chain.ToHandlerFunc(v1Ctrl.HandleItemAttachmentCreate(), userMW...))
|
||||||
|
|
|
@ -635,6 +635,46 @@ const docTemplate = `{
|
||||||
"description": "No Content"
|
"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": {
|
"/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": {
|
"repo.ItemSummary": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
@ -627,6 +627,46 @@
|
||||||
"description": "No Content"
|
"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": {
|
"/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": {
|
"repo.ItemSummary": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
@ -191,6 +191,15 @@ definitions:
|
||||||
warrantyExpires:
|
warrantyExpires:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
repo.ItemPatch:
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
quantity:
|
||||||
|
type: integer
|
||||||
|
x-nullable: true
|
||||||
|
x-omitempty: true
|
||||||
|
type: object
|
||||||
repo.ItemSummary:
|
repo.ItemSummary:
|
||||||
properties:
|
properties:
|
||||||
archived:
|
archived:
|
||||||
|
@ -992,6 +1001,31 @@ paths:
|
||||||
summary: Get Item
|
summary: Get Item
|
||||||
tags:
|
tags:
|
||||||
- Items
|
- 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:
|
put:
|
||||||
parameters:
|
parameters:
|
||||||
- description: Item ID
|
- description: Item ID
|
||||||
|
|
|
@ -104,7 +104,7 @@ type (
|
||||||
ItemPatch struct {
|
ItemPatch struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
Quantity *int `json:"quantity,omitempty" extensions:"x-nullable,x-omitempty"`
|
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 {
|
ItemSummary struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue