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

Endpoint para cruzar excedente e doações necessárias entre abrigos #74

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

cesarpastorini
Copy link

@cesarpastorini cesarpastorini commented May 11, 2024

A base de dados do sistema possui as informações de excedente e demanda de doações por abrigo. Tendo isso, podemos utilizar essas informações para combinar os abrigos que possuem itens em excedente com os que demandam os mesmos, auxiliando assim no esforço de troca de itens entre abrigos.

Esta PR introduz um novo endpoint no backend, GET supplies/surplus-demand-matches, que retorna a combinação dos abrigos com itens em excedente com os que demandam. Internamente, a combinação é feita através de uma consulta na base de dados.

Exemplo de uso:

$ curl -s 'http://localhost:4000/supplies/surplus-demand-matches?perPage=30&page=3' | jq | head -n 28
{
  "statusCode": 200,
  "message": "Successfully got matches between surplus and demand",
  "data": [
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "0cbf3209-453d-40c6-85ee-060b8a8ae9cb",
      "shelter_from_name": "Ipa - Centro Universitário Metodista",
      "shelter_to_id": "bef1fe53-bf7e-4f4f-89f7-d515074e028c",
      "shelter_to_name": "Usina do Gasômetro"
    },
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "0cbf3209-453d-40c6-85ee-060b8a8ae9cb",
      "shelter_from_name": "Ipa - Centro Universitário Metodista",
      "shelter_to_id": "c0ee062d-9de5-49b5-bc22-f274a52b039e",
      "shelter_to_name": "RUs UFRGS"
    },
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "0cbf3209-453d-40c6-85ee-060b8a8ae9cb",
      "shelter_from_name": "Ipa - Centro Universitário Metodista",
      "shelter_to_id": "38050655-12ed-4698-bce2-59089feb4d61",
      "shelter_to_name": "Recomeçar"
    },

Exemplo usando um supplyId:

