diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-02 21:23:02 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-11-02 21:23:02 -0300 |
| commit | 9e5e5da02b4a9704543e0efd7eb568b31a77a369 (patch) | |
| tree | d5929d84620b4eaa87c63a82c8b70c3c4d63a6a2 /api | |
| parent | c3a884f12c1d7b6bc286e14bf0f8af2d99dad542 (diff) | |
list locations
Diffstat (limited to 'api')
| -rw-r--r-- | api/.dockerignore | 1 | ||||
| -rw-r--r-- | api/Dockerfile | 20 | ||||
| -rw-r--r-- | api/main.py | 11 | ||||
| -rw-r--r-- | api/models.py | 2 | ||||
| -rw-r--r-- | api/requirements.txt | 3 | ||||
| -rw-r--r-- | api/routes/locations.py | 26 |
6 files changed, 62 insertions, 1 deletions
diff --git a/api/.dockerignore b/api/.dockerignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/api/.dockerignore @@ -0,0 +1 @@ +venv diff --git a/api/Dockerfile b/api/Dockerfile index e69de29..5119feb 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3.14-slim +ENV PYTHONUNBUFFERED=1 + +WORKDIR /api + +RUN useradd \ + --shell /sbin/nologin \ + --uid 10001 \ + --no-create-home \ + api-usr + +COPY requirements.txt . + +RUN python -m pip install -r requirements.txt + +USER api-usr + +COPY . . + +CMD ["fastapi", "run", "main.py", "--port", "80"] diff --git a/api/main.py b/api/main.py index e69de29..b4c85c5 100644 --- a/api/main.py +++ b/api/main.py @@ -0,0 +1,11 @@ +from fastapi import FastAPI +from .routes import locations + +app = FastAPI() +app.include_router(locations.router) + + +@app.get('/') +async def root(): + return {'msg': 'You will never be happy.'} + diff --git a/api/models.py b/api/models.py index 98549bc..c4e16de 100644 --- a/api/models.py +++ b/api/models.py @@ -1,7 +1,7 @@ from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Boolean from sqlalchemy.orm import relationship from sqlalchemy.sql import func -from database import Base +from .database import Base # ---------------------------- # Location diff --git a/api/requirements.txt b/api/requirements.txt index e69de29..b82030c 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -0,0 +1,3 @@ +fastapi[standard] +psycopg2-binary +sqlalchemy 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 + |
