0.1.1
This commit is contained in:
0
.gitea/workflows/ci.yml
Normal file
0
.gitea/workflows/ci.yml
Normal file
0
ansible/deploy.yml
Normal file
0
ansible/deploy.yml
Normal file
0
ansible/inventory.ini
Normal file
0
ansible/inventory.ini
Normal file
0
ansible/secrets.yml
Normal file
0
ansible/secrets.yml
Normal file
46
src/models/database_models/model.py
Normal file
46
src/models/database_models/model.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from sqlalchemy import Table, create_engine, String, Boolean, MetaData, Column, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, DeclarativeBase, relationship
|
||||
from uuid import UUID, uuid4
|
||||
engine = create_engine("sqlite:///DB/database.db", echo=True)
|
||||
|
||||
'''remember as a boilerplate, or just cp/pst'''
|
||||
class Model(DeclarativeBase):
|
||||
metadata = MetaData(naming_convention={
|
||||
"ix": "ix_%(column_0_label)s",
|
||||
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
||||
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
"pk": "pk_%(table_name)s",
|
||||
})
|
||||
|
||||
class User(Model):
|
||||
__tablename__ = "users"
|
||||
|
||||
id:Mapped[UUID] = mapped_column(default=uuid4,primary_key=True)
|
||||
first_name:Mapped[str] = mapped_column(String(64), index=True)
|
||||
last_name:Mapped[str]=mapped_column(String(64), index=True)
|
||||
middle_name:Mapped[str]=mapped_column(String(64), index=True)
|
||||
email:Mapped[str]=mapped_column(String(255), index=True, unique=True)
|
||||
status:Mapped[bool]=mapped_column(Boolean)
|
||||
hashed_password:Mapped[str]=mapped_column(String(255))
|
||||
|
||||
permissions:Mapped[list["Permissions"]]=relationship(secondary="user_permission", back_populates="user", lazy="selectin")
|
||||
def __repr__(self) -> str:
|
||||
return f"ID: {self.id}, Name: {self.first_name}, Status: {self.status}"
|
||||
|
||||
user_permission = Table(
|
||||
"user_permission",
|
||||
Model.metadata,
|
||||
Column("user_id", ForeignKey("users.id"), primary_key=True),
|
||||
Column("permission_id", ForeignKey("permissions.id"), primary_key=True),
|
||||
)
|
||||
|
||||
class Permissions(Model):
|
||||
__tablename__ = "permissions"
|
||||
|
||||
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
||||
permission:Mapped[str]=mapped_column(String(255), unique=True)
|
||||
|
||||
user:Mapped[list['User']]=relationship(secondary="user_permission", back_populates="permissions")
|
||||
def __repr__(self)->str:
|
||||
return f"ID: {self.id}, Permissions: {self.permission}"
|
||||
52
src/models/pydantic_models/model.py
Normal file
52
src/models/pydantic_models/model.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from typing import Annotated
|
||||
from pydantic import BaseModel, EmailStr, Field
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
class Base(BaseModel):
|
||||
pass
|
||||
|
||||
class UserCreate(Base):
|
||||
|
||||
first_name:Annotated[str, Field(..., max_length=64,description="first name of the user")]
|
||||
last_name:Annotated[str, Field(...,max_length=64, description="last name of the user")]
|
||||
middle_name:Annotated[str, Field(...,max_length=64, description="middle name of the user")]
|
||||
email:Annotated[EmailStr, Field(...,min_length=5, max_length=255, description="email of the user")]
|
||||
plain_password:Annotated[str, Field(...,min_length=8,max_length=72, description="plain password of the user")]
|
||||
status:Annotated[bool, Field(..., description="status of the user")]
|
||||
permissions:Annotated[list[str], Field(..., description="permissions of the user")]
|
||||
permission_groups:Annotated[list[str], Field(..., description="permissions groups of the user")]
|
||||
|
||||
class UserOut(Base):
|
||||
|
||||
id:Annotated[UUID, Field(..., description="Id of the user")]
|
||||
first_name:Annotated[str, Field(..., max_length=64,description="first name of the user")]
|
||||
last_name:Annotated[str, Field(..., max_length=64,description="last name of the user")]
|
||||
middle_name:Annotated[str, Field(..., max_length=64, description="middle name of the user")]
|
||||
email:Annotated[EmailStr, Field(...,min_length=5, max_length=255, description="email of the user")]
|
||||
status:Annotated[bool, Field(..., description="status of the user")]
|
||||
permissions:Annotated[list[str], Field(..., description="permissions of the user")]
|
||||
permission_groups:Annotated[list[str], Field(..., description="permissions groups of the user")]
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
class UserUpdate(Base):
|
||||
|
||||
first_name:Annotated[str|None, Field(None, max_length=64, description="first name of the user")]
|
||||
last_name:Annotated[str|None, Field(None, max_length=64,description="last name of the user")]
|
||||
middle_name:Annotated[str|None, Field(None, max_length=64,description="middle name of the user")]
|
||||
email:Annotated[EmailStr|None, Field(None, min_length=5, max_length=255, description="email of the user")]
|
||||
status:Annotated[bool|None, Field(None, description="status of the user")]
|
||||
permissions:Annotated[list[str]|None, Field(None, description="permissions of the user")]
|
||||
permission_groups:Annotated[list[str]|None, Field(None, description="permissions groups of the user")]
|
||||
|
||||
class Permissions(Base):
|
||||
id:int
|
||||
permission_name:Annotated[str, Field(..., max_length=30, description="permission name")]
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
class PermissionsOut(Base):
|
||||
permission_name:Annotated[str, Field(..., max_length=30, description="permission name")]
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
Reference in New Issue
Block a user