$ curl -s 'http://localhost:4000/supplies/surplus-demand-matches?supplyId=b9368d94-0425-4b23-ada4-66f8986f7368' | jq | head -n 28
{
  "statusCode": 200,
  "message": "Successfully got matches between surplus and demand",
  "data": [
    {
      "supply_id": "b9368d94-0425-4b23-ada4-66f8986f7368",
      "supply_name": "Água",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "911c231d-a09d-4b3e-b199-78854be2cb58",
      "shelter_to_name": "Templo Das Nações - Santa Maria"
    },
    {
      "supply_id": "b9368d94-0425-4b23-ada4-66f8986f7368",
      "supply_name": "Água",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "64c872b6-3e46-43a8-a705-6db3289b3fae",
      "shelter_to_name": "Projeto Surfar"
    },
    {
      "supply_id": "b9368d94-0425-4b23-ada4-66f8986f7368",
      "supply_name": "Água",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "573f4bb7-cf57-484b-a95a-d8829c1f406a",
      "shelter_to_name": "PetMedic Poa"
    },

@cesarpastorini cesarpastorini changed the title Endpoint para cruzar excedente de doações entre abrigos que têm sobrando e faltando Endpoint para cruzar excedente e doações necessárias entre abrigos May 12, 2024
@cesarpastorini
Copy link
Author

O endpoint suporta os parâmetros supplyId, shelterIdSurplus e shelterIdNeeded.

Exemplos usando último commit:

Filtrando por matches de um determinado abrigo com excedentes
curl -s 'http://localhost:4000/supplies/surplus-demand-matches?shelterIdSurplus=0cbf3209-453d-40c6-85ee-060b8a8ae9cb' | jq | head -n 28
{
  "statusCode": 200,
  "message": "Successfully got matches between surplus and demand",
  "data": [
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "0cbf3209-453d-40c6-85ee-060b8a8ae9cb",
      "shelter_from_name": "Ipa - Centro Universitário Metodista",
      "shelter_to_id": "bef1fe53-bf7e-4f4f-89f7-d515074e028c",
      "shelter_to_name": "Usina do Gasômetro"
    },
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "0cbf3209-453d-40c6-85ee-060b8a8ae9cb",
      "shelter_from_name": "Ipa - Centro Universitário Metodista",
      "shelter_to_id": "c0ee062d-9de5-49b5-bc22-f274a52b039e",
      "shelter_to_name": "RUs UFRGS"
    },
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "0cbf3209-453d-40c6-85ee-060b8a8ae9cb",
      "shelter_from_name": "Ipa - Centro Universitário Metodista",
      "shelter_to_id": "38050655-12ed-4698-bce2-59089feb4d61",
      "shelter_to_name": "Recomeçar"
    },
Filtrando por matches de um determinado abrigo com itens em falta
curl -s 'http://localhost:4000/supplies/surplus-demand-matches?shelterIdNeeded=685d0226-062b-4b77-a2df-c7c05a637856' | jq | head -n 28
{
  "statusCode": 200,
  "message": "Successfully got matches between surplus and demand",
  "data": [
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "97ef5b90-6f9b-4adb-bd07-086e7330b745",
      "shelter_from_name": "Nexos Ibn Church",
      "shelter_to_id": "685d0226-062b-4b77-a2df-c7c05a637856",
      "shelter_to_name": "Ctg Estância Do Rubem Berta"
    },
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "0cbf3209-453d-40c6-85ee-060b8a8ae9cb",
      "shelter_from_name": "Ipa - Centro Universitário Metodista",
      "shelter_to_id": "685d0226-062b-4b77-a2df-c7c05a637856",
      "shelter_to_name": "Ctg Estância Do Rubem Berta"
    },
    {
      "supply_id": "524ad35e-7967-4ebf-96d8-cdf0f56d1e81",
      "supply_name": "Sabonetes",
      "shelter_from_id": "5577f295-484a-41bf-8b11-5848f060ee9e",
      "shelter_from_name": "Igreja Deus É Amor",
      "shelter_to_id": "685d0226-062b-4b77-a2df-c7c05a637856",
      "shelter_to_name": "Ctg Estância Do Rubem Berta"
    },
Matches especificando o abrigo com excedentes e o abrigo com necessidades
$ curl -s 'http://localhost:4000/supplies/surplus-demand-matches?shelterIdSurplus=c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d&shelterIdNeeded=5daec969-8869-4121-bafc-1425731e6487' | jq
{
  "statusCode": 200,
  "message": "Successfully got matches between surplus and demand",
  "data": [
    {
      "supply_id": "e87c2f41-f417-4ee0-b818-9adfe7c790e9",
      "supply_name": "Colchões",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "5daec969-8869-4121-bafc-1425731e6487",
      "shelter_to_name": "Cremers"
    },
    {
      "supply_id": "b9368d94-0425-4b23-ada4-66f8986f7368",
      "supply_name": "Água",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "5daec969-8869-4121-bafc-1425731e6487",
      "shelter_to_name": "Cremers"
    }
  ]
}
Filtrando por item
# NOTE: Há outros supply_id para o item "água"
curl -s 'http://localhost:4000/supplies/surplus-demand-matches?supplyId=b9368d94-0425-4b23-ada4-66f8986f7368' | jq | head -n 28
{
  "statusCode": 200,
  "message": "Successfully got matches between surplus and demand",
  "data": [
    {
      "supply_id": "b9368d94-0425-4b23-ada4-66f8986f7368",
      "supply_name": "Água",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "911c231d-a09d-4b3e-b199-78854be2cb58",
      "shelter_to_name": "Templo Das Nações - Santa Maria"
    },
    {
      "supply_id": "b9368d94-0425-4b23-ada4-66f8986f7368",
      "supply_name": "Água",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "64c872b6-3e46-43a8-a705-6db3289b3fae",
      "shelter_to_name": "Projeto Surfar"
    },
    {
      "supply_id": "b9368d94-0425-4b23-ada4-66f8986f7368",
      "supply_name": "Água",
      "shelter_from_id": "c07ad79d-51ec-4b06-aeeb-2bc5492e5b7d",
      "shelter_from_name": "Estádio Olímpico Monumental",
      "shelter_to_id": "573f4bb7-cf57-484b-a95a-d8829c1f406a",
      "shelter_to_name": "PetMedic Poa"
    },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant