add b asic endpoint
This commit is contained in:
@@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"nos-comptes/handler"
|
||||
"nos-comptes/internal/account"
|
||||
"nos-comptes/internal/jointaccount"
|
||||
"nos-comptes/internal/storage/dao/postgresql"
|
||||
"nos-comptes/internal/storage/model"
|
||||
"nos-comptes/internal/storage/validators"
|
||||
@@ -13,13 +14,14 @@ import (
|
||||
)
|
||||
|
||||
type Validator struct {
|
||||
accountService *account.Service
|
||||
userService *user.Service
|
||||
jointaccountService *jointaccount.Service
|
||||
accountService *account.Service
|
||||
userService *user.Service
|
||||
*handler.Context
|
||||
}
|
||||
|
||||
func NewValidator(ctx *handler.Context, db *postgresql.DatabasePostgreSQL) *Validator {
|
||||
return &Validator{accountService: account.NewService(account.NewDatabase(db)), userService: user.NewService(user.NewDatabase(db)), Context: ctx}
|
||||
return &Validator{accountService: account.NewService(account.NewDatabase(db)), userService: user.NewService(user.NewDatabase(db)), jointaccountService: jointaccount.NewService(jointaccount.NewDatabase(db)), Context: ctx}
|
||||
}
|
||||
func (v Validator) HasValidUserId(gc *gin.Context) {
|
||||
userId := gc.Param("userId")
|
||||
@@ -108,3 +110,28 @@ func (v Validator) AccountExists(gc *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) HasValidJointAccountId(gc *gin.Context) {
|
||||
accountId := gc.Param("jointaccountId")
|
||||
err := v.Validator.VarCtx(gc, accountId, "uuid4")
|
||||
if err != nil {
|
||||
utils.JSONError(gc.Writer, validators.NewDataValidationAPIError(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (v Validator) JointAccountExists(gc *gin.Context) {
|
||||
userId := gc.Param("userId")
|
||||
accountId := gc.Param("jointaccountId")
|
||||
_, err := v.jointaccountService.GetASpecificJointaccountForUser(userId, accountId)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user