summaryrefslogtreecommitdiff
path: root/api/routes/locations.py
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-11-02 21:23:02 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-11-02 21:23:02 -0300
commit9e5e5da02b4a9704543e0efd7eb568b31a77a369 (patch)
treed5929d84620b4eaa87c63a82c8b70c3c4d63a6a2 /api/routes/locations.py
parentc3a884f12c1d7b6bc286e14bf0f8af2d99dad542 (diff)
list locations
Diffstat (limited to 'api/routes/locations.py')
-rw-r--r--api/routes/locations.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/api/routes/locations.py b/api/routes/locations.py
index e69de29..c3b30aa 100644
--- a/api/routes/locations.py
+++ b/api/routes/locations.py
@@ -0,0 +1,26 @@
+from fastapi import APIRouter
+from sqlalchemy import select
+from ..database import SessionLocal
+from ..models import Location
+
+router = APIRouter(
+ prefix='/locations',
+ tags=['locations']
+)
+
+@router.get('/')
+async def get_locations():
+ dc = {'locations': []}
+ session = SessionLocal()
+ stmt = select(Location.street, Location.avenue, Location.zip_code)
+ locs = session.execute(stmt).all() # TODO: Page results
+ for loc in locs:
+ l = {
+ 'street': loc.street,
+ 'avenue': loc.avenue,
+ 'zip_code': loc.zip_code
+ }
+ dc['locations'].append(l)
+ dc['size'] = len(dc['locations'])
+ return dc
+