odapi/app/schemas.py

168 lines
3.4 KiB
Python

from datetime import datetime, timedelta
from secrets import randbits, token_hex
from typing import Optional
from fastapi import Query
from pydantic import BaseModel, EmailStr
class UserBase(BaseModel):
email: EmailStr
device_id: str
lang_type: int = Query(None, ge=1, le=2)
user_type: int = Query(None, ge=1, le=2)
class UserCreate(UserBase):
full_name: str
password: str
gender: int = Query(None, ge=1, le=3)
mobile: str = Query(None, min_length=8, max_length=13)
user_image: Optional[str] = None
device_type: int = Query(None, ge=1, le=2)
city_id: int
access_key: str = token_hex()
otp: int = randbits(20)
otp_valid_time: datetime = datetime.now() + timedelta(minutes=10)
class Config:
orm_mode = True
class UserCreateResponse(UserBase):
id: int
full_name: str
password: str
gender: int = Query(None, ge=1, le=3)
mobile: str = Query(None, min_length=8, max_length=13)
user_image: Optional[str] = None
device_type: int = Query(None, ge=1, le=2)
access_key: str
otp: int
otp_valid_time: datetime
status: int = Query(None, ge=0, le=1)
admin_status: int = Query(None, ge=0, le=1)
created: datetime
updated: datetime = Query(None)
class Config:
orm_mode = True
class UserLogin(UserBase):
password: str
class Config:
orm_mode = True
class UserLoginResponse(UserBase):
pass
class Config:
orm_mode = True
class SocialLogin(UserBase):
type: int = Query(None, ge=1, le=2)
social_id: str
device_type: int = Query(None, ge=1, le=2)
mobile: str = Query(None, min_length=8, max_length=13)
full_name: str
class Config:
orm_mode = True
class OTPBase(BaseModel):
access_key: str
otp: int
class Config:
orm_mode = True
class OTPVerify(OTPBase):
pass
class Config:
orm_mode = True
class OTPVerifyResponse(OTPBase):
id: int
full_name: str
email: EmailStr
gender: int = Query(None, ge=1, le=3)
mobile: str = Query(None, min_length=8, max_length=13)
otp_valid_time: datetime
lang_type: int = Query(None, ge=1, le=2)
status: int = Query(None, ge=0, le=1)
device_type: int = Query(None, ge=1, le=2)
created: datetime
updated: datetime = Query(None)
class Config:
orm_mode = True
class OTPResend(BaseModel):
email: EmailStr
otp: int = randbits(20)
otp_valid_time: datetime = datetime.now() + timedelta(minutes=10)
class Config:
orm_mode = True
class OTPResendResponse(UserCreateResponse):
pass
class Config:
orm_mode = True
class ForgotPassword(OTPResend):
pass
class Config:
orm_mode = True
class ResetPassword(ForgotPassword):
password: str
class Config:
orm_mode = True
class ForgotPasswordResponse(BaseModel):
otp: int
mobile: str = Query(None, min_length=8, max_length=13)
message: str = "The OTP has been sent to you via SMS"
class Config:
orm_mode = True
class ResetPasswordResponse(BaseModel):
message: str = "The password has been updated"
class Config:
orm_mode = True
class MatchesList(BaseModel):
access_key: str
city_id: int
latitude: str
longitude: str
type: Optional[int] = Query(0, ge=0, le=2)
class Config:
orm_mode = True
class MatchesResponse(BaseModel):
pass