async def createCamera(camera: Camera, token: str) -> Camera: email = getEmailFromJWTToken(token) user = await getUserByEmail(email) camera.userID = user["userID"] if not await cameraExists(camera): camera.cameraID = await CameraDao.createCamera(camera) sendMessage(routing_key='testingDetection', body={"ID": camera.cameraID, "action": "add"}) return camera else: raise HTTPException(status_code=HTTP_409_CONFLICT, detail="Duplicate Camera")
async def updateCamera(token: str, cameraID: int, camera: Camera) -> Camera: email = getEmailFromJWTToken(token) user = await getUserByEmail(email) currentCamera = await getCameraByID(cameraID) if currentCamera["userID"] == user["userID"]: if camera.userID == None: camera.userID = user["userID"] if await CameraDao.updateCamera(camera, cameraID): camera.cameraID = cameraID return camera raise HTTPException(status_code=HTTP_500_INTERNAL_SERVER_ERROR, detail="Could not update camera") raise HTTPException(status_code=HTTP_409_CONFLICT, detail="Camera does not belong to current user")