Skip to content

Conversation

@pari-27
Copy link

@pari-27 pari-27 commented Sep 15, 2020

The code consist :
Update by ID for user.
GetById for user

@pari-27 pari-27 requested a review from mohitpm September 15, 2020 11:08
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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename userList to users

Copy link
Author

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) {
Copy link

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)

Copy link
Author

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)
Copy link

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

Copy link
Author

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"
Copy link

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"
Copy link

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

return
}

user.Validate()
Copy link

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
}

Copy link
Author

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

Copy link

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) {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove new line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants