Skip to content

Validate user#496

Open
myanhtruong304 wants to merge 1 commit intodevelopfrom
chore/validate-user
Open

Validate user#496
myanhtruong304 wants to merge 1 commit intodevelopfrom
chore/validate-user

Conversation

@myanhtruong304
Copy link
Contributor

@myanhtruong304 myanhtruong304 commented Nov 10, 2022

  • Validate user before get user quests list, post quest progres, post claim quest. If userID was not exist in users table, quests would not be generate/get.

- Get user quests list with invalid user_id
Screen Shot 2022-11-11 at 18 28 06

- Post user quest progress list with invalid user_id/action
Screen Shot 2022-11-11 at 18 30 00
Screen Shot 2022-11-11 at 19 53 03

- Post claim quest with invalid user_id/quest_id
Screen Shot 2022-11-11 at 19 55 14
Screen Shot 2022-11-11 at 19 55 30

Comment on lines +212 to +226
//validate quest action
err_action := e.validateQuestAction(string(log.Action))
// validate user
err_user := e.validateUser(log.UserID)

if err_action != nil && err_user == nil {
return err_action
}
if err_action == nil && err_user != nil {
return err_user
}
if err_action != nil && err_user != nil {
return errors.New(err_action.Error() + ", " + err_user.Error())
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

why need to have 3 cases here?

Suggested change
//validate quest action
err_action := e.validateQuestAction(string(log.Action))
// validate user
err_user := e.validateUser(log.UserID)
if err_action != nil && err_user == nil {
return err_action
}
if err_action == nil && err_user != nil {
return err_user
}
if err_action != nil && err_user != nil {
return errors.New(err_action.Error() + ", " + err_user.Error())
}
if err := e.validateQuestAction(string(log.Action)); err != nil {
return err
}
if err := e.validateUser(log.UserID); err != nil {
return err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To notify user when they failed to call the API due to invalid fields (action, user_id, quest_id) in their requests, instead of returning null or nothing.

Comment on lines +356 to +370
//validate quest id
err_id := e.validateQuestID(listQ.QuestID)
// validate user
err_user := e.validateUser(*listQ.UserID)

if err_id != nil && err_user == nil {
return nil, err_id
}
if err_id == nil && err_user != nil {
return nil, err_user
}
if err_id != nil && err_user != nil {
return nil, errors.New(err_id.Error() + ", " + err_user.Error())
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, this endpoint will return data: null if user failed to call API.

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

Comments