18 lines
437 B
Python
18 lines
437 B
Python
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.models.fit import Fit, FitNote
|
|
from app.models.user import User
|
|
|
|
|
|
async def create(db: AsyncSession, *, fit: Fit, author: User, body: str) -> FitNote:
|
|
note = FitNote(
|
|
fit_id=fit.id,
|
|
user_id=author.id,
|
|
username=author.full_name or author.email,
|
|
body=body,
|
|
)
|
|
db.add(note)
|
|
await db.commit()
|
|
await db.refresh(note)
|
|
return note
|