initial version of the app
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getSession } from '@/lib/session';
|
||||
import { db } from '@/lib/db';
|
||||
import { announcements } from '@/lib/db/schema';
|
||||
import { desc, eq } from 'drizzle-orm';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
// Get all active announcements, ordered by creation date (newest first)
|
||||
const allAnnouncements = await db
|
||||
.select({
|
||||
id: announcements.id,
|
||||
title: announcements.title,
|
||||
content: announcements.content,
|
||||
priority: announcements.priority,
|
||||
isActive: announcements.isActive,
|
||||
createdAt: announcements.createdAt,
|
||||
})
|
||||
.from(announcements)
|
||||
.where(eq(announcements.isActive, true))
|
||||
.orderBy(desc(announcements.createdAt));
|
||||
|
||||
return NextResponse.json({
|
||||
announcements: allAnnouncements,
|
||||
unreadCount: allAnnouncements.length, // For now, all announcements are considered unread
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching announcements:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user