Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: API de resultado de loteria #547

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sendo um resultado diário, não seria interessante termos algum cache aqui?

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;
}
};