diff --git a/backend/api/main.py b/backend/api/main.py index e3a4b0a..0c24ce0 100644 --- a/backend/api/main.py +++ b/backend/api/main.py @@ -4,7 +4,7 @@ from sqlalchemy.orm import clear_mappers, sessionmaker import backend.adapters.orm as orm from backend.api.model import TribeModel from backend.model.tribe import Tribe -from fastapi import FastAPI +from fastapi import FastAPI, status orm.start_mappers() engine = create_engine("sqlite:///:memory:") @@ -14,22 +14,22 @@ get_session = sessionmaker(bind=engine) app = FastAPI() -@app.put("/tribes") -async def put_tribe(item: TribeModel, status_code=201): +@app.put("/tribes", status_code=status.HTTP_201_CREATED, response_model=TribeModel) +async def put_tribe(item: TribeModel): tribe = Tribe(**item.dict()) session = get_session() session.add(tribe) session.commit() - tribes = session.query(Tribe).all() - return {} + return tribe.to_dict() -@app.get("/tribes") -async def get_tribes(response_model=list[TribeModel]): +@app.get("/tribes", response_model=list[TribeModel]) +async def get_tribes(): session = get_session() tribes = session.query(Tribe).all() + print(tribes[0].__dict__) return [t.to_dict() for t in tribes] diff --git a/backend/api/model.py b/backend/api/model.py index fcb7616..a20a4e3 100644 --- a/backend/api/model.py +++ b/backend/api/model.py @@ -4,5 +4,5 @@ from pydantic import BaseModel class TribeModel(BaseModel): name: str level: str - students: list = [] - assessments: list = [] + students: list | None = [] + assessments: list | None = []