This commit is contained in:
2021-11-17 23:44:20 +01:00
parent 7bf8db8050
commit e05bd1c743
4 changed files with 66 additions and 3 deletions

View File

@@ -63,7 +63,6 @@ func (c *Context) CreateAccountOfUser(gc *gin.Context) {
utils2.JSONError(gc.Writer, validators.NewDataValidationAPIError(err))
return
}
utils.GetLogger().Info(userId)
_, err = c.userService.GetUserById(userId)
if e, ok := err.(*model.APIError); ok {
utils.GetLogger().Info(err)
@@ -111,7 +110,57 @@ func (c *Context) CreateAccountOfUser(gc *gin.Context) {
return
}
func (c *Context) DeleteAccountOfUser(context *gin.Context) {
func (c *Context) DeleteAccountOfUser(gc *gin.Context) {
userId := gc.Param("userId")
err := c.Validator.VarCtx(gc, userId, "uuid4")
if err != nil {
utils2.JSONError(gc.Writer, validators.NewDataValidationAPIError(err))
return
}
accountId := gc.Param("accountId")
err = c.Validator.VarCtx(gc, userId, "uuid4")
if err != nil {
utils2.JSONError(gc.Writer, validators.NewDataValidationAPIError(err))
return
}
accountParam, err := c.userService.GetUserById(userId)
if e, ok := err.(*model.APIError); ok {
utils.GetLogger().Info(err)
utils.GetLoggerFromCtx(gc).WithError(err).WithField("type", e.Type).Error("error GetUser: get user error")
utils.JSONErrorWithMessage(gc.Writer, *e, e.Description)
return
} else if err != nil {
utils.GetLoggerFromCtx(gc).WithError(err).Error("error while get user")
utils.JSONError(gc.Writer, model.ErrInternalServer)
return
}
googleUserId, exists := gc.Get("googleUserId")
if exists == false {
utils.GetLoggerFromCtx(gc).Error("error while getting google user id")
utils.JSONError(gc.Writer, model.ErrInternalServer)
return
}
acc, err := c.userService.GetUserFromGoogleID(googleUserId.(string))
if e, ok := err.(*model.APIError); ok {
utils.GetLogger().Info(err)
utils.GetLoggerFromCtx(gc).WithError(err).WithField("type", e.Type).Error("error GetUserFromGoogleID: get user from google user id")
utils.JSONErrorWithMessage(gc.Writer, *e, e.Description)
return
} else if err != nil {
utils.GetLoggerFromCtx(gc).WithError(err).Error("error while get user from google user id")
utils.JSONError(gc.Writer, model.ErrInternalServer)
return
}
if acc == nil || acc.ID != accountParam.ID {
utils.GetLoggerFromCtx(gc).WithError(err).Error("User in path doesn't match authenticated user")
utils.JSONError(gc.Writer, model.ErrBadRequestFormat)
return
}
c.service.DeleteAccountOfUser(userId, accountId)
}