mekasu0124

Untitled

Jun 12th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. # root/backend/api/models/models.py
  2. from datetime import datetime
  3.  
  4. from pydantic import BaseModel, Field
  5. from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
  6.  
  7. from api.database.database import Base
  8.  
  9. class User(Base):
  10.     __tablename__ = "users"
  11.  
  12.     id = Column(Integer, primary_key=True, index=True)
  13.     first_name = Column(String)
  14.     last_name = Column(String)
  15.     email_address = Column(String, unique=True, index=True)
  16.     username = Column(String, unique=True, index=True)
  17.     phone_number = Column(String)
  18.     password = Column(String)
  19.     date_of_birth = Column(String)
  20.  
  21. class Session(Base):
  22.     __tablename__ = "sessions"
  23.  
  24.     id = Column(Integer, primary_key=True, index=True)
  25.     user_id = Column(Integer, ForeignKey("users.id"))
  26.     token = Column(String, unique=True, index=True)
  27.     expiration_date = Column(DateTime, default=datetime.utcnow)
  28.  
  29. class Login(Base):
  30.     __tablename__ = "logins"
  31.  
  32.     id = Column(Integer, primary_key=True, index=True)
  33.     user_id = Column(Integer, ForeignKey("users.id"))
  34.     username = Column(String, unique=True, index=True)
  35.     password = Column(String)
  36.     created_at = Column(DateTime, default=datetime.utcnow)
  37.  
  38. class UserBase(BaseModel):
  39.     first_name: str = Field(alias="firstName")
  40.     last_name: str = Field(alias="lastName")
  41.     email_address: str = Field(alias="emailAddress")
  42.     phone_number: str = Field(alias="phoneNumber")
  43.     password: str = Field(alias="password")
  44.     date_of_birth: str = Field(alias="dateOfBirth")
  45.  
  46.     class Config:
  47.         allow_population_by_field_name = True
  48.  
  49. class UserModel(UserBase):
  50.     id: int
  51.  
  52. class LoginModel(BaseModel):
  53.     email_address: str = Field(alias="emailAddress")
  54.     password: str = Field(alias="password")
  55.  
  56.     class Config:
  57.         allow_population_by_field_name = True
  58.  
  59. class LoginResponseModel(BaseModel):
  60.     user_name: str = Field(alias="userName")
  61.     logged_in: bool = Field(alias="loggedIn")
  62.  
  63.     class Config:
  64.         allow_population_by_field_name = True
Advertisement
Add Comment
Please, Sign In to add comment