Skip to content

Commit

Permalink
add room
Browse files Browse the repository at this point in the history
  • Loading branch information
WSL0809 committed May 22, 2024
1 parent eedc30b commit 01822de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
from .manage_plan import router as manage_plan_router
from .allocate_room import router as allocate_room_router
from .get_plan_by_id import router as get_plan_by_id_router
from .update_client_status import router as update_client_status_router
from .update_client_status import router as update_client_status_router
from .room import router as room_router
16 changes: 16 additions & 0 deletions api/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class AddRoomRecv(BaseModel):
room_number: str
notes: Union[str, None]

class DeleteRoomRecv(BaseModel):
room_number: str

class AddRoomResp(BaseModel):
msg: str
Expand All @@ -36,3 +38,17 @@ async def add_room(room_info: AddRoomRecv, db: Session = Depends(get_db)):
return AddRoomResp(msg=f"Database error: {str(e)}", success=False)
except Exception as e:
return AddRoomResp(msg=f"Unexpected error: {str(e)}", success=False)


@router.post("/delete_room")
@roles_required("admin")
async def delete_room(room: DeleteRoomRecv, db: Session = Depends(get_db)):
try:
db.query(Room).filter(Room.room_number == room.room_number).delete()
db.commit()
return AddRoomResp(msg="Room deleted successfully", success=True)
except SQLAlchemyError as e:
db.rollback()
return AddRoomResp(msg=f"Database error: {str(e)}", success=False)
except Exception as e:
return AddRoomResp(msg=f"Unexpected error: {str(e)}", success=False)
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
check_out_router, get_room_by_room_name_router, get_all_clients_router,
fault_registration_router, get_baby_nurse_router, insert_baby_nurse_router,
reminder_router, get_client_by_room_number_router, product_router, insert_client_router,
manage_plan_router, allocate_room_router, get_plan_by_id_router, update_client_status_router)
manage_plan_router, allocate_room_router, get_plan_by_id_router, update_client_status_router,
room_router)
from fastapi.middleware.cors import CORSMiddleware

model.Base.metadata.create_all(bind=engine)
Expand All @@ -44,6 +45,7 @@
app.include_router(allocate_room_router)
app.include_router(get_plan_by_id_router)
app.include_router(update_client_status_router)
app.include_router(room_router)
origins = [
"*"
]
Expand Down

0 comments on commit 01822de

Please sign in to comment.