Skip to content
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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rmonroy-wiz
Copy link

No description provided.

@rmonroy-wiz rmonroy-wiz marked this pull request as draft May 11, 2022 16:26
Copy link

@makkoman makkoman left a 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!

pokemons, err := p.pokemonBusiness.GetAll()

if err != nil {
c.AbortWithStatus(http.StatusNotFound)

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

func (p pokemon) GetPokemonByID(c *gin.Context) {
id, err := strconv.Atoi(c.Params.ByName("pokemonId"))
if err != nil {
c.AbortWithStatus(http.StatusNotFound)

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"`

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

c.AbortWithStatus(http.StatusNotFound)
}
pokemon, err := p.pokemonBusiness.GetByID(id)
if err != nil {

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?

return nil, err
}
if err := gocsv.MarshalFile(&pokemons, pokemonFile); err != nil {
return nil, errors.New("There was a problem accesing to csv file")

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

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.

3 participants