Skip to content

Commit 5cca58a

Browse files
committed
added get endpoint for time labels by range and registered route
1 parent 6f3033b commit 5cca58a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

backend/api-server/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,27 @@ async fn store_time_labels(
302302
}
303303
}
304304

305+
// Handler for GET /api/sessions/{session_id}/time-label
306+
// Returns time labels within a given time range (passed as ?start=...&end=... query params).
307+
async fn get_time_labels(
308+
State(app_state): State<AppState>,
309+
Path(session_id): Path<i32>,
310+
Query(params): Query<EegDataQuery>,
311+
) -> Result<Json<Vec<TimeLabel>>, (StatusCode, String)> {
312+
info!("Received request to get time labels for session {} from {} to {}", session_id, params.start, params.end);
313+
314+
match get_time_labels_by_range(&app_state.db_client, session_id, params.start, params.end).await {
315+
Ok(labels) => {
316+
info!("Retrieved {} time labels", labels.len());
317+
Ok(Json(labels))
318+
}
319+
Err(e) => {
320+
error!("Failed to get time labels: {}", e);
321+
Err((StatusCode::INTERNAL_SERVER_ERROR, format!("Failed to get time labels: {}", e)))
322+
}
323+
}
324+
}
325+
305326
// Handler for GET /api/sessions/{session_id}/eeg-data
306327
// Returns EEG data rows within a given time range (passed as ?start=...&end=... query params).
307328
async fn get_eeg_data(
@@ -414,6 +435,7 @@ async fn main() {
414435
.route("/api/sessions/:session_id/frontend-state", get(get_frontend_state))
415436

416437
.route("/api/sessions/:session_id/time-label", post(store_time_labels))
438+
.route("/api/sessions/:session_id/time-label", get(get_time_labels))
417439
.route("/api/sessions/:session_id/eeg-data", get(get_eeg_data))
418440
.route("/api/sessions/:session_id/eeg_data/export", post(export_eeg_data))
419441

0 commit comments

Comments
 (0)