Skip to content

Commit

Permalink
Merge pull request #53 from nikhilnarayanan623/feature/aws-s3
Browse files Browse the repository at this point in the history
aws s3 added and product image upload to s3 feature added
  • Loading branch information
nikhilnarayanan623 authored Aug 11, 2023
2 parents ff4d32d + 8bd03f1 commit 68cfbd6
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 132 deletions.
74 changes: 33 additions & 41 deletions cmd/api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 33 additions & 41 deletions cmd/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1793,9 +1793,6 @@
},
"post": {
"description": "API for admin to add a new product",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
Expand All @@ -1806,13 +1803,39 @@
"operationId": "SaveProduct",
"parameters": [
{
"description": "Product input",
"name": "input",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.Product"
}
"type": "string",
"description": "Product Name",
"name": "name",
"in": "formData",
"required": true
},
{
"type": "string",
"description": "Product Description",
"name": "description",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "Category Id",
"name": "category_id",
"in": "formData",
"required": true
},
{
"type": "integer",
"description": "Product Price",
"name": "price",
"in": "formData",
"required": true
},
{
"type": "file",
"description": "Product Description",
"name": "image",
"in": "formData",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -3793,37 +3816,6 @@
}
}
},
"request.Product": {
"type": "object",
"required": [
"category_id",
"description",
"image",
"price",
"product_name"
],
"properties": {
"category_id": {
"type": "integer"
},
"description": {
"type": "string",
"maxLength": 100,
"minLength": 10
},
"image": {
"type": "string"
},
"price": {
"type": "integer"
},
"product_name": {
"type": "string",
"maxLength": 50,
"minLength": 3
}
}
},
"request.ProductItem": {
"type": "object",
"required": [
Expand Down
54 changes: 24 additions & 30 deletions cmd/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,29 +267,6 @@ definitions:
- offer_id
- product_id
type: object
request.Product:
properties:
category_id:
type: integer
description:
maxLength: 100
minLength: 10
type: string
image:
type: string
price:
type: integer
product_name:
maxLength: 50
minLength: 3
type: string
required:
- category_id
- description
- image
- price
- product_name
type: object
request.ProductItem:
properties:
images:
Expand Down Expand Up @@ -1629,17 +1606,34 @@ paths:
tags:
- Admin Products
post:
consumes:
- application/json
description: API for admin to add a new product
operationId: SaveProduct
parameters:
- description: Product input
in: body
name: input
- description: Product Name
in: formData
name: name
required: true
schema:
$ref: '#/definitions/request.Product'
type: string
- description: Product Description
in: formData
name: description
required: true
type: string
- description: Category Id
in: formData
name: category_id
required: true
type: integer
- description: Product Price
in: formData
name: price
required: true
type: integer
- description: Product Description
in: formData
name: image
required: true
type: file
produces:
- application/json
responses:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/aws/aws-sdk-go v1.44.319
github.com/gin-gonic/gin v1.9.1
github.com/go-playground/validator/v10 v10.14.1
github.com/golang-jwt/jwt v3.2.2+incompatible
Expand Down Expand Up @@ -54,6 +55,7 @@ require (
github.com/jackc/pgx/v5 v5.4.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20O
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/aws/aws-sdk-go v1.44.319 h1:cwynvM8DBwWGzlINTZ6XLkGy5O99wZIS0197j3B61Fs=
github.com/aws/aws-sdk-go v1.44.319/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
Expand Down Expand Up @@ -215,6 +217,10 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
Expand Down Expand Up @@ -419,6 +425,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
Expand Down Expand Up @@ -485,12 +492,14 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -500,6 +509,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
Expand Down Expand Up @@ -668,6 +678,7 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
29 changes: 23 additions & 6 deletions pkg/api/handler/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,40 @@ func (c *ProductHandler) GetAllVariations(ctx *gin.Context) {
// @Description API for admin to add a new product
// @ID SaveProduct
// @Tags Admin Products
// @Accept json
// @Produce json
// @Param input body request.Product{} true "Product input"
// @Param name formData string true "Product Name"
// @Param description formData string true "Product Description"
// @Param category_id formData int true "Category Id"
// @Param price formData int true "Product Price"
// @Param image formData file true "Product Description"
// @Success 200 {object} response.Response{} "successfully product added"
// @Router /admin/products [post]
// @Failure 400 {object} response.Response{} "invalid input"
// @Failure 409 {object} response.Response{} "Product name already exist"
func (p *ProductHandler) SaveProduct(ctx *gin.Context) {

var body request.Product
name, err1 := request.GetFormValuesAsString(ctx, "name")
description, err2 := request.GetFormValuesAsString(ctx, "description")
categoryID, err3 := request.GetFormValuesAsUint(ctx, "category_id")
price, err4 := request.GetFormValuesAsUint(ctx, "price")

if err := ctx.ShouldBindJSON(&body); err != nil {
response.ErrorResponse(ctx, http.StatusBadRequest, BindJsonFailMessage, err, nil)
fileHeader, err5 := ctx.FormFile("image")

err := errors.Join(err1, err2, err3, err4, err5)

if err != nil {
response.ErrorResponse(ctx, http.StatusBadRequest, BindFormValueMessage, err, nil)
return
}

err := p.productUseCase.SaveProduct(ctx, body)
product := request.Product{
Name: name,
Description: description,
CategoryID: categoryID,
Price: price,
ImageFileHeader: fileHeader,
}
err = p.productUseCase.SaveProduct(ctx, product)

if err != nil {
statusCode := http.StatusInternalServerError
Expand Down
Loading

0 comments on commit 68cfbd6

Please sign in to comment.