Skip to content

Commit

Permalink
feat: API de resultado de loteria
Browse files Browse the repository at this point in the history
  • Loading branch information
brunascafutto13 committed Nov 30, 2023
1 parent 1fefaa2 commit 88a89c7
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pages/api/loteria/index.js
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);
147 changes: 147 additions & 0 deletions pages/docs/doc/loteria.json
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"
}
}
}
}
}
20 changes: 20 additions & 0 deletions services/dados-loteria/loteria.js
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;
}
};

0 comments on commit 88a89c7

Please sign in to comment.