37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
from database import new_session, User, CSVFile, H5Model, ModelStatistics
|
|
from schemas import UserCreate, CSVFileUpload, H5ModelCreate, ModelStatisticsCreate
|
|
from sqlalchemy import select
|
|
|
|
class UserRepository:
|
|
@staticmethod
|
|
async def create_user(data: UserCreate):
|
|
async with new_session() as session:
|
|
user = User(username=data.username, password_hash=data.password)
|
|
session.add(user)
|
|
await session.commit()
|
|
return user.id
|
|
|
|
class CSVFileRepository:
|
|
@staticmethod
|
|
async def upload_file(user_id: int, file_path: str):
|
|
async with new_session() as session:
|
|
csv_file = CSVFile(user_id=user_id, file_path=file_path)
|
|
session.add(csv_file)
|
|
await session.commit()
|
|
|
|
class H5ModelRepository:
|
|
@staticmethod
|
|
async def add_model(user_id: int, model_path: str):
|
|
async with new_session() as session:
|
|
model = H5Model(user_id=user_id, model_path=model_path)
|
|
session.add(model)
|
|
await session.commit()
|
|
|
|
class ModelStatisticsRepository:
|
|
@staticmethod
|
|
async def add_statistics(data: ModelStatisticsCreate):
|
|
async with new_session() as session:
|
|
stats = ModelStatistics(**data.model_dump())
|
|
session.add(stats)
|
|
await session.commit()
|