-
Notifications
You must be signed in to change notification settings - Fork 39
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
First deliverable #6
base: main
Are you sure you want to change the base?
Conversation
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.
Very good deliverable! my comments are mostly about error handling and some code style issues, but other than that this is very good!
Keep at it!
controller/pokemon.go
Outdated
pokemons, err := p.pokemonBusiness.GetAll() | ||
|
||
if err != nil { | ||
c.AbortWithStatus(http.StatusNotFound) |
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.
this is applicable for all endpoints, you must add a return
statement after writing the response/response headers
Gin prevents overriding the status code, but other frameworks might override the 404 with the default status code, http 200 in this case
controller/pokemon.go
Outdated
func (p pokemon) GetPokemonByID(c *gin.Context) { | ||
id, err := strconv.Atoi(c.Params.ByName("pokemonId")) | ||
if err != nil { | ||
c.AbortWithStatus(http.StatusNotFound) |
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.
In case of an error, the API returns a 404 (all endpoints), please use the most appropriate HTTP return code
package model | ||
|
||
type Pokemon struct { | ||
Id int `csv:"ID"` |
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.
Initialisms should be all underscored or all caps, i.e.: ID int
csv:"ID"``
https://github.com/golang/go/wiki/CodeReviewComments#initialisms
controller/pokemon.go
Outdated
c.AbortWithStatus(http.StatusNotFound) | ||
} | ||
pokemon, err := p.pokemonBusiness.GetByID(id) | ||
if err != nil { |
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.
Is a good practice to log the errors in the uppermost layer or where you are handling them and returning something else (recovering from the error and returning a value or returning a different error)
can you please log the error here?
repository/pokemon.go
Outdated
return nil, err | ||
} | ||
if err := gocsv.MarshalFile(&pokemons, pokemonFile); err != nil { | ||
return nil, errors.New("There was a problem accesing to csv file") |
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.
by convention, error strings shouldn't be capitalized
https://github.com/golang/go/wiki/CodeReviewComments#error-strings
No description provided.