-
Notifications
You must be signed in to change notification settings - Fork 4
update and getById for user #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename userList to users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
db/user.go
Outdated
| } | ||
|
|
||
| //Validate function for user | ||
| func (user *User) Validate() (valid bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convert prototype of func
From: func (user *User) Validate() (valid bool)
To: func (user *User) Validate() (err error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
db/user.go
Outdated
|
|
||
| //Validate function for user | ||
| func (user *User) Validate() (valid bool) { | ||
| fieldErrors := make(map[string]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to create map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code
db/user.go
Outdated
| country, | ||
| state, | ||
| city | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remave newline
db/user.go
Outdated
| } | ||
|
|
||
| func (s *pgStore) UpdateUserByID(ctx context.Context, user User, userID int) (err error) { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove new line
The code consist :
Update by ID for user.
GetById for user