Skip to content

Commit

Permalink
refactor(endpoint): refactor get endpoint: ne
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloh-fm committed Jul 15, 2024
1 parent 22c2d59 commit d0ce9db
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/app/api/sheets/route.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
import { getSheetData } from "@/services/googleSheetsService";
import { NextResponse } from "next/server";

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const range = searchParams.get("range");
const sheetName = searchParams.get("sheetName");

if (!range || !sheetName) {
return new Response(
JSON.stringify({
message: "Parâmetros 'range' e 'sheetName' são obrigatórios",
}),
{
status: 400,
headers: { "Content-Type": "application/json" },
},
return NextResponse.json(
{ error: "Parâmetros 'range' e 'sheetName' são obrigatório" },
{ status: 400 },
);
}

try {
const data = await getSheetData(range, sheetName);
return new Response(JSON.stringify(data), {
status: 200,
headers: { "Content-Type": "application/json" },
});
return NextResponse.json(data, { status: 200 });
} catch (error) {
console.error("GET sheets error:", error);
return new Response(
JSON.stringify({ message: "Erro ao recuperar dados da planilha" }),
{
status: 500,
headers: { "Content-Type": "application/json" },
},
return NextResponse.json(
{ error: "Erro ao recuperar dados da planilha" },
{ status: 500 },
);
}
}

0 comments on commit d0ce9db

Please sign in to comment.