Add BMAD framework, authentication, and new features
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import prisma from '@/lib/prisma'
|
||||
import { auth } from '@/auth'
|
||||
|
||||
const COLORS = ['red', 'orange', 'yellow', 'green', 'teal', 'blue', 'purple', 'pink', 'gray'];
|
||||
|
||||
// GET /api/labels - Get all labels
|
||||
export async function GET(request: NextRequest) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const labels = await prisma.label.findMany({
|
||||
where: { userId: session.user.id },
|
||||
orderBy: { name: 'asc' }
|
||||
})
|
||||
|
||||
@@ -23,6 +32,11 @@ export async function GET(request: NextRequest) {
|
||||
|
||||
// POST /api/labels - Create a new label
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { name, color } = body
|
||||
@@ -34,9 +48,14 @@ export async function POST(request: NextRequest) {
|
||||
)
|
||||
}
|
||||
|
||||
// Check if label already exists
|
||||
// Check if label already exists for this user
|
||||
const existing = await prisma.label.findUnique({
|
||||
where: { name: name.trim() }
|
||||
where: {
|
||||
name_userId: {
|
||||
name: name.trim(),
|
||||
userId: session.user.id
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (existing) {
|
||||
@@ -49,7 +68,8 @@ export async function POST(request: NextRequest) {
|
||||
const label = await prisma.label.create({
|
||||
data: {
|
||||
name: name.trim(),
|
||||
color: color || 'gray'
|
||||
color: color || COLORS[Math.floor(Math.random() * COLORS.length)],
|
||||
userId: session.user.id
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user