feat(expense): create and display expenses

This commit is contained in:
2021-11-26 01:51:13 +01:00
parent 82d86fb33f
commit 53b0b8c9a2
6 changed files with 71 additions and 24 deletions

View File

@@ -1,7 +1,6 @@
package user
import (
"fmt"
"net/http"
"nos-comptes/handler"
"nos-comptes/internal/storage/dao/postgresql"
@@ -45,7 +44,7 @@ func (hc *Context) ConnectUser(c *gin.Context) {
oauth2Service, err := oauth2.New(&http.Client{})
if oauth2Service == nil {
fmt.Println(err)
utils.GetLoggerFromCtx(c).WithError(err).Error(err)
utils.JSONError(c.Writer, model.ErrInternalServer)
return
}
@@ -53,18 +52,17 @@ func (hc *Context) ConnectUser(c *gin.Context) {
tokenInfoCall.IdToken(authorizationHeaderSplitted[1])
tokenInfo, err := tokenInfoCall.Do()
if err != nil {
utils.GetLogger().WithError(err).Error(err)
utils.GetLoggerFromCtx(c).WithError(err).Error(err)
utils.JSONError(c.Writer, model.ErrBadRequestFormat)
return
}
user, err := hc.service.GetUserFromGoogleID(tokenInfo.UserId)
if err != nil {
utils.GetLogger().WithError(err).Error(err)
if castedError, ok := err.(*model.APIError); ok {
if castedError.Type == model.ErrNotFound.Type {
user, err := hc.service.CreateUserFromGoogleToken(tokenInfo.UserId, tokenInfo.Email)
if err != nil {
fmt.Println(err)
utils.GetLoggerFromCtx(c).WithError(err).Error(err)
utils.JSONError(c.Writer, model.ErrInternalServer)
return
}
@@ -74,6 +72,7 @@ func (hc *Context) ConnectUser(c *gin.Context) {
utils.JSONError(c.Writer, *castedError)
return
}
utils.GetLoggerFromCtx(c).WithError(err).Error(err)
utils.JSONError(c.Writer, model.ErrInternalServer)
return
}
@@ -90,7 +89,7 @@ func (hc *Context) CreateUser(c *gin.Context) {
oauth2Service, err := oauth2.New(&http.Client{})
if oauth2Service == nil {
fmt.Println(err)
utils.GetLogger().WithError(err).Error(err)
utils.JSONError(c.Writer, model.ErrInternalServer)
return
}
@@ -109,7 +108,7 @@ func (hc *Context) CreateUser(c *gin.Context) {
if castedError.Type == model.ErrNotFound.Type {
user, err := hc.service.CreateUserFromGoogleToken(tokenInfo.UserId, tokenInfo.Email)
if err != nil {
fmt.Println(err)
utils.GetLogger().WithError(err).Error(err)
utils.JSONError(c.Writer, model.ErrInternalServer)
return
}
@@ -119,6 +118,7 @@ func (hc *Context) CreateUser(c *gin.Context) {
utils.JSONError(c.Writer, *castedError)
return
}
utils.GetLogger().Info(err)
utils.JSONError(c.Writer, model.ErrInternalServer)
return
}