Skip to content

Commit ff7775f

Browse files
committed
Add: DELETE /cameras/{camera_id}. Fix: yeah
1 parent 94ebb21 commit ff7775f

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/api/api.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,26 @@ async def update_zone(zone_id: int, update: UpdateZone):
260260
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
261261
detail=f"Internal server error: {str(e)}"
262262
)
263+
264+
@self.app.delete("cameras/{camera_id}")
265+
async def delete_camera(camera_id: int):
266+
try:
267+
camera = self.db_manager.get_camera(camera_id)
268+
269+
if camera is None:
270+
raise HTTPException(
271+
status_code=status.HTTP_404_NOT_FOUND,
272+
detail=f"Camera with id {camera_id} doesn't exist"
273+
)
274+
275+
self.db_manager.delete_camera(camera)
276+
except HTTPException:
277+
raise
278+
except Exception as e:
279+
raise HTTPException(
280+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
281+
detail=f"Internal server error: {str(e)}"
282+
)
263283

264284
@self.app.get("/cameras/{camera_id}/snapshot")
265285
async def get_camera_snapshot(camera_id: int):

src/db_manager/db_manager.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def create_zone(self, zone):
212212
with self.get_session() as session:
213213
new_zone = ParkingZone(
214214
zone_type=zone['zone_type'],
215-
parking_lots_count=zone['parking_lots_count'],
215+
capacity=zone['capacity'],
216216
camera_id=zone['camera_id'],
217217
pay=zone['pay']
218218
)
@@ -359,4 +359,9 @@ def update_zone(self, zone_id, update_zone):
359359

360360
zone = session.query(ParkingZone).filter(ParkingZone.id == zone_id).one_or_none()
361361

362-
return zone.serialize() if zone is not None else None
362+
return zone.serialize() if zone is not None else None
363+
364+
def delete_camera(self, camera):
365+
with self.get_session() as session:
366+
session.delete(camera)
367+
session.commit()

0 commit comments

Comments
 (0)