initial commit
This commit is contained in:
291
internal/dto/auth.go
Normal file
291
internal/dto/auth.go
Normal file
@@ -0,0 +1,291 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"base/internal/pkg/oauth"
|
||||
"base/pkg/validation"
|
||||
)
|
||||
|
||||
type RegisterRequest struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
}
|
||||
|
||||
func (*RegisterRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"email": validation.Rule{
|
||||
Field: "email",
|
||||
Type: validation.ValidationTypeEmail,
|
||||
Required: true,
|
||||
},
|
||||
"password": validation.Rule{
|
||||
Field: "password",
|
||||
Type: validation.ValidationTypeString,
|
||||
MinLength: validation.IntPtr(8),
|
||||
MaxLength: validation.IntPtr(32),
|
||||
Required: true,
|
||||
},
|
||||
"first_name": validation.Rule{
|
||||
Field: "first_name",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
"last_name": validation.Rule{
|
||||
Field: "last_name",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
"phone_number": validation.Rule{
|
||||
Field: "phone_number",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type LoginRequest struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func (*LoginRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"email": validation.Rule{
|
||||
Field: "email",
|
||||
Type: validation.ValidationTypeEmail,
|
||||
Required: true,
|
||||
},
|
||||
"password": validation.Rule{
|
||||
Field: "password",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type TokenResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
|
||||
func (*TokenResponse) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"access_token": validation.Rule{
|
||||
Field: "access_token",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
"refresh_token": validation.Rule{
|
||||
Field: "refresh_token",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type RefreshTokenRequest struct {
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
|
||||
func (*RefreshTokenRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"refresh_token": validation.Rule{
|
||||
Field: "refresh_token",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type SendVerificationEmailRequest struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
func (*SendVerificationEmailRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"email": validation.Rule{
|
||||
Field: "email",
|
||||
Type: validation.ValidationTypeEmail,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type SetupProfileRequest struct {
|
||||
Handle string `json:"handle"`
|
||||
RoleID uuid.UUID `json:"role_id"`
|
||||
RoleLevel string `json:"role_level"`
|
||||
ShortDescription string `json:"short_description"`
|
||||
}
|
||||
|
||||
func (*SetupProfileRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"handle": validation.Rule{
|
||||
Field: "handle",
|
||||
Type: validation.ValidationTypeString,
|
||||
MinLength: validation.IntPtr(2),
|
||||
MaxLength: validation.IntPtr(80),
|
||||
Required: true,
|
||||
},
|
||||
"role_id": validation.Rule{
|
||||
Field: "role_id",
|
||||
Type: validation.ValidationTypeUUID,
|
||||
Required: false,
|
||||
},
|
||||
"role_level": validation.Rule{
|
||||
Field: "role_level",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: false,
|
||||
},
|
||||
"short_description": validation.Rule{
|
||||
Field: "short_description",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type VerifyAccountRequest struct {
|
||||
Email string `json:"email"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
func (*VerifyAccountRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"email": validation.Rule{
|
||||
Field: "email",
|
||||
Type: validation.ValidationTypeEmail,
|
||||
Required: true,
|
||||
},
|
||||
"code": validation.Rule{
|
||||
Field: "code",
|
||||
Type: validation.ValidationTypeString,
|
||||
MinLength: validation.IntPtr(6),
|
||||
MaxLength: validation.IntPtr(6),
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type OAuthRedirectURLRequest struct {
|
||||
Provider oauth.Provider `json:"provider"`
|
||||
}
|
||||
|
||||
func (*OAuthRedirectURLRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"provider": validation.Rule{
|
||||
Field: "provider",
|
||||
Path: "provider",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type OAuthRedirectURLResponse struct {
|
||||
RedirectURL string `json:"redirect_url"`
|
||||
}
|
||||
|
||||
func (*OAuthRedirectURLResponse) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"redirect_url": validation.Rule{
|
||||
Field: "redirect_url",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type OAuthCallbackRequest struct {
|
||||
Provider oauth.Provider `json:"provider"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
func (*OAuthCallbackRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"provider": validation.Rule{
|
||||
Field: "provider",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
"code": validation.Rule{
|
||||
Field: "code",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type OAuthCallbackResponse struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
IsNewUser bool `json:"is_new_user"`
|
||||
}
|
||||
|
||||
func (*OAuthCallbackResponse) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"access_token": validation.Rule{
|
||||
Field: "access_token",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
"refresh_token": validation.Rule{
|
||||
Field: "refresh_token",
|
||||
Type: validation.ValidationTypeString,
|
||||
Required: true,
|
||||
},
|
||||
"is_new_user": validation.Rule{
|
||||
Field: "is_new_user",
|
||||
Type: validation.ValidationTypeBool,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type SendResetPasswordEmailRequest struct {
|
||||
Email string `json:"email"`
|
||||
}
|
||||
|
||||
func (*SendResetPasswordEmailRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"email": validation.Rule{
|
||||
Field: "email",
|
||||
Type: validation.ValidationTypeEmail,
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type ResetPasswordRequest struct {
|
||||
Email string `json:"email"`
|
||||
Code string `json:"code"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func (*ResetPasswordRequest) Schema() validation.Schema {
|
||||
return validation.Schema{
|
||||
"email": validation.Rule{
|
||||
Field: "email",
|
||||
Type: validation.ValidationTypeEmail,
|
||||
Required: true,
|
||||
},
|
||||
"code": validation.Rule{
|
||||
Field: "code",
|
||||
Type: validation.ValidationTypeString,
|
||||
MinLength: validation.IntPtr(6),
|
||||
MaxLength: validation.IntPtr(6),
|
||||
Required: true,
|
||||
},
|
||||
"password": validation.Rule{
|
||||
Field: "password",
|
||||
Type: validation.ValidationTypeString,
|
||||
MinLength: validation.IntPtr(8),
|
||||
MaxLength: validation.IntPtr(32),
|
||||
Required: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user