Add notification pagination to backend and frontend
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Query
|
||||
from fastapi.exceptions import HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pydantic import BaseModel
|
||||
@@ -144,11 +144,18 @@ def remove_subscription(subscription_id: int):
|
||||
|
||||
|
||||
@app.get("/subscriptions/{subscription_id}/notifications")
|
||||
def list_subscription_notifications(subscription_id: int):
|
||||
def list_subscription_notifications(
|
||||
subscription_id: int,
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
offset: int = Query(0, ge=0),
|
||||
):
|
||||
db = SessionLocal()
|
||||
notifications = (
|
||||
db.query(Notification)
|
||||
.filter(Notification.subscription_id == subscription_id)
|
||||
.order_by(Notification.created_at.desc())
|
||||
.limit(limit)
|
||||
.offset(offset)
|
||||
.all()
|
||||
)
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user