1
This commit is contained in:
@@ -317,17 +317,22 @@ async def list_admin_notifications(
|
|||||||
page: int = Query(1, ge=1),
|
page: int = Query(1, ge=1),
|
||||||
page_size: int = Query(20, ge=1, le=500),
|
page_size: int = Query(20, ge=1, le=500),
|
||||||
user_id: str | None = Query(None),
|
user_id: str | None = Query(None),
|
||||||
|
is_read: bool = Query(None),
|
||||||
admin: User = Depends(get_admin_user),
|
admin: User = Depends(get_admin_user),
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
):
|
):
|
||||||
"""List unread notifications with optional user_id filter."""
|
"""List all notifications with optional filters."""
|
||||||
query = select(Notification).where(Notification.is_read == False).order_by(Notification.created_at.desc())
|
query = select(Notification).order_by(Notification.created_at.desc())
|
||||||
count_query = select(func.count(Notification.id)).where(Notification.is_read == False)
|
count_query = select(func.count(Notification.id))
|
||||||
|
|
||||||
if user_id:
|
if user_id:
|
||||||
query = query.where(Notification.user_id == user_id)
|
query = query.where(Notification.user_id == user_id)
|
||||||
count_query = count_query.where(Notification.user_id == user_id)
|
count_query = count_query.where(Notification.user_id == user_id)
|
||||||
|
|
||||||
|
if is_read is not None:
|
||||||
|
query = query.where(Notification.is_read == is_read)
|
||||||
|
count_query = count_query.where(Notification.is_read == is_read)
|
||||||
|
|
||||||
total = (await db.execute(count_query)).scalar() or 0
|
total = (await db.execute(count_query)).scalar() or 0
|
||||||
result = await db.execute(query.offset((page - 1) * page_size).limit(page_size))
|
result = await db.execute(query.offset((page - 1) * page_size).limit(page_size))
|
||||||
items = result.scalars().all()
|
items = result.scalars().all()
|
||||||
|
|||||||
@@ -27,11 +27,10 @@ const NotificationPopup: React.FC = () => {
|
|||||||
|
|
||||||
const fetchNotifications = useCallback(async () => {
|
const fetchNotifications = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const result = await getNotifications();
|
const result = await getNotifications(1, 20, false);
|
||||||
const data = result.items || [];
|
const data = result.items || [];
|
||||||
const unread = data.filter((n: Notification) => !n.isRead);
|
setNotifications(data);
|
||||||
setNotifications(unread);
|
if (data.length > 0 && !visible) {
|
||||||
if (unread.length > 0 && !visible) {
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
setCurrentIndex(0);
|
setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user