diff --git a/Backend/node/swarm.py b/Backend/node/swarm.py index bd9f83a58a1daae67976a6bb28062b57579f8da7..1cb59ad344740e19375afdcc7ff7244394252cfb 100644 --- a/Backend/node/swarm.py +++ b/Backend/node/swarm.py @@ -66,10 +66,6 @@ class NodeSwarm: async with db.get_session() as session: group_repo = GroupRepository(session) group = await group_repo.get(group_id) - if group is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) await self._set_group(group, session) return group diff --git a/ProxyNode/node_settings/node_settings.py b/ProxyNode/node_settings/node_settings.py index 564c6db97cb1b398336061b9a8ace8b80b8871c4..2bc85d1f4a0c1357fbb012a4b85a1b7947802b37 100644 --- a/ProxyNode/node_settings/node_settings.py +++ b/ProxyNode/node_settings/node_settings.py @@ -18,21 +18,17 @@ hot_cams: HotCams = HotCams() @node_router.post("/set/{node_id}", response_model=NodeFull) async def set_node_id( node_id: int, - node_repo: NodeRepository = Depends(db.get_repository(NodeRepository)) ): global current_node global hot_cams - node = await node_repo.get(node_id) - if node is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) - current_node = node + with db.get_session() as session: + node_repo: NodeRepository = NodeRepository(session) + current_node = await node_repo.get(node_id) + cams = await node_repo.get_node_cams(current_node) # Warm up cams del hot_cams hot_cams = HotCams() - cams = await node_repo.get_node_cams(current_node) cams = [int(getattr(cam, 'id')) for cam in cams] await hot_cams.try_connect_cams_list(cams) return current_node diff --git a/ProxyNode/onvif_proxy/hot_cams.py b/ProxyNode/onvif_proxy/hot_cams.py index 3dd5b0fa0bb8b3faecb6e2dbd33d1dae84316479..c1f3cb8f88a797f52b02fdfc724cc6ff541c6f40 100644 --- a/ProxyNode/onvif_proxy/hot_cams.py +++ b/ProxyNode/onvif_proxy/hot_cams.py @@ -23,6 +23,7 @@ class HotCams: try: cam = Camera(_cam_id, **kwargs) await cam.update() + print(f"Connection to camera {kwargs['name']} established.") break except (ONVIFError, httpx.ConnectTimeout, httpx.ConnectError) as e: if 'name' in kwargs: @@ -38,7 +39,7 @@ class HotCams: async def try_connect(self, cam_id: int): async with db.get_session() as session: cam_repo = CamRepository(session) - cam_db_obj = await cam_repo.get(cam_id) + cam_db_obj = await cam_repo.get_or_none(cam_id) if cam_db_obj is None: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND diff --git a/database/api/cam_groups.py b/database/api/cam_groups.py index 2c3b1de8e64c786bede246ce6edc201150c8c37f..72b15cf717d7b0e74ce558ff51e1d8d2c7dbc136 100644 --- a/database/api/cam_groups.py +++ b/database/api/cam_groups.py @@ -30,10 +30,6 @@ async def get_group( group_repo: GroupRepository = Depends(db.get_repository(GroupRepository)) ): group = await group_repo.get(group_id) - if group is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) return group @@ -84,10 +80,6 @@ async def list_cams_in_group( group_repo: GroupRepository = Depends(db.get_repository(GroupRepository)) ): group = await group_repo.get(group_id) - if group is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) return await group_repo.list_cams_in_group(group) diff --git a/database/api/cams.py b/database/api/cams.py index d1e2c6b6ac564347b8ab3eb386145c1bd2688b51..6b5404e1f28fb8bf0774e63b55c8b2b90d272200 100644 --- a/database/api/cams.py +++ b/database/api/cams.py @@ -30,10 +30,6 @@ async def get_cam( cam_repo: CamRepository = Depends(db.get_repository(CamRepository)) ): cam = await cam_repo.get(cam_id) - if cam is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) return cam diff --git a/database/api/nodes.py b/database/api/nodes.py index 3fc28c296190bb7c3ac71e478e53d33ad0fb280c..6a512fff4a4e26c9f64174c6f5804ce14ad37217 100644 --- a/database/api/nodes.py +++ b/database/api/nodes.py @@ -27,10 +27,6 @@ async def get_node( node_repo: NodeRepository = Depends(db.get_repository(NodeRepository)) ): node = await node_repo.get(node_id) - if node is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) return node diff --git a/database/api/roles.py b/database/api/roles.py index 0d7d1754f6fc7433a32ecbe7aea36c9559da608c..6d89668df824ce22a57f156fa02d97264ec04686 100644 --- a/database/api/roles.py +++ b/database/api/roles.py @@ -27,10 +27,6 @@ async def get_role( role_repo: RoleRepository = Depends(db.get_repository(RoleRepository)) ): role = await role_repo.get(role_id) - if role is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) return role diff --git a/database/api/users.py b/database/api/users.py index 4607d7453208c678809e57312857488f8c966027..0d6954e5225fae762948953f156979d09a0369e0 100644 --- a/database/api/users.py +++ b/database/api/users.py @@ -29,10 +29,6 @@ async def get_user( user_repo: UserRepository = Depends(db.get_repository(UserRepository)) ): user = await user_repo.get(user_id) - if user is None: - raise HTTPException( - status_code=status.HTTP_404_NOT_FOUND - ) return user