Polymorphes akte_notiz-Modell (gleiches entitaet_typ/entitaet_id-Muster wie Dokument/Historie/Mangel), CRUD-Endpunkte, NotizenPanel im Akte-Grid. Löschen nur durch Autor oder Administrator. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CVgbozhYmuEhiEJHffRXCV
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import uuid
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.models.notiz import AkteNotiz
|
|
|
|
|
|
async def erstelle_notiz(
|
|
db: AsyncSession, *, entitaet_typ: str, entitaet_id: str, text: str, autor_id: int
|
|
) -> AkteNotiz:
|
|
notiz = AkteNotiz(
|
|
id=uuid.uuid4(),
|
|
entitaet_typ=entitaet_typ,
|
|
entitaet_id=entitaet_id,
|
|
text=text,
|
|
autor_id=autor_id,
|
|
erstellt_am=datetime.now(timezone.utc),
|
|
)
|
|
db.add(notiz)
|
|
await db.commit()
|
|
await db.refresh(notiz)
|
|
return notiz
|
|
|
|
|
|
async def liste_fuer_entitaet(db: AsyncSession, *, entitaet_typ: str, entitaet_id: str) -> list[AkteNotiz]:
|
|
ergebnis = await db.execute(
|
|
select(AkteNotiz)
|
|
.where(AkteNotiz.entitaet_typ == entitaet_typ, AkteNotiz.entitaet_id == entitaet_id)
|
|
.order_by(AkteNotiz.erstellt_am.desc())
|
|
)
|
|
return list(ergebnis.scalars().all())
|
|
|
|
|
|
async def loesche_notiz(db: AsyncSession, *, notiz: AkteNotiz) -> None:
|
|
await db.delete(notiz)
|
|
await db.commit()
|