export async function GET(request: Request) {
try {
const url = new URL(request.url);
const topicId = parseInt(url.searchParams.get("topicId") ?? "", 10);
console.log("Received topicId:", topicId);
const topic = await db.topic.findUnique({
where: {
id: topicId,
},
include: {
subtopics: {
select: {
name: true,
},
},
},
});
if (!topic) {
return new Response(null, { status: 404 });
}
const subtopicNames = topic.subtopics.map((subtopic) => subtopic.name);
return new Response(JSON.stringify(subtopicNames));
} catch (error) {
return new Response(null, { status: 500 });
}
}
export async function GET(request: Request) {
try {
const url = new URL(request.url);
const topicId = parseInt(url.searchParams.get("topicId") ?? "", 10);
console.log("Received topicId:", topicId);
const topic = await db.topic.findUnique({
where: {
id: topicId,
},
include: {
subtopics: {
select: {
name: true,
},
},
},
});
if (!topic) {
return new Response(null, { status: 404 });
}
const subtopicNames = topic.subtopics.map((subtopic) => subtopic.name);
return new Response(JSON.stringify(subtopicNames));
} catch (error) {
return new Response(null, { status: 500 });
}
}