refactor: Update user profile routing from @[handle] to [handle], add an explore page, and introduce a user API route.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { db } from '@/db';
|
||||
import { users } from '@/db';
|
||||
import { desc, sql } from 'drizzle-orm';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
if (!db) {
|
||||
return NextResponse.json({ users: [] });
|
||||
}
|
||||
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
const limit = Math.min(parseInt(searchParams.get('limit') || '20'), 50);
|
||||
|
||||
const userList = await db
|
||||
.select({
|
||||
id: users.id,
|
||||
handle: users.handle,
|
||||
displayName: users.displayName,
|
||||
bio: users.bio,
|
||||
avatarUrl: users.avatarUrl,
|
||||
createdAt: users.createdAt,
|
||||
})
|
||||
.from(users)
|
||||
.where(sql`${users.status} IS NULL OR ${users.status} != 'suspended'`)
|
||||
.orderBy(desc(users.createdAt))
|
||||
.limit(limit);
|
||||
|
||||
return NextResponse.json({ users: userList });
|
||||
} catch (error) {
|
||||
console.error('List users error:', error);
|
||||
return NextResponse.json({ users: [] });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user