import { NextResponse } from "next/server" import { transactionService } from "@/services/transaction.service" import type { Transaction } from "@/lib/types" export async function POST(request: Request) { try { const transactions: Transaction[] = await request.json() const result = await transactionService.createMany(transactions) return NextResponse.json(result) } catch (error) { console.error("Error creating transactions:", error) return NextResponse.json({ error: "Failed to create transactions" }, { status: 500 }) } } export async function PUT(request: Request) { try { const transaction: Transaction = await request.json() const updated = await transactionService.update(transaction.id, transaction) return NextResponse.json(updated) } catch (error) { console.error("Error updating transaction:", error) return NextResponse.json({ error: "Failed to update transaction" }, { status: 500 }) } } export async function DELETE(request: Request) { try { const { searchParams } = new URL(request.url) const id = searchParams.get("id") if (!id) { return NextResponse.json({ error: "Transaction ID is required" }, { status: 400 }) } await transactionService.delete(id) return NextResponse.json({ success: true }) } catch (error) { console.error("Error deleting transaction:", error) return NextResponse.json({ error: "Failed to delete transaction" }, { status: 500 }) } }