@@ -4,10 +4,10 @@ use std::io::{Cursor, Read};
44use anyhow:: anyhow;
55use image:: ImageFormat ;
66use rocket:: form:: { Contextual , Form } ;
7- use rocket:: http:: { ContentType , Status } ;
7+ use rocket:: http:: { Status } ;
88use rocket:: response:: { Redirect } ;
99use rocket:: response:: status:: Custom ;
10- use rocket:: { Build , Data , Rocket , State } ;
10+ use rocket:: { Build , Rocket , State } ;
1111use rocket_dyn_templates:: { context, Template } ;
1212use sqlx:: { query, query_as, FromRow , SqlitePool } ;
1313use crate :: db:: { get_event_db, DbPool } ;
@@ -167,12 +167,12 @@ pub async fn get_user_info(session_id: &QxSessionId, state: &State<SharedQxState
167167 Ok ( user_info)
168168}
169169
170- pub async fn event_owner_opt ( event_id : EventId , session_id : MaybeSessionId , state : & State < SharedQxState > , gdb : & State < DbPool > ) -> anyhow:: Result < Option < UserInfo > > {
171- let event = load_event ( event_id, gdb) . await ?;
172- let user = user_info_opt ( session_id. 0 . as_ref ( ) , state) . await ?
173- . and_then ( |user| if user. email == event. owner { Some ( user) } else { None } ) ;
174- Ok ( user)
175- }
170+ // pub async fn event_owner_opt(event_id: EventId, session_id: MaybeSessionId, state: &State<SharedQxState>, gdb: &State<DbPool>) -> anyhow::Result<Option<UserInfo>> {
171+ // let event = load_event(event_id, gdb).await?;
172+ // let user = user_info_opt(session_id.0.as_ref(), state).await?
173+ // .and_then(|user| if user.email == event.owner {Some(user)} else {None});
174+ // Ok(user)
175+ // }
176176
177177pub fn is_event_owner ( event : & EventRecord , user : Option < & UserInfo > ) -> bool {
178178 if let Some ( user) = user {
@@ -308,7 +308,7 @@ async fn get_event_start_list(event_id: EventId, session_id: MaybeSessionId, cla
308308 . fetch_all ( & edb) . await . map_err ( sqlx_to_custom_error) ?;
309309 let changes = sqlx:: query_as :: < _ , ChangesRecord > ( "SELECT changes.* FROM changes, runs
310310 WHERE runs.class_name=?
311- AND changes.run_id =runs.run_id
311+ AND changes.data_id =runs.run_id
312312 AND changes.data_type=?
313313 AND changes.status=?" )
314314 . bind ( & class_name)
@@ -362,25 +362,7 @@ async fn get_event_results(event_id: EventId, class_name: Option<&str>, state: &
362362 } ) )
363363
364364}
365- #[ post( "/api/event/current/upload/startlist" , data = "<data>" ) ]
366- async fn upload_start_list ( qx_api_token : QxApiToken , data : Data < ' _ > , content_type : & ContentType , state : & State < SharedQxState > , gdb : & State < DbPool > ) -> Result < String , Custom < String > > {
367- let event_info = load_event_info_for_api_token ( & qx_api_token, gdb) . await ?;
368- let edb = get_event_db ( event_info. id , state) . await . map_err ( anyhow_to_custom_error) ?;
369- let file_id = crate :: files:: upload_file ( qx_api_token, START_LIST_IOFXML3_FILE , data, content_type, state, gdb) . await ?;
370- import_start_list ( event_info. id , & edb, gdb) . await . map_err ( anyhow_to_custom_error) ?;
371- Ok ( file_id. to_string ( ) )
372- }
373- #[ post( "/api/event/<event_id>/upload/startlist" , data = "<data>" ) ]
374- async fn upload_start_list_user ( event_id : EventId , data : Data < ' _ > , content_type : & ContentType , session_id : MaybeSessionId , state : & State < SharedQxState > , gdb : & State < DbPool > ) -> Result < String , Custom < String > > {
375- let Some ( _event_owner) = event_owner_opt ( event_id, session_id, state, gdb) . await . map_err ( anyhow_to_custom_error) ? else {
376- return Err ( Custom ( Status :: Unauthorized , String :: from ( "Session expired or not valid" ) ) ) ;
377- } ;
378- let event_info = load_event_info ( event_id, gdb) . await ?;
379- let edb = get_event_db ( event_info. id , state) . await . map_err ( anyhow_to_custom_error) ?;
380- let file_id = crate :: files:: upload_file ( event_info. api_token , START_LIST_IOFXML3_FILE , data, content_type, state, gdb) . await ?;
381- import_start_list ( event_info. id , & edb, gdb) . await . map_err ( anyhow_to_custom_error) ?;
382- Ok ( file_id. to_string ( ) )
383- }
365+
384366pub async fn import_start_list ( event_id : EventId , edb : & SqlitePool , gdb : & State < DbPool > ) -> anyhow:: Result < ( ) > {
385367 let data = sqlx:: query_as :: < _ , ( Vec < u8 > , ) > ( "SELECT data FROM files WHERE name=?" )
386368 . bind ( START_LIST_IOFXML3_FILE )
@@ -432,15 +414,6 @@ pub async fn import_start_list(event_id: EventId, edb: &SqlitePool, gdb: &State<
432414 Ok ( ( ) )
433415}
434416
435- #[ post( "/api/event/current/upload/runs" , data = "<data>" ) ]
436- async fn upload_runs ( qx_api_token : QxApiToken , data : Data < ' _ > , content_type : & ContentType , state : & State < SharedQxState > , gdb : & State < DbPool > ) -> Result < String , Custom < String > > {
437- let event_info = load_event_info_for_api_token ( & qx_api_token, gdb) . await ?;
438- let edb = get_event_db ( event_info. id , state) . await . map_err ( anyhow_to_custom_error) ?;
439- let file_id = crate :: files:: upload_file ( qx_api_token, RUNS_CSV_FILE , data, content_type, state, gdb) . await ?;
440- import_runs ( & edb) . await . map_err ( anyhow_to_custom_error) ?;
441- Ok ( file_id)
442- }
443-
444417pub async fn import_runs ( edb : & SqlitePool ) -> anyhow:: Result < ( ) > {
445418 let data = load_file_from_db ( RUNS_CSV_FILE , edb) . await ?;
446419 let mut rdr = csv:: Reader :: from_reader ( & * data) ;
@@ -526,13 +499,10 @@ pub fn extend(rocket: Rocket<Build>) -> Rocket<Build> {
526499 event_delete,
527500 post_event,
528501 get_event,
529- upload_start_list,
530- upload_start_list_user,
531502 get_event_start_list,
532503 get_event_results,
533504 get_api_event_current,
534505 post_api_event_current,
535- upload_runs,
536506 ] )
537507}
538508
0 commit comments