- Unify API: lib/api.ts uses /api/v1, inbox uses /api/inbox (rewrites) - Remove localhost refs: openapi, inbox page - Add rewrites: /api/inbox|tmc -> inbox-server, /api/v1 -> FastAPI - Add stub routes: knowledge/insights, recommendations, search, log-error - Transfer from PAPA: prompts (inspection, tmc), scripts, supabase, data/tmc-requests - Fix inbox-server: ORDER BY created_at, package.json - Remove redundant app/api/inbox/files route (rewrites handle it) - knowledge/ in gitignore (large PDFs) Co-authored-by: Cursor <cursoragent@cursor.com>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api.deps import get_current_user
|
|
from app.db.session import get_db
|
|
from app.models import Notification
|
|
from app.schemas.notification import NotificationOut
|
|
|
|
router = APIRouter(tags=["notifications"])
|
|
|
|
|
|
@router.get("/notifications", response_model=list[NotificationOut])
|
|
def list_my_notifications(db: Session = Depends(get_db), user=Depends(get_current_user)):
|
|
return (
|
|
db.query(Notification)
|
|
.filter(Notification.recipient_user_id == user.id)
|
|
.order_by(Notification.created_at.desc())
|
|
.all()
|
|
)
|
|
from fastapi import HTTPException
|
|
|
|
@router.post("/{notification_id}/read", response_model=NotificationOut)
|
|
def mark_read(
|
|
notification_id: str,
|
|
db: Session = Depends(get_db),
|
|
user=Depends(get_current_user),
|
|
):
|
|
n = db.query(Notification).filter(Notification.id == notification_id).first()
|
|
|
|
if not n:
|
|
raise HTTPException(status_code=404, detail="Not found")
|
|
if n.recipient_user_id != user.id:
|
|
raise HTTPException(status_code=403, detail="Forbidden")
|
|
|
|
n.is_read = True
|
|
db.commit()
|
|
db.refresh(n)
|
|
return n
|