Skip to content

Commit

Permalink
Added check for the experience level and ensured 403 forbidden is rep…
Browse files Browse the repository at this point in the history
…resented in the docs
  • Loading branch information
justinfarrelldev committed Aug 29, 2024
1 parent 7c78557 commit 45871d9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const docTemplate = `{
"description": "Bad Request",
"schema": {}
},
"403": {
"description": "Forbidden",
"schema": {}
},
"500": {
"description": "Internal Server Error",
"schema": {}
Expand Down
4 changes: 4 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"description": "Bad Request",
"schema": {}
},
"403": {
"description": "Forbidden",
"schema": {}
},
"500": {
"description": "Internal Server Error",
"schema": {}
Expand Down
3 changes: 3 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ paths:
"400":
description: Bad Request
schema: {}
"403":
description: Forbidden
schema: {}
"500":
description: Internal Server Error
schema: {}
Expand Down
7 changes: 7 additions & 0 deletions internal/account/create_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func isEmailValid(email string, db *sql.DB) (bool, error) {
// @Param body body CreateAccountArgs true "account creation request body"
// @Success 201 {string} string "Account successfully created"
// @Failure 400 {object} error "Bad Request"
// @Failure 403 {object} error "Forbidden"
// @Failure 500 {object} error "Internal Server Error"
// @Router /account/create_account [post]
func CreateAccount(w http.ResponseWriter, r *http.Request, db *sql.DB) error {
Expand All @@ -90,6 +91,12 @@ func CreateAccount(w http.ResponseWriter, r *http.Request, db *sql.DB) error {
return errors.New("an error occurred while decoding the request body:" + err.Error())
}

if account.Account.ExperienceLevel < 0 || account.Account.ExperienceLevel > 5 {
w.WriteHeader(http.StatusBadRequest)

return errors.New("experience_level must be between 0 and 5 (0=easy, 5=impossible)")
}

if account.Password == "" {
w.WriteHeader(http.StatusBadRequest)

Expand Down

0 comments on commit 45871d9

Please sign in to comment.