35 lines
574 B
Go
35 lines
574 B
Go
package domain
|
|
|
|
import (
|
|
"backend/pkg/util"
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type OTPRepo interface {
|
|
Create(ctx context.Context, phone string, otp *OTP) error
|
|
Get(ctx context.Context, phone string) (*OTP, error)
|
|
Delete(ctx context.Context, phone string) error
|
|
}
|
|
|
|
type OTP struct {
|
|
ID uuid.UUID
|
|
Code string
|
|
Phone string
|
|
ExpiresAt time.Time
|
|
}
|
|
|
|
func NewOTP(phone string) *OTP {
|
|
return &OTP{
|
|
ID: uuid.New(),
|
|
Code: util.GenOTPCode(),
|
|
Phone: phone,
|
|
}
|
|
}
|
|
|
|
func (o *OTP) IsExpired() bool {
|
|
return time.Now().After(o.ExpiresAt)
|
|
}
|