1- use axum:: { Json , extract:: State , http:: StatusCode } ;
1+ use axum:: {
2+ Json ,
3+ extract:: { FromRef , FromRequestParts , Path , State } ,
4+ http:: { StatusCode , request:: Parts } ,
5+ } ;
26use axum_extra:: response:: Attachment ;
37use chrono:: Datelike ;
48use sqlx:: { SqliteConnection , SqlitePool } ;
@@ -16,9 +20,8 @@ use crate::{
1620 data_entry:: PollingStationResults ,
1721 election:: ElectionWithPoliticalGroups ,
1822 investigation:: {
19- CurrentSessionPollingStationId , PollingStationInvestigation ,
20- PollingStationInvestigationConcludeRequest , PollingStationInvestigationCreateRequest ,
21- PollingStationInvestigationUpdateRequest ,
23+ PollingStationInvestigation , PollingStationInvestigationConcludeRequest ,
24+ PollingStationInvestigationCreateRequest , PollingStationInvestigationUpdateRequest ,
2225 } ,
2326 models:: { ModelNa14_2Bijlage1Input , ToPdfFileModel } ,
2427 polling_station:: { PollingStation , PollingStationId } ,
@@ -105,6 +108,33 @@ pub async fn delete_investigation_for_polling_station(
105108 Ok ( ( ) )
106109}
107110
111+ pub struct CurrentSessionPollingStationId ( pub PollingStationId ) ;
112+
113+ impl < S > FromRequestParts < S > for CurrentSessionPollingStationId
114+ where
115+ SqlitePool : FromRef < S > ,
116+ S : Send + Sync ,
117+ {
118+ type Rejection = APIError ;
119+
120+ async fn from_request_parts ( parts : & mut Parts , state : & S ) -> Result < Self , Self :: Rejection > {
121+ let path_extractor = Path :: < PollingStationId > :: from_request_parts ( parts, state) . await ;
122+ let pool = SqlitePool :: from_ref ( state) ;
123+ let mut conn = pool. acquire ( ) . await ?;
124+
125+ if let Ok ( Path ( id) ) = path_extractor
126+ && polling_station_repo:: get ( & mut conn, id) . await . is_ok ( )
127+ {
128+ return Ok ( CurrentSessionPollingStationId ( id) ) ;
129+ }
130+
131+ Err ( APIError :: NotFound (
132+ "Polling station not found for the current committee session" . to_string ( ) ,
133+ ErrorReference :: EntryNotFound ,
134+ ) )
135+ }
136+ }
137+
108138/// Create an investigation for a polling station
109139#[ utoipa:: path(
110140 post,
0 commit comments