diff --git a/docs/docs.go b/docs/docs.go index 398eadd..6f0b677 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -52,40 +52,25 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "$ref": "#/definitions/product.Product" - } - } + "$ref": "#/definitions/product.productGetResponse" } }, "400": { "description": "Bad Request", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "401": { "description": "Unauthorized", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "500": { "description": "Internal Server Error", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } } } @@ -122,46 +107,31 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/product.Product" - } + "$ref": "#/definitions/product.getProductByIdResponse" } }, "400": { "description": "Bad Request", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "401": { "description": "Unauthorized", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "404": { "description": "Not Found", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "500": { "description": "Internal Server Error", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } } } @@ -169,6 +139,14 @@ const docTemplate = `{ } }, "definitions": { + "handlers.Error": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + }, "product.Product": { "type": "object", "properties": { @@ -522,6 +500,25 @@ const docTemplate = `{ "type": "string" } } + }, + "product.getProductByIdResponse": { + "type": "object", + "properties": { + "product": { + "$ref": "#/definitions/product.Product" + } + } + }, + "product.productGetResponse": { + "type": "object", + "properties": { + "products": { + "type": "array", + "items": { + "$ref": "#/definitions/product.Product" + } + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.json b/docs/swagger.json index 22b0495..a99fb2b 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -45,40 +45,25 @@ "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "$ref": "#/definitions/product.Product" - } - } + "$ref": "#/definitions/product.productGetResponse" } }, "400": { "description": "Bad Request", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "401": { "description": "Unauthorized", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "500": { "description": "Internal Server Error", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } } } @@ -115,46 +100,31 @@ "200": { "description": "OK", "schema": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/product.Product" - } + "$ref": "#/definitions/product.getProductByIdResponse" } }, "400": { "description": "Bad Request", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "401": { "description": "Unauthorized", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "404": { "description": "Not Found", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } }, "500": { "description": "Internal Server Error", "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } + "$ref": "#/definitions/handlers.Error" } } } @@ -162,6 +132,14 @@ } }, "definitions": { + "handlers.Error": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + }, "product.Product": { "type": "object", "properties": { @@ -515,6 +493,25 @@ "type": "string" } } + }, + "product.getProductByIdResponse": { + "type": "object", + "properties": { + "product": { + "$ref": "#/definitions/product.Product" + } + } + }, + "product.productGetResponse": { + "type": "object", + "properties": { + "products": { + "type": "array", + "items": { + "$ref": "#/definitions/product.Product" + } + } + } } }, "securityDefinitions": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9fb97b7..2380081 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,5 +1,10 @@ basePath: /api/v1 definitions: + handlers.Error: + properties: + error: + type: string + type: object product.Product: properties: _id: @@ -235,6 +240,18 @@ definitions: product_name: type: string type: object + product.getProductByIdResponse: + properties: + product: + $ref: '#/definitions/product.Product' + type: object + product.productGetResponse: + properties: + products: + items: + $ref: '#/definitions/product.Product' + type: array + type: object info: contact: {} description: API for accessing the SnackLog product database. @@ -258,33 +275,23 @@ paths: "200": description: OK schema: - additionalProperties: - $ref: '#/definitions/product.Product' - type: object + $ref: '#/definitions/product.getProductByIdResponse' "400": description: Bad Request schema: - additionalProperties: - type: string - type: object + $ref: '#/definitions/handlers.Error' "401": description: Unauthorized schema: - additionalProperties: - type: string - type: object + $ref: '#/definitions/handlers.Error' "404": description: Not Found schema: - additionalProperties: - type: string - type: object + $ref: '#/definitions/handlers.Error' "500": description: Internal Server Error schema: - additionalProperties: - type: string - type: object + $ref: '#/definitions/handlers.Error' security: - Bearer: [] summary: Get product by ID @@ -311,29 +318,19 @@ paths: "200": description: OK schema: - additionalProperties: - items: - $ref: '#/definitions/product.Product' - type: array - type: object + $ref: '#/definitions/product.productGetResponse' "400": description: Bad Request schema: - additionalProperties: - type: string - type: object + $ref: '#/definitions/handlers.Error' "401": description: Unauthorized schema: - additionalProperties: - type: string - type: object + $ref: '#/definitions/handlers.Error' "500": description: Internal Server Error schema: - additionalProperties: - type: string - type: object + $ref: '#/definitions/handlers.Error' security: - Bearer: [] summary: Search products diff --git a/internal/handlers/product/get.go b/internal/handlers/product/get.go index e5bdee8..4874df0 100644 --- a/internal/handlers/product/get.go +++ b/internal/handlers/product/get.go @@ -10,6 +10,10 @@ import ( "github.com/gin-gonic/gin" ) +type productGetResponse struct { + Products []product.Product `json:"products"` +} + // Get godoc // @Summary Search products // @Description Search for products by name @@ -18,7 +22,7 @@ import ( // @Produce json // @Param q query string true "Search query (min 3 chars)" // @Param limit query int false "Limit results (default 10, max 100)" -// @Success 200 {object} map[string][]product.Product +// @Success 200 {object} productGetResponse // @Failure 400 {object} handlers.Error // @Failure 401 {object} handlers.Error // @Failure 500 {object} handlers.Error @@ -57,5 +61,5 @@ func (p *ProductController) Get(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{"products": products}) + c.JSON(http.StatusOK, productGetResponse{Products: *products}) } diff --git a/internal/handlers/product/getId.go b/internal/handlers/product/getId.go index 1e768f0..37343fb 100644 --- a/internal/handlers/product/getId.go +++ b/internal/handlers/product/getId.go @@ -9,6 +9,10 @@ import ( "github.com/gin-gonic/gin" ) +type getProductByIdResponse struct { + Product product.Product `json:"product"` +} + // GetID godoc // @Summary Get product by ID // @Description Get a single product by its ID @@ -16,7 +20,7 @@ import ( // @Accept json // @Produce json // @Param id path string true "Product ID" -// @Success 200 {object} map[string]product.Product +// @Success 200 {object} getProductByIdResponse // @Failure 400 {object} handlers.Error // @Failure 401 {object} handlers.Error // @Failure 404 {object} handlers.Error @@ -42,5 +46,5 @@ func (p *ProductController) GetID(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{"product": product}) + c.JSON(http.StatusOK, getProductByIdResponse{Product: *product}) }