WIP: initial fastapi endpoint implementation

Client endpoint - GET & POST implemented
This commit is contained in:
2025-06-08 23:17:58 +02:00
parent aa64491313
commit e60489715a
25 changed files with 207 additions and 88 deletions
+30
View File
@@ -0,0 +1,30 @@
"""
"""
from fastapi import Depends
from sqlmodel import Session, SQLModel, select
from app.core.db import get_session
from app.schemas.models import Client
from typing import Type, Optional, Annotated
SessionDep = Annotated[Session, Depends(get_session)]
def exists(session: Session, model: Type[SQLModel], **filters) -> Optional[bool]:
"""
Checks if a request exists in the given model using any filters.
Example:
exists(session, Client, phone="0781232465", tax_number="TIN123")
"""
if not filters:
raise ValueError("At least one filter must be provided")
stmt = select(model)
for field, value in filters.items():
if not hasattr(model, field):
raise ValueError(f"Invalid filter field: {field}")
stmt = stmt.where(getattr(model, field) == value)
result = session.exec(stmt).first()
return result is not None