Created
October 14, 2021 02:03
-
-
Save axel-andrade/e6f44d970548987d9314993f9081b5f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package presenters | |
import ( | |
ERROR "go_clean_api/api/shared/constants/errors" | |
"go_clean_api/api/usecases/common" | |
interactor "go_clean_api/api/usecases/login" | |
"net/http" | |
) | |
type LoginPresenter struct{} | |
func (p *LoginPresenter) Show(result *interactor.LoginOutputDTO, err error) common.OutputPort { | |
if err != nil { | |
return p.formatErrOutput(err) | |
} | |
return p.formatSuccessOutput(result) | |
} | |
func (p *LoginPresenter) formatSuccessOutput(result *interactor.LoginOutputDTO) common.OutputPort { | |
var out common.OutputPort | |
out.Data = result | |
out.StatusCode = http.StatusOK | |
return out | |
} | |
func (p *LoginPresenter) formatErrOutput(err error) common.OutputPort { | |
var out common.OutputPort | |
switch err.Error() { | |
case ERROR.USER_NOT_FOUND: | |
out.StatusCode = http.StatusNotFound | |
case ERROR.INVALID_EMAIL, ERROR.INVALID_PASSWORD: | |
out.StatusCode = http.StatusUnprocessableEntity | |
default: | |
out.StatusCode = http.StatusBadRequest | |
} | |
out.Error = err.Error() | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment