-
Notifications
You must be signed in to change notification settings - Fork 574
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
brunascafutto13
wants to merge
2
commits into
BrasilAPI:main
Choose a base branch
from
brunascafutto13:feat/loteriaAPI
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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; | ||
} | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?