1010from sqlalchemy import select
1111
1212from app .api import crud
13- from app .api .crud .authorizations import check_group_read , check_group_update , is_admin_access
13+ from app .api .crud .authorizations import check_group_read , is_admin_access
1414from app .api .crud .groups import get_entity_group_id
1515from app .api .deps import get_current_access , get_current_device
1616from app .api .external import post_request
17- from app .api .schemas import AccessType , AlertBase , AlertIn , AlertMediaId , AlertOut , DeviceOut
17+ from app .api .schemas import AlertBase , AlertIn , AlertOut , DeviceOut
1818from app .db import alerts , events , get_session , media , models
19+ from app .db .models import AccessType
1920
2021router = APIRouter ()
2122
@@ -110,20 +111,6 @@ async def fetch_alerts(
110111 return retrieved_alerts
111112
112113
113- @router .put ("/{alert_id}/" , response_model = AlertOut , summary = "Update information about a specific alert" )
114- async def update_alert (
115- payload : AlertIn ,
116- alert_id : int = Path (..., gt = 0 ),
117- requester = Security (get_current_access , scopes = [AccessType .admin , AccessType .user ]),
118- ):
119- """
120- Based on a alert_id, updates information about the specified alert
121- """
122- requested_group_id = await get_entity_group_id (alerts , alert_id )
123- await check_group_update (requester .id , requested_group_id )
124- return await crud .update_entry (alerts , payload , alert_id )
125-
126-
127114@router .delete ("/{alert_id}/" , response_model = AlertOut , summary = "Delete a specific alert" )
128115async def delete_alert (alert_id : int = Path (..., gt = 0 ), _ = Security (get_current_access , scopes = [AccessType .admin ])):
129116 """
@@ -132,29 +119,6 @@ async def delete_alert(alert_id: int = Path(..., gt=0), _=Security(get_current_a
132119 return await crud .delete_entry (alerts , alert_id )
133120
134121
135- @router .put ("/{alert_id}/link-media" , response_model = AlertOut , summary = "Link an alert to a media" )
136- async def link_media (
137- payload : AlertMediaId ,
138- alert_id : int = Path (..., gt = 0 ),
139- current_device : DeviceOut = Security (get_current_device , scopes = [AccessType .device ]),
140- ):
141- """
142- Based on a alert_id, and media information as arguments, link the specified alert to a media
143- """
144- # Check that alert is linked to this device
145- existing_alert = await crud .fetch_one (alerts , {"id" : alert_id , "device_id" : current_device .id })
146- if existing_alert is None :
147- raise HTTPException (
148- status_code = status .HTTP_404_NOT_FOUND ,
149- detail = f"Unable to find alert with id={ alert_id } & device_id={ current_device .id } ." ,
150- )
151-
152- await check_media_existence (payload .media_id )
153- existing_alert = dict (** existing_alert )
154- existing_alert ["media_id" ] = payload .media_id
155- return await crud .update_entry (alerts , AlertIn (** existing_alert ), alert_id )
156-
157-
158122@router .get ("/ongoing" , response_model = List [AlertOut ], summary = "Get the list of ongoing alerts" )
159123async def fetch_ongoing_alerts (
160124 requester = Security (get_current_access , scopes = [AccessType .admin , AccessType .user ]), session = Depends (get_session )
0 commit comments