feat(akte): FILE-009 Freitext-Notizen an beliebiger Ressource
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
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user