diff --git a/backend/src/api.py b/backend/src/api.py new file mode 100644 index 0000000..663e05f --- /dev/null +++ b/backend/src/api.py @@ -0,0 +1,21 @@ +""" +TODO +- don't directly call DB +- use API models instead of DB ones (see models.py) +""" + +from fastapi import APIRouter +from sqlmodel import select, Session + +from .db import engine +from .models import Reimbursement + +api_router = APIRouter( + prefix="/reimbursements", + tags=["reimbursements"] +) + +@api_router.get("/", response_model=list[Reimbursement]) +async def get_reimbursements() -> list[Reimbursement]: + with Session(engine) as session: + return session.exec(select(Reimbursement)).all() diff --git a/backend/src/main.py b/backend/src/main.py index bbd5b20..370921c 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -2,6 +2,7 @@ from fastapi import FastAPI +from .api import api_router from .db import create_tables_with_data, delete_tables @asynccontextmanager @@ -11,3 +12,4 @@ async def lifespan(application: FastAPI): delete_tables() app = FastAPI(lifespan=lifespan) +app.include_router(api_router) diff --git a/backend/src/models.py b/backend/src/models.py index ce072fe..58f0af6 100644 --- a/backend/src/models.py +++ b/backend/src/models.py @@ -1,6 +1,8 @@ """ TODO -- separate into individual files +- separate into individual files under a db folder +- create separate models for API usage that don't include unnecessary/sensistive info (such as id) + - add create_date, update_date, etc for all models - create a parent "human" class for admins & members (names, addr, ssn) - logging/tracking for changes made (e.g. which admin modified a reimbursement) diff --git a/backend/tst/__init__.py b/backend/tst/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/tst/test_api.py b/backend/tst/test_api.py new file mode 100644 index 0000000..3d8393a --- /dev/null +++ b/backend/tst/test_api.py @@ -0,0 +1,11 @@ +""" +TODO: unit tests for api.py + +get_reimbursements +- calls DB once +- returns list of Reimbursements + +api_router variable: +- prefix & tags correct? +- GET for / path response is list of Reimbursements, no request params +""" diff --git a/backend/tst/test_main.py b/backend/tst/test_main.py new file mode 100644 index 0000000..ba51558 --- /dev/null +++ b/backend/tst/test_main.py @@ -0,0 +1,7 @@ +""" +TODO: unit tests for main.py + +- FastAPI gets called with lifespan argument +- test for including api_router? +- test that create_tables_with_data and delete_tables get called? +""" diff --git a/backend/tst_integ/__init__.py b/backend/tst_integ/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/tst_integ/test_get_reimbursements.py b/backend/tst_integ/test_get_reimbursements.py new file mode 100644 index 0000000..bbb6c73 --- /dev/null +++ b/backend/tst_integ/test_get_reimbursements.py @@ -0,0 +1,14 @@ +""" +TODO: + +implement tests +once other tags/prefixes used, group endpoints for each tag under their own folders +""" + +def test_get_reimbursements(): + # TODO: returns the 3 reimbursements set up in db.py + pass + +def test_get_reimbursements_no_records(): + # TODO: (set up db for this test to not interfere with other tests somehow) returns empty list + pass