feat: middleware for request body parsing, validation and authentication;
feat: helper function for getting request info from gin context
This commit is contained in:
@@ -21,10 +21,12 @@ import (
|
||||
"easywish/internal/middleware"
|
||||
"easywish/internal/models"
|
||||
"easywish/internal/services"
|
||||
"easywish/internal/utils"
|
||||
"easywish/internal/utils/enums"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AuthController interface {
|
||||
@@ -39,10 +41,11 @@ type AuthController interface {
|
||||
|
||||
type authControllerImpl struct {
|
||||
authService services.AuthService
|
||||
log *zap.Logger
|
||||
}
|
||||
|
||||
func NewAuthController(as services.AuthService) AuthController {
|
||||
return &authControllerImpl{authService: as}
|
||||
func NewAuthController(_log *zap.Logger, as services.AuthService) AuthController {
|
||||
return &authControllerImpl{log: _log, authService: as}
|
||||
}
|
||||
|
||||
// Login implements AuthController.
|
||||
@@ -96,14 +99,14 @@ func (a *authControllerImpl) Refresh(c *gin.Context) {
|
||||
// @Router /auth/registrationBegin [post]
|
||||
func (a *authControllerImpl) RegistrationBegin(c *gin.Context) {
|
||||
|
||||
var request models.RegistrationBeginRequest
|
||||
|
||||
if err := c.ShouldBindJSON(&request); err != nil {
|
||||
request, ok := utils.GetRequest[models.RegistrationBeginRequest](c)
|
||||
if !ok {
|
||||
c.Status(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := a.authService.RegistrationBegin(request)
|
||||
_, err := a.authService.RegistrationBegin(request.Body)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user