Add message actions (#482)
This commit is contained in:
parent
94f563f179
commit
171914941e
20 changed files with 1011 additions and 150 deletions
48
app/(chat)/api/vote/route.ts
Normal file
48
app/(chat)/api/vote/route.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { auth } from '@/app/(auth)/auth';
|
||||
import { getVotesByChatId, voteMessage } from '@/db/queries';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const chatId = searchParams.get('chatId');
|
||||
|
||||
if (!chatId) {
|
||||
return new Response('chatId is required', { status: 400 });
|
||||
}
|
||||
|
||||
const session = await auth();
|
||||
|
||||
if (!session || !session.user || !session.user.email) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
const votes = await getVotesByChatId({ id: chatId });
|
||||
|
||||
return Response.json(votes, { status: 200 });
|
||||
}
|
||||
|
||||
export async function PATCH(request: Request) {
|
||||
const {
|
||||
chatId,
|
||||
messageId,
|
||||
type,
|
||||
}: { chatId: string; messageId: string; type: 'up' | 'down' } =
|
||||
await request.json();
|
||||
|
||||
if (!chatId || !messageId || !type) {
|
||||
return new Response('messageId and type are required', { status: 400 });
|
||||
}
|
||||
|
||||
const session = await auth();
|
||||
|
||||
if (!session || !session.user || !session.user.email) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
|
||||
await voteMessage({
|
||||
chatId,
|
||||
messageId,
|
||||
type: type,
|
||||
});
|
||||
|
||||
return new Response('Message voted', { status: 200 });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue