fix: Setup interface mismatch;

refactor: GetRequest now panics on missing client_info since it is only supposed to be used on handlers behind AuthMiddleware
This commit is contained in:
2025-07-17 17:52:12 +03:00
parent 7298ab662f
commit f9d7439def

View File

@@ -19,7 +19,6 @@ package controllers
import (
"easywish/internal/dto"
errs "easywish/internal/errors"
"easywish/internal/middleware"
"easywish/internal/services"
"easywish/internal/utils/enums"
@@ -105,7 +104,7 @@ func (ctrl *controllerImpl) Setup(group *gin.RouterGroup, log *zap.Logger, auth
}
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) {
@@ -116,6 +115,7 @@ func GetRequest[ModelT any](c *gin.Context) (*dto.Request[ModelT], error) {
return nil, err
}
// TODO: Think hard on a singleton for better performance
validate := validation.NewValidator()
if err := validate.Struct(body); err != nil {
@@ -130,7 +130,7 @@ func GetRequest[ModelT any](c *gin.Context) (*dto.Request[ModelT], error) {
c.AbortWithStatusJSON(
http.StatusInternalServerError,
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)