From ba848d70d564077c6d732e6d0618fd426a550ac8 Mon Sep 17 00:00:00 2001 From: wnlRlfl Date: Tue, 13 Jan 2026 21:25:32 +0900 Subject: [PATCH] Implement todos --- .env.example | 8 -------- app/routers/places.py | 40 ++++++++++++++++++++++++++++------------ fastapi-community | 1 + 3 files changed, 29 insertions(+), 20 deletions(-) delete mode 100644 .env.example create mode 160000 fastapi-community diff --git a/.env.example b/.env.example deleted file mode 100644 index c0a8432..0000000 --- a/.env.example +++ /dev/null @@ -1,8 +0,0 @@ -DATABASE_URL= - -# Azure Resources -SEARCH_SERVICE_ENDPOINT= -STORAGE_ACCOUNT_ENDPOINT= -KEY_VAULT_URI= -APP_INSIGHTS_KEY= -WEB_APP_URL= diff --git a/app/routers/places.py b/app/routers/places.py index 669b2d1..46c79c0 100644 --- a/app/routers/places.py +++ b/app/routers/places.py @@ -14,9 +14,7 @@ status_code=status.HTTP_200_OK ) async def list_places(db: Session = Depends(get_db)): - """Get all places.""" - # TODO: Query DB and return list - return [] + return db.query(Place).all() @router.post( "/", @@ -25,9 +23,11 @@ async def list_places(db: Session = Depends(get_db)): status_code=status.HTTP_201_CREATED ) async def create_place(place: PlaceCreate, db: Session = Depends(get_db)): - """Create a new place.""" - # TODO: Create and save to DB - raise NotImplementedError("TODO: Implement place creation") + new_place = Place(**place.dict()) + db.add(new_place) + db.commit() + db.refresh(new_place) + return new_place @router.get( "/{place_id}", @@ -35,8 +35,10 @@ async def create_place(place: PlaceCreate, db: Session = Depends(get_db)): response_model=PlaceResponse ) async def get_place(place_id: int, db: Session = Depends(get_db)): - # TODO - raise NotImplementedError("TODO: Implement get place") + place = db.query(Place).filter(Place.id == place_id).first() + if not place: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Place not found") + return place @router.patch( "/{place_id}", @@ -44,8 +46,18 @@ async def get_place(place_id: int, db: Session = Depends(get_db)): response_model=PlaceResponse ) async def update_place(place_id: int, place: PlaceUpdate, db: Session = Depends(get_db)): - # TODO - raise NotImplementedError("TODO: Implement update place") + db_place = db.query(Place).filter(Place.id == place_id).first() + if not db_place: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Place not found") + update_data = place.dict(exclude_unset = True) + + for key, value in update_data.items(): + setattr(db_place, key, value) + + db.add(db_place) + db.commit() + db.refresh(db_place) + return db_place @router.delete( "/{place_id}", @@ -53,5 +65,9 @@ async def update_place(place_id: int, place: PlaceUpdate, db: Session = Depends( status_code=status.HTTP_204_NO_CONTENT ) async def delete_place(place_id: int, db: Session = Depends(get_db)): - # TODO - raise NotImplementedError("TODO: Implement delete place") + place = db.query(Place).filter(Place.id == place.id).first() + if not place: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Place not found") + db.delete(place) + db.commit() + return diff --git a/fastapi-community b/fastapi-community new file mode 160000 index 0000000..8831283 --- /dev/null +++ b/fastapi-community @@ -0,0 +1 @@ +Subproject commit 88312839a3702e99f222578835709d9cae694dfd