23 lines
854 B
Python
23 lines
854 B
Python
"""Rückmeldung zu einer Antwort (HTMX): Daumen hoch/runter, optional ein Kommentar."""
|
|
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Form, Request
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
from app import web
|
|
from app.feedback import service as feedback
|
|
|
|
|
|
def router() -> APIRouter:
|
|
r = APIRouter()
|
|
|
|
@r.post("/messages/{message_id}/feedback")
|
|
def rate(request: Request, principal: web.Checked, message_id: int, rating: Annotated[int, Form()],
|
|
comment: Annotated[str | None, Form()] = None) -> HTMLResponse:
|
|
with web.db(request).session() as session:
|
|
found = feedback.rate(session, principal, message_id, rating, comment)
|
|
context = {"message_id": message_id, "fb": found, "thanks": comment is not None}
|
|
return web.render(request, "_feedback.html", context)
|
|
|
|
return r
|