forked from BrasilAPI/BrasilAPI
-
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.
- Loading branch information
1 parent
1fefaa2
commit 88a89c7
Showing
3 changed files
with
195 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import app from '@/app'; | ||
import { getLoteriaResults } from '@/services/loteria'; | ||
|
||
const action = async (request, response) => { | ||
try { | ||
|
||
const allLoteriaData = await getLoteriaResults(); | ||
|
||
|
||
const premios = allLoteriaData.listaRateioPremio.map(premio => ({ | ||
descricaoFaixa: premio.descricaoFaixa, | ||
valorPremio: premio.valorPremio | ||
})); | ||
|
||
|
||
response.status(200).json(premios); | ||
} catch (error) { | ||
|
||
console.error("Error:", error); | ||
response.status(500).json({ | ||
message: 'Error: 500', | ||
type: 'INTERNAL_SERVER_ERROR', | ||
}); | ||
} | ||
}; | ||
|
||
export default app().get(action); |
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,147 @@ | ||
{ | ||
"tags": [ | ||
{ | ||
"name": "LOTERIA", | ||
"description": "Resultados e dados das loterias" | ||
} | ||
], | ||
"paths": { | ||
"/loterias/v1": { | ||
"get": { | ||
"tags": [ | ||
"LOTERIA" | ||
], | ||
"summary": "Retorna os últimos resultados das loterias", | ||
"description": "Fornece informações detalhadas sobre os últimos resultados das loterias, incluindo números sorteados, prêmios e mais.", | ||
"responses": { | ||
"200": { | ||
"description": "Operação bem-sucedida", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/ResultadoLoteria" | ||
} | ||
} | ||
} | ||
}, | ||
"404": { | ||
"description": "Resultado não encontrado", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/ErrorMessage" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"ResultadoLoteria": { | ||
"title": "ResultadoLoteria", | ||
"type": "object", | ||
"properties": { | ||
"acumulado": { | ||
"type": "boolean" | ||
}, | ||
"dataApuracao": { | ||
"type": "string", | ||
"format": "date" | ||
}, | ||
"dataProximoConcurso": { | ||
"type": "string", | ||
"format": "date" | ||
}, | ||
"dezenasSorteadasOrdemSorteio": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"listaDezenas": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
}, | ||
"valorArrecadado": { | ||
"type": "number", | ||
"format": "float" | ||
}, | ||
"valorEstimadoProximoConcurso": { | ||
"type": "number", | ||
"format": "float" | ||
}, | ||
"listaRateioPremio": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/RateioPremio" | ||
} | ||
} | ||
|
||
}, | ||
"example": { | ||
"acumulado": true, | ||
"dataApuracao": "29/11/2023", | ||
"dezenasSorteadasOrdemSorteio": [ | ||
"29", "89", "85", "46", "93", "54", "25", "07", "17", "87" | ||
], | ||
"listaDezenas": [ | ||
"07", "17", "25", "29", "30", "35", "40", "41", "43", "46" | ||
], | ||
"valorArrecadado": 4690338.0, | ||
"valorEstimadoProximoConcurso": 5000000.0 | ||
} | ||
|
||
}, | ||
"RateioPremio": { | ||
"title": "RateioPremio", | ||
"type": "object", | ||
"properties": { | ||
"descricaoFaixa": { | ||
"type": "string" | ||
}, | ||
"faixa": { | ||
"type": "integer" | ||
}, | ||
"numeroDeGanhadores": { | ||
"type": "integer" | ||
}, | ||
"valorPremio": { | ||
"type": "number", | ||
"format": "float" | ||
} | ||
}, | ||
"example": { | ||
"descricaoFaixa": "20 acertos", | ||
"faixa": 1, | ||
"numeroDeGanhadores": 0, | ||
"valorPremio": 0.0 | ||
} | ||
}, | ||
"ErrorMessage": { | ||
"title": "ErrorMessage", | ||
"required": [ | ||
"name", | ||
"message" | ||
], | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
}, | ||
"message": { | ||
"type": "string" | ||
} | ||
}, | ||
"example": { | ||
"name": "NotFoundError", | ||
"message": "Resultado não encontrado" | ||
} | ||
} | ||
} | ||
} | ||
} |
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,20 @@ | ||
//recuperação de dados da última loteria | ||
import axios from 'axios'; | ||
let tipoDeLoteria; | ||
//Escolher tipo de loteria | ||
//Exemplo de tipo de loteria - passar como parâmetro para a API | ||
|
||
tipoDeLoteria = 'lotomania' | ||
|
||
const URL_LOTERIAS = 'https://servicebus2.caixa.gov.br/portaldeloterias/api/${tipoDeLoteria}/'; | ||
|
||
export const getLoteriaResults = async () => { | ||
try { | ||
const response = await axios.get(URL_LOTERIAS); | ||
return response.data; | ||
} catch (error) { | ||
console.error("Error ao coletar dados da API", error); | ||
throw error; | ||
} | ||
}; | ||
|