Skip to content

Commit

Permalink
api: add empty import endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jone committed Sep 6, 2024
1 parent 20f9914 commit 0d6d707
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
7 changes: 7 additions & 0 deletions api/app/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from fastapi import FastAPI
from fastapi import File
from fastapi import Query
from fastapi import UploadFile
from fastapi.responses import RedirectResponse

from app.elastic import Elastic
Expand Down Expand Up @@ -30,3 +32,8 @@ async def health():
async def photos(longitude: float = Query(...), latitude: float = Query(...), radius: float = Query(...)):
"""The photos endpoint queries the database for fotos in a specific radious of a location."""
return Elastic().search_documents(longitude=longitude, latitude=latitude, radius=f"{radius}m")


@app.post("/api/import")
async def import_data(file: UploadFile = File(...)):
return file.filename
16 changes: 15 additions & 1 deletion api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fastapi = "^0.113.0"
uvicorn = {extras = ["standard"], version = "^0.30.6"}
pydantic-settings = "^2.4.0"
elasticsearch = "^8.15.0"
python-multipart = "^0.0.9"

[tool.poetry.group.test.dependencies]
pytest = "^8.3.1"
Expand Down
12 changes: 12 additions & 0 deletions api/tests/test_http.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pathlib import Path
from tempfile import NamedTemporaryFile

from tests.case import TestCase


Expand Down Expand Up @@ -53,3 +56,12 @@ def test_photos_querying(self):
)
self.assertEqual(response.status_code, 200)
self.assert_json_equal([seeblick], response.json())

def test_data_import(self):
with NamedTemporaryFile(suffix=".csv") as fio:
fio.write(b"title")
fio.flush()
fio.seek(0)
response = self.client.post("/api/import/", files={"file": (Path(fio.name).name, fio, "text/csv")})
self.assertEqual(200, response.status_code, response.content)
self.assertEqual(Path(fio.name).name, response.json())

0 comments on commit 0d6d707

Please sign in to comment.