Skip to content

Commit

Permalink
[ADD] Delete ingredient stock endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jedipw committed Oct 13, 2024
1 parent 0d4d0fa commit 57edd83
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 1 deletion.
110 changes: 110 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,46 @@ const docTemplate = `{
}
}
},
"/ingredient/addIngredientStock": {
"post": {
"description": "Add ingredient stock by using ingredient stock request",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ingredient"
],
"summary": "Add ingredient stock",
"parameters": [
{
"description": "Ingredient Stock Request",
"name": "AddIngredientStockRequest",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.AddIngredientStockRequest"
}
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/http.response"
}
},
"400": {
"description": "Cannot add ingredient stock\"'",
"schema": {
"$ref": "#/definitions/http.response"
}
}
}
}
},
"/ingredient/addIngredients": {
"post": {
"description": "Add ingredient by using ingredient request",
Expand Down Expand Up @@ -247,6 +287,44 @@ const docTemplate = `{
}
}
},
"/ingredient/deleteIngredientStock": {
"delete": {
"description": "Delete an ingredient stock by using ingredient stock id",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ingredient"
],
"summary": "Delete an ingredient stock",
"parameters": [
{
"type": "string",
"description": "Ingredient Stock ID",
"name": "ingredient_stock_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/http.response"
}
},
"400": {
"description": "Cannot delete an ingredient stock",
"schema": {
"$ref": "#/definitions/http.response"
}
}
}
}
},
"/ingredient/getAllIngredients": {
"get": {
"description": "Get all ingredients by user ID",
Expand Down Expand Up @@ -1124,6 +1202,38 @@ const docTemplate = `{
}
}
},
"domain.AddIngredientStockRequest": {
"type": "object",
"properties": {
"expiration_date": {
"type": "string"
},
"img": {
"type": "string"
},
"ingredient_brand": {
"type": "string"
},
"ingredient_id": {
"type": "string"
},
"note": {
"type": "string"
},
"price": {
"type": "string"
},
"quantity": {
"type": "string"
},
"supplier": {
"type": "string"
},
"user_id": {
"type": "string"
}
}
},
"domain.ChangeExpirationDateSetting": {
"type": "object",
"properties": {
Expand Down
110 changes: 110 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,46 @@
}
}
},
"/ingredient/addIngredientStock": {
"post": {
"description": "Add ingredient stock by using ingredient stock request",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ingredient"
],
"summary": "Add ingredient stock",
"parameters": [
{
"description": "Ingredient Stock Request",
"name": "AddIngredientStockRequest",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/domain.AddIngredientStockRequest"
}
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/http.response"
}
},
"400": {
"description": "Cannot add ingredient stock\"'",
"schema": {
"$ref": "#/definitions/http.response"
}
}
}
}
},
"/ingredient/addIngredients": {
"post": {
"description": "Add ingredient by using ingredient request",
Expand Down Expand Up @@ -241,6 +281,44 @@
}
}
},
"/ingredient/deleteIngredientStock": {
"delete": {
"description": "Delete an ingredient stock by using ingredient stock id",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ingredient"
],
"summary": "Delete an ingredient stock",
"parameters": [
{
"type": "string",
"description": "Ingredient Stock ID",
"name": "ingredient_stock_id",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ref": "#/definitions/http.response"
}
},
"400": {
"description": "Cannot delete an ingredient stock",
"schema": {
"$ref": "#/definitions/http.response"
}
}
}
}
},
"/ingredient/getAllIngredients": {
"get": {
"description": "Get all ingredients by user ID",
Expand Down Expand Up @@ -1118,6 +1196,38 @@
}
}
},
"domain.AddIngredientStockRequest": {
"type": "object",
"properties": {
"expiration_date": {
"type": "string"
},
"img": {
"type": "string"
},
"ingredient_brand": {
"type": "string"
},
"ingredient_id": {
"type": "string"
},
"note": {
"type": "string"
},
"price": {
"type": "string"
},
"quantity": {
"type": "string"
},
"supplier": {
"type": "string"
},
"user_id": {
"type": "string"
}
}
},
"domain.ChangeExpirationDateSetting": {
"type": "object",
"properties": {
Expand Down
72 changes: 72 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ definitions:
user_id:
type: string
type: object
domain.AddIngredientStockRequest:
properties:
expiration_date:
type: string
img:
type: string
ingredient_brand:
type: string
ingredient_id:
type: string
note:
type: string
price:
type: string
quantity:
type: string
supplier:
type: string
user_id:
type: string
type: object
domain.ChangeExpirationDateSetting:
properties:
black_expiration_date:
Expand Down Expand Up @@ -511,6 +532,32 @@ paths:
summary: Get unread notification amount of user
tags:
- home
/ingredient/addIngredientStock:
post:
consumes:
- application/json
description: Add ingredient stock by using ingredient stock request
parameters:
- description: Ingredient Stock Request
in: body
name: AddIngredientStockRequest
required: true
schema:
$ref: '#/definitions/domain.AddIngredientStockRequest'
produces:
- application/json
responses:
"200":
description: Success
schema:
$ref: '#/definitions/http.response'
"400":
description: Cannot add ingredient stock"'
schema:
$ref: '#/definitions/http.response'
summary: Add ingredient stock
tags:
- ingredient
/ingredient/addIngredients:
post:
consumes:
Expand Down Expand Up @@ -587,6 +634,31 @@ paths:
summary: Delete ingredient batch note
tags:
- ingredient
/ingredient/deleteIngredientStock:
delete:
consumes:
- application/json
description: Delete an ingredient stock by using ingredient stock id
parameters:
- description: Ingredient Stock ID
in: query
name: ingredient_stock_id
required: true
type: string
produces:
- application/json
responses:
"200":
description: Success
schema:
$ref: '#/definitions/http.response'
"400":
description: Cannot delete an ingredient stock
schema:
$ref: '#/definitions/http.response'
summary: Delete an ingredient stock
tags:
- ingredient
/ingredient/getAllIngredients:
get:
consumes:
Expand Down
23 changes: 23 additions & 0 deletions internal/adapter/handler/http/ingredient.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,29 @@ func (ih *IngredientHandler) DeleteIngredient(c *fiber.Ctx) error {
return nil
}

// DeleteIngredientStock godoc
// @Summary Delete an ingredient stock
// @Description Delete an ingredient stock by using ingredient stock id
// @Tags ingredient
// @Accept json
// @Produce json
// @Param ingredient_stock_id query string true "Ingredient Stock ID"
// @Success 200 {object} response "Success"
// @Failure 400 {object} response "Cannot delete an ingredient stock"
// @Router /ingredient/deleteIngredientStock [delete]
func (ih *IngredientHandler) DeleteIngredientStock(c *fiber.Ctx) error {
ingredientStockID := c.Query("ingredient_stock_id")

err := ih.svc.DeleteIngredientStock(c, ingredientStockID)
if err != nil {
handleError(c, 400, "Cannot delete an ingredient stock", err.Error())
return nil
}

handleSuccess(c, nil)
return nil
}

// AddIngredient godoc
// @Summary Add ingredient
// @Description Add ingredient by using ingredient request
Expand Down
1 change: 1 addition & 0 deletions internal/adapter/handler/http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewRouter(a *fiber.App, ingredientHandler IngredientHandler, recipeHandler
ingredient.Get("/getIngredientStockDetail", ingredientHandler.GetIngredientStockDetail)
ingredient.Delete("/deleteIngredientBatchNote", ingredientHandler.DeleteIngredientBatchNote)
ingredient.Delete("/deleteIngredient", ingredientHandler.DeleteIngredient)
ingredient.Delete("/deleteIngredientStock", ingredientHandler.DeleteIngredientStock)
ingredient.Post("/addIngredient", ingredientHandler.AddIngredient)
ingredient.Post("/addIngredientStock", ingredientHandler.AddIngredientStock)
}
Expand Down
Loading

0 comments on commit 57edd83

Please sign in to comment.