Skip to content

Commit

Permalink
[Ticket 3] Create GET /reimbursements
Browse files Browse the repository at this point in the history
Add GET /reimbursements endpoint. Tests through browser. Comments added
for adding tests and organizing files & models  in the future.
  • Loading branch information
Sahar committed May 3, 2024
1 parent bd96cbf commit f6f9716
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 1 deletion.
21 changes: 21 additions & 0 deletions backend/src/api.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from fastapi import FastAPI

from .api import api_router
from .db import create_tables_with_data, delete_tables

@asynccontextmanager
Expand All @@ -11,3 +12,4 @@ async def lifespan(application: FastAPI):
delete_tables()

app = FastAPI(lifespan=lifespan)
app.include_router(api_router)
4 changes: 3 additions & 1 deletion backend/src/models.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Empty file added backend/tst/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions backend/tst/test_api.py
Original file line number Diff line number Diff line change
@@ -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
"""
7 changes: 7 additions & 0 deletions backend/tst/test_main.py
Original file line number Diff line number Diff line change
@@ -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?
"""
Empty file added backend/tst_integ/__init__.py
Empty file.
14 changes: 14 additions & 0 deletions backend/tst_integ/test_get_reimbursements.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f6f9716

Please sign in to comment.