chore: migrate to gitea
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"budget/internal/storage/model"
|
||||
"budget/internal/utils"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/storage/model"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/api/oauth2/v1"
|
||||
)
|
||||
@@ -19,7 +19,7 @@ func ValidateOAuthToken(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
oauth2Service, err := oauth2.New(&http.Client{})
|
||||
oauth2Service, err := oauth2.NewService(c)
|
||||
if oauth2Service == nil {
|
||||
fmt.Println(err)
|
||||
utils.JSONError(c.Writer, model.ErrInternalServer)
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"budget/handler"
|
||||
"budget/internal/account"
|
||||
"budget/internal/jointaccount"
|
||||
"budget/internal/storage/dao/postgresql"
|
||||
"budget/internal/storage/model"
|
||||
"budget/internal/storage/validators"
|
||||
"budget/internal/user"
|
||||
"budget/internal/utils"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/handler"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/account"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/storage/dao/postgresql"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/storage/model"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/storage/validators"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/user"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Validator struct {
|
||||
jointaccountService *jointaccount.Service
|
||||
accountService *account.Service
|
||||
userService *user.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)), jointaccountService: jointaccount.NewService(jointaccount.NewDatabase(db)), Context: ctx}
|
||||
return &Validator{accountService: account.NewService(account.NewDatabase(db)), userService: user.NewService(user.NewDatabase(db)), Context: ctx}
|
||||
}
|
||||
func (v Validator) HasValidUserId(gc *gin.Context) {
|
||||
userId := gc.Param("userId")
|
||||
@@ -62,7 +60,7 @@ func (v Validator) UserdIdMatchOAuthToken(gc *gin.Context) {
|
||||
return
|
||||
}
|
||||
googleUserId, exists := gc.Get("googleUserId")
|
||||
if exists == false {
|
||||
if !exists {
|
||||
utils.GetLoggerFromCtx(gc).Error("error while getting google user id")
|
||||
utils.JSONError(gc.Writer, model.ErrInternalServer)
|
||||
return
|
||||
@@ -110,28 +108,3 @@ 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