50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package request
|
|
|
|
import (
|
|
"enaklo-pos-be/internal/entity"
|
|
"github.com/go-playground/validator/v10"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type CustomerRegister struct {
|
|
Name string `json:"name" validate:"required" binding:"required"`
|
|
Email string `json:"email" validate:"required" binding:"required"`
|
|
PhoneNumber string `json:"phone_number" validate:"required" binding:"required"`
|
|
BirthDate string `json:"birth_date" validate:"required" binding:"required"`
|
|
Password string `json:"password" validate:"required" binding:"required"`
|
|
}
|
|
|
|
func (c *CustomerRegister) Validate() error {
|
|
validate := validator.New()
|
|
if err := validate.Struct(c); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *CustomerRegister) GetBirthdate() (time.Time, error) {
|
|
parsedDate, err := time.Parse("02-01-2006", c.BirthDate)
|
|
if err != nil {
|
|
return time.Time{}, err
|
|
}
|
|
return parsedDate, nil
|
|
}
|
|
|
|
func (c *CustomerRegister) ToEntity() *entity.Customer {
|
|
birthdate, _ := c.GetBirthdate()
|
|
return &entity.Customer{
|
|
Name: c.Name,
|
|
Email: strings.ToLower(c.Email),
|
|
PhoneNumber: c.PhoneNumber,
|
|
Password: c.Password,
|
|
BirthDate: birthdate,
|
|
}
|
|
}
|
|
|
|
type VerifyEmailRequest struct {
|
|
VerificationID string `json:"verification_id" binding:"required"`
|
|
OTPCode string `json:"otp_code" binding:"required"`
|
|
}
|