blob: c3b30aa2d996fa0961048479e9d35464c649cdf6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
|