feat: integrate React Query for improved data fetching and state management across banking and transactions components
This commit is contained in:
@@ -1,8 +1,39 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { accountService } from "@/services/account.service";
|
||||
import { bankingService } from "@/services/banking.service";
|
||||
import { requireAuth } from "@/lib/auth-utils";
|
||||
import type { Account } from "@/lib/types";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const withStats = searchParams.get("withStats") === "true";
|
||||
|
||||
if (withStats) {
|
||||
const accountsWithStats = await bankingService.getAccountsWithStats();
|
||||
return NextResponse.json(accountsWithStats, {
|
||||
headers: {
|
||||
"Cache-Control": "public, s-maxage=60, stale-while-revalidate=120",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid request" },
|
||||
{ status: 400 },
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error fetching accounts:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch accounts" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const authError = await requireAuth();
|
||||
if (authError) return authError;
|
||||
|
||||
Reference in New Issue
Block a user