refactor-controllers #5
@@ -19,7 +19,6 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"easywish/internal/dto"
|
"easywish/internal/dto"
|
||||||
errs "easywish/internal/errors"
|
|
||||||
"easywish/internal/middleware"
|
"easywish/internal/middleware"
|
||||||
"easywish/internal/services"
|
"easywish/internal/services"
|
||||||
"easywish/internal/utils/enums"
|
"easywish/internal/utils/enums"
|
||||||
@@ -105,7 +104,7 @@ func (ctrl *controllerImpl) Setup(group *gin.RouterGroup, log *zap.Logger, auth
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Controller interface {
|
type Controller interface {
|
||||||
Setup()
|
Setup(group *gin.RouterGroup, log *zap.Logger, auth services.AuthService)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRequest[ModelT any](c *gin.Context) (*dto.Request[ModelT], error) {
|
func GetRequest[ModelT any](c *gin.Context) (*dto.Request[ModelT], error) {
|
||||||
@@ -116,6 +115,7 @@ func GetRequest[ModelT any](c *gin.Context) (*dto.Request[ModelT], error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Think hard on a singleton for better performance
|
||||||
validate := validation.NewValidator()
|
validate := validation.NewValidator()
|
||||||
|
|
||||||
if err := validate.Struct(body); err != nil {
|
if err := validate.Struct(body); err != nil {
|
||||||
@@ -130,7 +130,7 @@ func GetRequest[ModelT any](c *gin.Context) (*dto.Request[ModelT], error) {
|
|||||||
c.AbortWithStatusJSON(
|
c.AbortWithStatusJSON(
|
||||||
http.StatusInternalServerError,
|
http.StatusInternalServerError,
|
||||||
gin.H{"error": "Client info was not found"})
|
gin.H{"error": "Client info was not found"})
|
||||||
return nil, errs.ErrClientInfoNotProvided
|
panic("No client_info found in gin context. Does the handler use AuthMiddleware?")
|
||||||
}
|
}
|
||||||
cinfo := cinfoFromCtx.(*dto.ClientInfo)
|
cinfo := cinfoFromCtx.(*dto.ClientInfo)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user