Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Migrate to clean arch
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmmartins committed Jul 9, 2024
1 parent 8b7344d commit d28b036
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN go mod download
COPY . .

# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o web cmd/rest/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o web cmd/http/main.go

# Stage 2: Create non-root user in a complete image
FROM alpine:3.19.1 as security_provider
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Miro Board: https://miro.com/app/board/uXjVKVoZwos=/?share_link_id=718027124865

### Go

- [Go Instalation](https://go.dev/doc/install)
- [Go Install](https://go.dev/doc/install)

> Make sure you have Go 1.22.2 or higher
Expand Down Expand Up @@ -59,7 +59,7 @@ Go to http://localhost:8080/swagger/index.html#/ after the application is runnin

- [Go](https://go.dev/)
- [Gin Web Framework](https://gin-gonic.com/) - Routes, JSON validation, Error management, Middleware support
- [PostgreSQL](https://www.postgresql.org/) - Database
- [PostgresSQL](https://www.postgresql.org/) - Database
- [swag](https://github.com/swaggo/swag) - Tool to generate swagger documentation
- [docker](https://www.docker.com/) - Containerization tool
- [docker-compose](https://docs.docker.com/compose/) - Tool to define and run multi-container Docker applications
Expand Down Expand Up @@ -94,7 +94,7 @@ Follow the steps described in the [official documentation](https://github.com/sw
### Generate

```shell
swag init -g cmd/rest/main.go
swag init -g cmd/http/main.go
```

### Access the documentation
Expand Down
9 changes: 4 additions & 5 deletions cmd/rest/main.go → cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package main

import (
"fmt"
"github.com/pangolin-do-golang/tech-challenge/internal/application/cart"
"github.com/pangolin-do-golang/tech-challenge/internal/application/order"
"github.com/pangolin-do-golang/tech-challenge/internal/application/product"
"log"
"os"

"github.com/joho/godotenv"
_ "github.com/pangolin-do-golang/tech-challenge/docs"
dbAdapter "github.com/pangolin-do-golang/tech-challenge/internal/adapters/db"
"github.com/pangolin-do-golang/tech-challenge/internal/adapters/rest/server"
"github.com/pangolin-do-golang/tech-challenge/internal/application/cart"
"github.com/pangolin-do-golang/tech-challenge/internal/application/customer"
"github.com/pangolin-do-golang/tech-challenge/internal/application/order"
"github.com/pangolin-do-golang/tech-challenge/internal/application/product"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
Expand All @@ -30,7 +29,7 @@ func main() {
}

customerRepository := dbAdapter.NewPostgresCustomerRepository(db)
customerService := customer.NewService(customerRepository)
customerService := cart.NewService(customerRepository)

productRepository := dbAdapter.NewPostgresProductRepository(db)
productService := product.NewProductService(productRepository)
Expand Down
6 changes: 4 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,15 @@
"type": "string",
"description": "Name of Product",
"name": "search",
"in": "path"
"in": "path",
"required": true
},
{
"type": "string",
"description": "Category of Product",
"name": "category",
"in": "path"
"in": "path",
"required": true
}
],
"responses": {
Expand Down
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ module github.com/pangolin-do-golang/tech-challenge
go 1.22.2

require (
github.com/gin-gonic/gin v1.9.1
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.9
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.10
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/bytedance/sonic v1.11.5 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.3 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand All @@ -29,7 +29,7 @@ require (
github.com/go-openapi/swag v0.19.15 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
Expand All @@ -45,18 +45,18 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/bytedance/sonic v1.11.5 h1:G00FYjjqll5iQ1PYXynbg/hyzqBqavH8Mo9/oTopd9k=
github.com/bytedance/sonic v1.11.5/go.mod h1:X2PC2giUdj/Cv2lliWFLk6c/DUQok5rViJSemeB0wDw=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.0/go.mod h1:UmRT+IRTGKz/DAkzcEGzyVqQFJ7H9BqwBO3pm9H/+HY=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/cloudwego/base64x v0.1.3 h1:b5J/l8xolB7dyDTTmhJP2oTs5LdrjyrUFuNxdfq5hAg=
github.com/cloudwego/base64x v0.1.3/go.mod h1:1+1K5BUHIQzyapgpF7LwvOGAEDicKtt1umPV+aN8pi8=
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand All @@ -25,6 +27,7 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
Expand All @@ -43,6 +46,7 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
Expand Down Expand Up @@ -95,6 +99,7 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
Expand Down Expand Up @@ -126,10 +131,13 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc=
golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand All @@ -140,6 +148,7 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
Expand All @@ -154,6 +163,7 @@ 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.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
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.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand All @@ -164,6 +174,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
Expand All @@ -174,6 +186,7 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IV
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand All @@ -188,7 +201,11 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8=
gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
8 changes: 4 additions & 4 deletions internal/adapters/db/cart_products.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewPostgresCartProductsRepository(db *gorm.DB) cart.ICartProductRepository
return &PostgresCartProductsRepository{db: db}
}

func (p *PostgresCartProductsRepository) Create(ctx context.Context, cartID uuid.UUID, product *cart.Product) error {
func (p *PostgresCartProductsRepository) Create(_ context.Context, cartID uuid.UUID, product *cart.Product) error {
cartProduct := CartProductsPostgres{
CartID: cartID,
ProductID: product.ProductID,
Expand All @@ -44,7 +44,7 @@ func (p *PostgresCartProductsRepository) Create(ctx context.Context, cartID uuid
return nil
}

func (p *PostgresCartProductsRepository) GetByCartID(ctx context.Context, cartID uuid.UUID) ([]*cart.Product, error) {
func (p *PostgresCartProductsRepository) GetByCartID(_ context.Context, cartID uuid.UUID) ([]*cart.Product, error) {
var cartProducts []CartProductsPostgres
err := p.db.Where("cart_id = ?", cartID).Find(&cartProducts).Error
if err != nil {
Expand All @@ -63,11 +63,11 @@ func (p *PostgresCartProductsRepository) GetByCartID(ctx context.Context, cartID
return products, nil
}

func (p *PostgresCartProductsRepository) DeleteByProductID(ctx context.Context, cartID, productID uuid.UUID) error {
func (p *PostgresCartProductsRepository) DeleteByProductID(_ context.Context, cartID, productID uuid.UUID) error {
return p.db.Delete(&CartProductsPostgres{}, "cart_id = ? AND product_id = ?", cartID, productID).Error
}

func (p *PostgresCartProductsRepository) UpdateProductByProductID(ctx context.Context, cartID, productID uuid.UUID, product *cart.Product) error {
func (p *PostgresCartProductsRepository) UpdateProductByProductID(_ context.Context, cartID, productID uuid.UUID, product *cart.Product) error {
return p.db.Model(&CartProductsPostgres{}).
Where("cart_id = ? AND product_id = ?", cartID, productID).
Updates(map[string]interface{}{
Expand Down
4 changes: 2 additions & 2 deletions internal/adapters/db/order_products.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewPostgresOrderProductsRepository(db *gorm.DB) order.IOrderProductReposito
return &PostgresOrderProductsRepository{db: db}
}

func (p *PostgresOrderProductsRepository) Create(ctx context.Context, orderID uuid.UUID, product *order.Product) error {
func (p *PostgresOrderProductsRepository) Create(_ context.Context, orderID uuid.UUID, product *order.Product) error {
orderProduct := OrderProductPostgres{
OrderID: orderID,
ProductID: product.ProductID,
Expand All @@ -45,7 +45,7 @@ func (p *PostgresOrderProductsRepository) Create(ctx context.Context, orderID uu
return nil
}

func (p *PostgresOrderProductsRepository) GetByOrderID(ctx context.Context, cartID uuid.UUID) ([]*order.Product, error) {
func (p *PostgresOrderProductsRepository) GetByOrderID(_ context.Context, cartID uuid.UUID) ([]*order.Product, error) {
var cartProducts []OrderProductPostgres
err := p.db.Where("order_id = ?", cartID).Find(&cartProducts).Error
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/adapters/rest/controller/order_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func (ctrl OrderController) GetAll(c *gin.Context) {
c.JSON(http.StatusOK, orderSlice)
}

// Get a order by ID
// Get an order by ID
// @Summary Get order by ID
// @Description Get a order by ID
// @Description Get an order by ID
// @Tags Order
// @Param id path string true "ID of the order"
// @Accept json
Expand Down
6 changes: 3 additions & 3 deletions internal/adapters/rest/controller/product_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package controller
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/pangolin-do-golang/tech-challenge/internal/application/product"
"github.com/pangolin-do-golang/tech-challenge/internal/application/cart"
"net/http"
)

type ProductController struct {
service *product.Service
service *cart.Service
}

func NewProductController(service *product.Service) *ProductController {
func NewProductController(service *cart.Service) *ProductController {
return &ProductController{
service: service,
}
Expand Down
3 changes: 2 additions & 1 deletion internal/adapters/rest/handler/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package handler
import (
"github.com/gin-gonic/gin"
"github.com/pangolin-do-golang/tech-challenge/internal/adapters/rest/controller"
"github.com/pangolin-do-golang/tech-challenge/internal/application/cart"
"github.com/pangolin-do-golang/tech-challenge/internal/application/order"
)

type OrderHandler struct {
service *order.Service
service *cart.Service
}

func RegisterOrderHandlers(router *gin.Engine, service order.IOrderService) {
Expand Down
4 changes: 2 additions & 2 deletions internal/adapters/rest/handler/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package handler
import (
"github.com/gin-gonic/gin"
"github.com/pangolin-do-golang/tech-challenge/internal/adapters/rest/controller"
"github.com/pangolin-do-golang/tech-challenge/internal/application/product"
"github.com/pangolin-do-golang/tech-challenge/internal/application/cart"
)

func RegisterProductHandlers(router *gin.Engine, service *product.Service) {
func RegisterProductHandlers(router *gin.Engine, service *cart.Service) {
productController := controller.NewProductController(service)

router.GET("/product", productController.Search)
Expand Down
5 changes: 2 additions & 3 deletions internal/adapters/rest/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import (
"github.com/pangolin-do-golang/tech-challenge/internal/application/cart"
"github.com/pangolin-do-golang/tech-challenge/internal/application/customer"
"github.com/pangolin-do-golang/tech-challenge/internal/application/order"
"github.com/pangolin-do-golang/tech-challenge/internal/application/product"
)

type RestServer struct {
orderService order.IOrderService
productService *product.Service
productService *cart.Service
cartService cart.IService
customerService customer.IService
}

type RestServerOptions struct {
OrderService order.IOrderService
ProductService *product.Service
ProductService *cart.Service
CartService cart.IService
CustomerService customer.IService
}
Expand Down
Loading

0 comments on commit d28b036

Please sign in to comment.