-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(endpoint): refactor get endpoint: ne
- Loading branch information
Showing
1 changed file
with
8 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }, | ||
); | ||
} | ||
} |