update
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package customerauth
|
||||
|
||||
import (
|
||||
auth2 "enaklo-pos-be/internal/handlers/request"
|
||||
"enaklo-pos-be/internal/services/v2/customer"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -8,7 +10,6 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"enaklo-pos-be/internal/common/errors"
|
||||
auth2 "enaklo-pos-be/internal/handlers/request"
|
||||
"enaklo-pos-be/internal/handlers/response"
|
||||
"enaklo-pos-be/internal/services"
|
||||
)
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
type AuthHandler struct {
|
||||
service services.Auth
|
||||
userService services.User
|
||||
customerSvc customer.Service
|
||||
}
|
||||
|
||||
func (a *AuthHandler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
@@ -24,12 +26,14 @@ func (a *AuthHandler) Route(group *gin.RouterGroup, jwt gin.HandlerFunc) {
|
||||
authRoute.POST("/forgot-password", a.ForgotPassword)
|
||||
authRoute.POST("/reset-password", jwt, a.ResetPassword)
|
||||
authRoute.POST("/register", a.Register)
|
||||
authRoute.POST("/verify", a.VerifyRegistration)
|
||||
}
|
||||
|
||||
func NewAuthHandler(service services.Auth, userService services.User) *AuthHandler {
|
||||
func NewAuthHandler(service services.Auth, userService services.User, customerSvc customer.Service) *AuthHandler {
|
||||
return &AuthHandler{
|
||||
service: service,
|
||||
userService: userService,
|
||||
customerSvc: customerSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,31 +151,47 @@ func (h *AuthHandler) ResetPassword(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *AuthHandler) Register(c *gin.Context) {
|
||||
var req auth2.UserRegister
|
||||
var req auth2.CustomerRegister
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := auth2.GetMyContext(c)
|
||||
res, err := h.userService.Create(ctx, req.ToEntity())
|
||||
customer, err := h.customerSvc.RegistrationMember(ctx, req.ToEntity())
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
resp := response.UserRegister{
|
||||
ID: res.ID,
|
||||
Name: res.Name,
|
||||
Email: res.Email,
|
||||
Status: string(res.Status),
|
||||
CreatedAt: res.CreatedAt,
|
||||
UpdatedAt: res.UpdatedAt,
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: response.CustomerRegistrationResp{
|
||||
EmailVerificationRequired: true,
|
||||
PhoneVerificationRequired: false,
|
||||
VerificationID: customer.VerificationID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (h *AuthHandler) VerifyRegistration(c *gin.Context) {
|
||||
var req auth2.VerifyEmailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.ErrorWrapper(c, errors.ErrorBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := auth2.GetMyContext(c)
|
||||
err := h.customerSvc.VerifyOTP(ctx, req.VerificationID, req.OTPCode)
|
||||
if err != nil {
|
||||
response.ErrorWrapper(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response.BaseResponse{
|
||||
Success: true,
|
||||
Status: http.StatusOK,
|
||||
Data: resp,
|
||||
Message: "Email verification successful",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user