from __future__ import annotations from fastapi import APIRouter, Depends, HTTPException, Query from sqlmodel import Session from ..db.session import get_session from ..services import notification_service router = APIRouter(prefix='/api/notifications') @router.get('/rules') def rules(session: Session = Depends(get_session)): return notification_service.list_rules(session) @router.post('/rules') def create_rule(payload: dict, session: Session = Depends(get_session)): return notification_service.create_rule(session, payload) @router.patch('/rules/{rule_id}') def update_rule(rule_id: str, payload: dict, session: Session = Depends(get_session)): result = notification_service.update_rule(session, rule_id, payload) if result.get('status') == 'not_found': raise HTTPException(status_code=404, detail='rule_not_found') return result @router.delete('/rules/{rule_id}') def delete_rule(rule_id: str, session: Session = Depends(get_session)): result = notification_service.delete_rule(session, rule_id) if result.get('status') == 'not_found': raise HTTPException(status_code=404, detail='rule_not_found') return result @router.get('/events') def events( limit: int = Query(default=250, ge=1, le=500), offset: int = Query(default=0, ge=0), include_dismissed: bool = Query(default=True), session: Session = Depends(get_session), ): return notification_service.list_events( session, include_dismissed=include_dismissed, limit=limit, offset=offset, ) @router.get('/events/unread') def unread_events( limit: int = Query(default=250, ge=1, le=500), offset: int = Query(default=0, ge=0), session: Session = Depends(get_session), ): return notification_service.unread_events(session, limit=limit, offset=offset) @router.post('/events/{event_id}/dismiss') def dismiss_event(event_id: str, session: Session = Depends(get_session)): result = notification_service.dismiss_event(session, event_id) if result.get('status') == 'not_found': raise HTTPException(status_code=404, detail='event_not_found') return result @router.post('/events/{event_id}/mark-read') def mark_read(event_id: str, session: Session = Depends(get_session)): result = notification_service.mark_read(session, event_id) if result.get('status') == 'not_found': raise HTTPException(status_code=404, detail='event_not_found') return result @router.post('/events/mark-all-read') def mark_all_read(session: Session = Depends(get_session)): return notification_service.mark_all_read(session) @router.get('/channels') def channels(session: Session = Depends(get_session)): return notification_service.list_channels(session) @router.post('/channels') def create_channel(payload: dict, session: Session = Depends(get_session)): return notification_service.create_channel(session, payload) @router.patch('/channels/{channel_id}') def update_channel(channel_id: str, payload: dict, session: Session = Depends(get_session)): result = notification_service.update_channel(session, channel_id, payload) if result.get('status') == 'not_found': raise HTTPException(status_code=404, detail='channel_not_found') return result @router.post('/channels/{channel_id}/test') def test_channel(channel_id: str, session: Session = Depends(get_session)): result = notification_service.test_channel(session, channel_id) if result.get('status') == 'not_found': raise HTTPException(status_code=404, detail='channel_not_found') return result @router.post('/channels/{channel_id}/test-connection') def test_channel_connection(channel_id: str, session: Session = Depends(get_session)): result = notification_service.test_channel_connection(session, channel_id) if result.get('status') == 'not_found': raise HTTPException(status_code=404, detail='channel_not_found') return result @router.post('/evaluate') def evaluate(session: Session = Depends(get_session)): return notification_service.evaluate_source(session, 'all') @router.post('/evaluate/safety') def evaluate_safety(session: Session = Depends(get_session)): return notification_service.evaluate_source(session, 'safety') @router.post('/evaluate/media') def evaluate_media(session: Session = Depends(get_session)): return notification_service.evaluate_source(session, 'media') @router.post('/evaluate/connectors') def evaluate_connectors(session: Session = Depends(get_session)): return notification_service.evaluate_source(session, 'connectors') @router.get('/summary') def summary(session: Session = Depends(get_session)): return notification_service.summary(session)