Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit a229ebf

Browse files
committed
Remove endpoints upload/startlist and /api/event/current/upload/runs
1 parent b0c747a commit a229ebf

7 files changed

Lines changed: 32 additions & 81 deletions

File tree

db/migrations/20250621184259_changes_table_rename_run_id_to_data_id.sql

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/changes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub struct ChangesRecord {
116116
pub data: ChangeData,
117117
pub user_id: Option<String>,
118118
// we need run_id to be able to pair changes with rows in runs table
119-
pub run_id: Option<i64>,
119+
// pub run_id: Option<i64>,
120120
pub status: Option<ChangeStatus>,
121121
pub created: QxDateTime,
122122
}

src/event.rs

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use std::io::{Cursor, Read};
44
use anyhow::anyhow;
55
use image::ImageFormat;
66
use rocket::form::{Contextual, Form};
7-
use rocket::http::{ContentType, Status};
7+
use rocket::http::{Status};
88
use rocket::response::{Redirect};
99
use rocket::response::status::Custom;
10-
use rocket::{Build, Data, Rocket, State};
10+
use rocket::{Build, Rocket, State};
1111
use rocket_dyn_templates::{context, Template};
1212
use sqlx::{query, query_as, FromRow, SqlitePool};
1313
use 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

177177
pub 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+
384366
pub 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-
444417
pub 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

src/files.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rocket::response::status::{Custom};
66
use rocket::serde::json::Json;
77
use serde::{Deserialize, Serialize};
88
use crate::db::{get_event_db, DbPool};
9-
use crate::event::{load_event_info_for_api_token, EventId};
9+
use crate::event::{import_runs, import_start_list, load_event_info_for_api_token, EventId, RUNS_CSV_FILE, START_LIST_IOFXML3_FILE};
1010
use crate::{QxApiToken, SharedQxState};
1111
use crate::util::{anyhow_to_custom_error, sqlx_to_anyhow, sqlx_to_custom_error, unzip_data};
1212

@@ -83,6 +83,12 @@ pub async fn upload_file(qx_api_token: QxApiToken, name: &str, data: Data<'_>, c
8383
data
8484
};
8585
let file_id = save_file_to_db(name, &data, &edb).await.map_err(anyhow_to_custom_error)?;
86+
if name == START_LIST_IOFXML3_FILE {
87+
import_start_list(event_info.id, &edb, gdb).await.map_err(anyhow_to_custom_error)?;
88+
}
89+
else if name == RUNS_CSV_FILE {
90+
import_runs(&edb).await.map_err(anyhow_to_custom_error)?;
91+
}
8692
Ok(format!("{file_id}"))
8793
}
8894
pub fn extend(rocket: Rocket<Build>) -> Rocket<Build> {

src/tests.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,26 @@ fn upload_file() {
100100
assert!(files.iter().find(|f| f.name == file_name).is_none());
101101
}
102102

103-
fn upload_start_list_impl(client: &Client) {
104-
let mut file = OpenOptions::new().read(true).open(format!("tests/{START_LIST_IOFXML3_FILE}")).unwrap();
103+
fn upload_test_file(client: &Client, file_name: &str) {
104+
let mut file = OpenOptions::new().read(true).open(format!("tests/{file_name}")).unwrap();
105105
let mut data = vec![];
106106
file.read_to_end(&mut data).unwrap();
107107

108108
let compressed = util::test::zip_data(&data).unwrap();
109-
let resp = client.post("/api/event/current/upload/startlist")
109+
let resp = client.post(format!("/api/event/current/file?name={file_name}"))
110110
.header(Header::new("qx-api-token", API_TOKEN))
111111
.header(ContentType::ZIP)
112112
.body(compressed)
113113
.dispatch();
114114
assert_eq!(resp.status(), Status::Ok);
115115
}
116+
fn upload_start_list(client: &Client) {
117+
upload_test_file(&client, START_LIST_IOFXML3_FILE);
118+
}
116119
#[test]
117-
fn upload_start_list() {
120+
fn test_upload_start_list() {
118121
let client = create_test_server();
119-
upload_start_list_impl(&client);
122+
upload_start_list(&client);
120123
// get start list page
121124
let resp = client.get(format!("/event/{EVENT_ID}/startlist")).dispatch();
122125
assert_eq!(resp.status(), Status::Ok);
@@ -125,7 +128,7 @@ fn upload_start_list() {
125128
#[test]
126129
fn post_qe_change() {
127130
let client = create_test_server();
128-
upload_start_list_impl(&client);
131+
upload_start_list(&client);
129132

130133
fn apply_change(client: &Client, run_id: DataId, change: &RunsRecord) -> RunsRecord {
131134
let resp = client.post(format!("/api/event/current/changes/run-updated?run_id={}", run_id.unwrap()))

templates/changes.html.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<tr class="w3-theme-l1">
99
<th>Status</th>
1010
<th>Data</th>
11-
<th class="w3-right-align">Run Id</th>
11+
<th class="w3-right-align">Data Id</th>
1212
<th>Source</th>
1313
<th>User ID</th>
1414
<th>Created</th>
@@ -19,7 +19,7 @@
1919
<tr>
2020
<td>{{ stringify status }}</td>
2121
<td>{{ stringify data }}</td>
22-
<td class="w3-right-align">{{ run_id }}</td>
22+
<td class="w3-right-align">{{ data_id }}</td>
2323
<td>{{ source }}</td>
2424
<td>{{ user_id }}</td>
2525
<td>{{ created }}</td>

templates/startlist.html.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@
139139
else {
140140
change.run_id = edited_entry.run_id;
141141
}
142-
fetch('/api/event/{{ event.id }}/changes/run-update-request', {
142+
const params = new URLSearchParams();
143+
params.append("data_id", change.run_id);
144+
fetch(`/api/event/{{ event.id }}/changes/run-update-request?${params}`, {
143145
method: 'POST',
144146
body: JSON.stringify(change),
145147
headers: {

0 commit comments

Comments
 (0)