-
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.
Merge pull request #63 from Grupo-Syntax-Squad/44-recepção-das-mediçõ…
…es-e-exibição-nos-gráficos Performando estações, parâmetros e alertas
- Loading branch information
Showing
67 changed files
with
5,305 additions
and
3,666 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export interface Endereco { | ||
cep: string; | ||
logradouro: string; | ||
complemento: string; | ||
bairro: string; | ||
localidade: string; | ||
uf: string; | ||
ibge: string; | ||
gia: string; | ||
ddd: string; | ||
siafi: string; | ||
} | ||
|
||
export async function fetchEndereco(cep: string): Promise<Endereco | null> { | ||
const url = `https://viacep.com.br/ws/${cep}/json/`; | ||
|
||
try { | ||
const response = await fetch(url); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Erro ao buscar o CEP: ${response.status}`); | ||
} | ||
|
||
const data: Endereco = await response.json(); | ||
|
||
if ('erro' in data) { | ||
console.log('CEP não encontrado'); | ||
return null; | ||
} | ||
|
||
return data; | ||
} catch (error) { | ||
console.error("Erro na requisição:", error); | ||
return null; | ||
} | ||
} | ||
|
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
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
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
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
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,60 +1,35 @@ | ||
import { api_route } from ".."; | ||
import { criarEndereco } from "@/app/_api/post/enderecos"; | ||
import { useToken } from "@/hooks/token"; | ||
import { api_route } from '..'; | ||
|
||
interface Estacao { | ||
nome: string; | ||
endereco: number; | ||
topico: string; | ||
ativo: boolean; | ||
criado: string; | ||
modificado: string; | ||
parametros: Number[]; | ||
} | ||
|
||
interface Endereco { | ||
logradouro: string; | ||
bairro: string; | ||
cidade: string; | ||
estado: string; | ||
numero: number; | ||
complemento: string; | ||
cep: string; | ||
latitude: number; | ||
longitude: number; | ||
} | ||
|
||
// Remova o segundo parâmetro 'endereco' porque ele já foi tratado antes | ||
export const criarEstacao = async (estacao: Estacao, enderecoId: number): Promise<any> => { | ||
const token = useToken() | ||
|
||
if (!token) { | ||
throw new Error('Token não encontrado. Por favor, faça login.'); | ||
} | ||
console.log('Função criarEstacao foi chamada'); | ||
export const criarEstacao = async (estacao: Estacao, token: any): Promise<any> => { | ||
try { | ||
const estacaoComEndereco = { ...estacao, endereco: enderecoId }; | ||
|
||
console.log('Payload enviado:', estacaoComEndereco); | ||
if (!token) { | ||
throw new Error('Token não encontrado. Por favor, faça login.'); | ||
} | ||
|
||
const response = await fetch(`${api_route}estacoes`, { | ||
method: "POST", | ||
const responseEstacao = await fetch(`${api_route}estacoes`, { | ||
method: 'POST', | ||
headers: { | ||
"Authorization": `Token ${token}`, | ||
"Content-Type": "application/json", | ||
Authorization: `Token ${token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(estacaoComEndereco), | ||
body: JSON.stringify(estacao), | ||
}); | ||
|
||
console.log('Resposta da API ao criar a estação:', response); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
console.error('Erro ao criar a estação:', errorData); | ||
throw new Error(`Erro ao criar a estação: ${response.statusText}`); | ||
if (!responseEstacao.ok) { | ||
throw new Error(`Erro ao criar a estação: ${responseEstacao.statusText}`); | ||
} | ||
|
||
return await response.json(); | ||
return await responseEstacao.json(); | ||
} catch (error) { | ||
console.error("Erro na requisição:", error); | ||
console.error(error); | ||
throw error; | ||
} | ||
}; | ||
}; |
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,3 +1,4 @@ | ||
import { useSetTokenUser } from '@/hooks/token'; | ||
import { api_route } from '..'; | ||
|
||
interface Usuario { | ||
|
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
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,9 +1,13 @@ | ||
// pages/_app.tsx | ||
import "leaflet/dist/leaflet.css"; | ||
import { AppProps } from "next/app"; | ||
|
||
import { AppProps } from 'next/app'; | ||
import AuthGuard from '@/app/authGuard'; | ||
|
||
function MyApp({ Component, pageProps }: AppProps) { | ||
return <Component {...pageProps} />; | ||
return ( | ||
<AuthGuard> | ||
<Component {...pageProps} /> | ||
</AuthGuard> | ||
); | ||
} | ||
|
||
export default MyApp; | ||
export default MyApp; |
Oops, something went wrong.