Files
NexaPantry/backend/app/api/routes/notifications.py
nessi 3792ca55e7
Some checks failed
CI / backend (push) Failing after 31s
CI / frontend (push) Successful in 40s
CI / docker (push) Has been skipped
chore: initial project setup with backend, frontend, and infrastructure
Add complete NexaPantry application structure including:
- Docker Compose configuration with PostgreSQL, Redis, FastAPI backend, worker, frontend and Caddy
- Environment configuration template with database, auth, and service settings
- GitHub Actions CI workflow for backend/frontend linting, testing, auditing and Docker builds
- AGPL-3.0 license and comprehensive README with setup, development, and security documentation
- Backend
2026-06-04 10:26:38 +02:00

27 lines
1.1 KiB
Python

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy import select
from sqlalchemy.orm import Session
from app.api.deps import current_user
from app.db.session import get_db
from app.models.entities import Notification, User
from app.services.notifications import mark_read
router = APIRouter()
@router.get("")
def list_notifications(user: User = Depends(current_user), db: Session = Depends(get_db)) -> list[dict]:
rows = db.scalars(select(Notification).where(Notification.user_id == user.id).order_by(Notification.created_at.desc()).limit(100)).all()
return [{"id": n.id, "title": n.title, "body": n.body, "kind": n.kind, "read_at": n.read_at, "created_at": n.created_at} for n in rows]
@router.post("/{notification_id}/read")
def read(notification_id: str, user: User = Depends(current_user), db: Session = Depends(get_db)) -> dict:
notification = db.get(Notification, notification_id)
if not notification or notification.user_id != user.id:
raise HTTPException(status_code=404, detail="Notification not found")
mark_read(db, notification)
db.commit()
return {"message": "Notification read"}