acikyazilimagi / musahit-harita-backend

Müşahit Haritası Backend Api Kodları
Apache License 2.0
22 stars 2 forks source link

feat(#19): add feed detail endpoint #22

Closed 9ssi7 closed 1 year ago

9ssi7 commented 1 year ago

What was done ?

Notes

Endpoint

URL: /feed/<neighborhood_id>

What kind of response is coming?

{
    "neighborhoodId": 1,
    "lastUpdateTime": "2023-05-24T11:37:09Z",
    "intensity": 1,
    "details": [
        {
            "buildingName": "deneme",
            "ballotBoxNos": [
                123123,
                12312312
            ]
        },
        {
            "buildingName": "test",
            "ballotBoxNos": [
                343
            ]
        }
    ]
}

Query

The SQL query this endpoint uses:

WITH selected_neighbourhood AS (
  SELECT id
  FROM locations
  WHERE neighbourhood_id = $1
  LIMIT 1
), box_numbers AS (
  SELECT b.id AS building_id, ARRAY_AGG(bb.box_no ORDER BY bb.box_no) AS box_numbers
  FROM volunteer_counts vc
  JOIN selected_neighbourhood sn ON vc.location_id = sn.id
  LEFT JOIN buildings b ON vc.building_id = b.id
  LEFT JOIN ballot_boxes bb ON b.id = bb.building_id
  GROUP BY b.id
)
SELECT b.name AS building_name, bn.box_numbers
FROM buildings b
LEFT JOIN box_numbers bn ON b.id = bn.building_id;

Closes #19