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
This commit is contained in:
26
backend/app/api/routes/notifications.py
Normal file
26
backend/app/api/routes/notifications.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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"}
|
||||
Reference in New Issue
Block a user