Conversation
wsushmita
suggested changes
Sep 17, 2020
wsushmita
left a comment
There was a problem hiding this comment.
@deepalipawade I have added some comments , pls do requested changes
config/config.go
Outdated
|
|
||
| // JWTExpiryDurationHours - returns duration for jwt expiry in int | ||
| func JWTExpiryDurationHours() int { | ||
| return int(ReadEnvInt("JWT_EXPIRY_DURATION_HOURS")) |
There was a problem hiding this comment.
ReadEnvInt returns int , here you don't need to use int()
db/cart.go
Outdated
| var pids, quantities []int | ||
| var products []Product | ||
|
|
||
| err = s.db.Select(&pids, getCartQuery, user_id) |
There was a problem hiding this comment.
- handle err != nil , log error & return
- Why are you using two query to get data from two tables? add a single query to fetch data from cart
db/cart.go
Outdated
| } | ||
|
|
||
| query, args, err := sqlx.In(getProductsQuery, pids) | ||
| query = s.db.Rebind(query) |
There was a problem hiding this comment.
here don't use sqlx.In with rebind .You can use exec() to fire any query
db/cart.go
Outdated
| for index, product := range products { | ||
| var category, image_urls []string | ||
| err = s.db.Select(&category, getCategoryQuery, product.CategoryId) | ||
| err = s.db.Select(&image_urls, getProductImageQuery, product.Id) |
There was a problem hiding this comment.
use join to get details from other table
db/cart.go
Outdated
| logger.WithField("err", err.Error()).Error("Error listing cart") | ||
| return | ||
| } | ||
| fmt.Println(category, image_urls, index) |
service/cart_http.go
Outdated
| // @Failure 400 {object} | ||
| func getCartHandler(deps Dependencies) http.HandlerFunc { | ||
| return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | ||
| // request_params := mux.Vars(req) |
service/user_http.go
Outdated
| func listUsersHandler(deps Dependencies) http.HandlerFunc { | ||
| return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | ||
| users, err := deps.Store.ListUsers(req.Context()) | ||
| fmt.Println(users) |
service/cart_http.go
Outdated
| cart_products, err := deps.Store.GetCart(req.Context(), int(userID)) | ||
| if err != nil { | ||
| logger.WithField("err", err.Error()).Error("Error fetching data") | ||
| rw.WriteHeader(http.StatusInternalServerError) |
wsushmita
suggested changes
Sep 17, 2020
db/cart.go
Outdated
| return | ||
| } | ||
|
|
||
| for _, row := range joinCartProduct { |
There was a problem hiding this comment.
you are fetching category id for every record, you can join multiple tables using diff where clauses
db/cart.go
Outdated
| return | ||
| } | ||
|
|
||
| err = s.db.Select(&image_urls, getProductImageQuery, row.ProductId) |
20af582 to
8a4496f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tasks to which I contributed and file names
. Create Schema for Cart -
migrations/1599535672_create_cart.up.sql
migrations/1599535672_create_cart.down.sql
Create Hanlder for Cart -
service/cart_http.go
service/cart_http_test.go
service/common_http_test.go
Database Interaction for Cart -
db/cart.go
db/cart_test.go
db/common_test.go
Added GetCart as Storer Interface method -
db/db.go
Added route for cart -
service/router.go