update config
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package customerauth
|
||||
|
||||
import (
|
||||
"enaklo-pos-be/internal/entity"
|
||||
auth2 "enaklo-pos-be/internal/handlers/request"
|
||||
"enaklo-pos-be/internal/services/member"
|
||||
"enaklo-pos-be/internal/services/v2/auth"
|
||||
"enaklo-pos-be/internal/services/v2/customer"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
@@ -11,23 +13,24 @@ import (
|
||||
|
||||
"enaklo-pos-be/internal/common/errors"
|
||||
"enaklo-pos-be/internal/handlers/response"
|
||||
"enaklo-pos-be/internal/services"
|
||||
)
|
||||
|
||||
type AuthHandler struct {
|
||||
service auth.Service
|
||||
userService services.User
|
||||
customerSvc customer.Service
|
||||
service auth.Service
|
||||
memberSvc member.RegistrationService
|
||||
}
|
||||
|
||||
func (a *AuthHandler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
authRoute := group.Group("/auth")
|
||||
authRoute.POST("/login", a.AuthLogin)
|
||||
authRoute.POST("/register", a.Registration)
|
||||
authRoute.POST("/verify-otp", a.VerifyOTP)
|
||||
}
|
||||
|
||||
func NewAuthHandler(service auth.Service) *AuthHandler {
|
||||
func NewAuthHandler(service auth.Service, memberSvc member.RegistrationService) *AuthHandler {
|
||||
return &AuthHandler{
|
||||
service: service,
|
||||
service: service,
|
||||
memberSvc: memberSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,3 +63,75 @@ func (h *AuthHandler) AuthLogin(c *gin.Context) {
|
||||
Data: resp,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *AuthHandler) Registration(c *gin.Context) {
|
||||
ctx := auth2.GetMyContext(c)
|
||||
userID := ctx.RequestedBy()
|
||||
|
||||
var req auth2.InitiateRegistrationRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(req); err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
birthDate, err := req.GetBirthdate()
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
memberReq := &entity.MemberRegistrationRequest{
|
||||
Name: req.Name,
|
||||
Email: req.Email,
|
||||
Phone: req.Phone,
|
||||
BirthDate: birthDate,
|
||||
CashierID: userID,
|
||||
Password: req.Password,
|
||||
}
|
||||
|
||||
result, err := h.memberSvc.InitiateRegistration(ctx, memberReq)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.MapToMemberRegistrationResponse(result),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *AuthHandler) VerifyOTP(c *gin.Context) {
|
||||
ctx := auth2.GetMyContext(c)
|
||||
|
||||
var req auth2.VerifyOTPRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
validate := validator.New()
|
||||
if err := validate.Struct(req); err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.memberSvc.VerifyOTP(ctx, req.Token, req.OTP)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.MapToMemberVerificationResponse(result.Auth),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user