Open
Conversation
mohitpm
reviewed
Sep 15, 2020
db/db.go
Outdated
| //Create(context.Context, User) error | ||
| //GetUser(context.Context) (User, error) | ||
| //Delete(context.Context, string) error | ||
| ListUsers(ctx context.Context) (userList []User, err error) |
db/user.go
Outdated
| } | ||
|
|
||
| //Validate function for user | ||
| func (user *User) Validate() (valid bool) { |
There was a problem hiding this comment.
convert prototype of func
From: func (user *User) Validate() (valid bool)
To: func (user *User) Validate() (err error)
db/user.go
Outdated
|
|
||
| //Validate function for user | ||
| func (user *User) Validate() (valid bool) { | ||
| fieldErrors := make(map[string]string) |
db/user.go
Outdated
| fieldErrors := make(map[string]string) | ||
|
|
||
| if user.FirstName == "" { | ||
| fieldErrors["name"] = "Can't be blank" |
There was a problem hiding this comment.
use return errors.New("email can't be blank")
db/user.go
Outdated
| fieldErrors["name"] = "Can't be blank" | ||
| } | ||
| if user.LastName == "" { | ||
| fieldErrors["LastName"] = "Can't be blank" |
There was a problem hiding this comment.
same here are & apply it to rest of the func
service/user_http.go
Outdated
| return | ||
| } | ||
|
|
||
| user.Validate() |
There was a problem hiding this comment.
use
err = user.Validate()
if err != niil {
rw.WriteHeader(http.StatusBadRequest)
repsonse(rw, http.StatusBadRequest, errorResponse{
Error: messageObject{
Message: err.Error(),
},
})
logger.WithField("err", err.Error()).Error("error while validating user's profile")
return
}
db/user.go
Outdated
| country, | ||
| state, | ||
| city | ||
|
|
db/user.go
Outdated
| } | ||
|
|
||
| func (s *pgStore) UpdateUserByID(ctx context.Context, user User, userID int) (err error) { | ||
|
|
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.
The code consist :
Update by ID for user.
GetById for user