diff --git a/backend/migrations/20260310120000_update_time_labels.sql b/backend/migrations/20260310120000_update_time_labels.sql new file mode 100644 index 0000000..ce7bc0f --- /dev/null +++ b/backend/migrations/20260310120000_update_time_labels.sql @@ -0,0 +1,4 @@ +ALTER TABLE time_labels RENAME COLUMN timestamp TO start_timestamp; +ALTER TABLE time_labels ADD COLUMN end_timestamp TIMESTAMPTZ; +ALTER TABLE time_labels ADD COLUMN color TEXT NOT NULL DEFAULT ''; +ALTER TABLE time_labels ALTER COLUMN color DROP DEFAULT; diff --git a/backend/shared-logic/src/db.rs b/backend/shared-logic/src/db.rs index 285ecf8..b90ae15 100644 --- a/backend/shared-logic/src/db.rs +++ b/backend/shared-logic/src/db.rs @@ -372,13 +372,15 @@ pub async fn insert_time_labels(client: &DbClient, session_id: i32, labels: Vec< } let mut query_builder = sqlx::QueryBuilder::new( - "INSERT INTO time_labels (session_id, timestamp, label) " + "INSERT INTO time_labels (session_id, start_timestamp, end_timestamp, label, color) " ); query_builder.push_values(labels.iter(), |mut b, label| { b.push_bind(session_id) - .push_bind(label.timestamp) - .push_bind(&label.label); + .push_bind(label.start_timestamp) + .push_bind(label.end_timestamp) + .push_bind(&label.label) + .push_bind(&label.color); }); query_builder.build().execute(&**client).await?; @@ -416,7 +418,7 @@ pub async fn get_time_labels_by_range(client: &DbClient, session_id: i32, start: let labels = sqlx::query_as!( TimeLabel, - "SELECT id, session_id, timestamp, label FROM time_labels WHERE session_id = $1 AND timestamp >= $2 AND timestamp <= $3 ORDER BY timestamp", + "SELECT id, session_id, start_timestamp, end_timestamp, label, color FROM time_labels WHERE session_id = $1 AND start_timestamp >= $2 AND start_timestamp <= $3 ORDER BY start_timestamp", session_id, start, end, diff --git a/backend/shared-logic/src/models.rs b/backend/shared-logic/src/models.rs index 92c51b5..b91c289 100644 --- a/backend/shared-logic/src/models.rs +++ b/backend/shared-logic/src/models.rs @@ -54,16 +54,20 @@ pub struct FrontendState { pub struct TimeLabel { pub id: i32, pub session_id: i32, - pub timestamp: DateTime, + pub start_timestamp: DateTime, + pub end_timestamp: Option>, pub label: String, + pub color: String, } // Struct for a time label coming INTO the API from the frontend // No id (auto-generated) or session_id (comes from URL path) #[derive(Debug, Serialize, Deserialize)] pub struct NewTimeLabel { - pub timestamp: DateTime, + pub start_timestamp: DateTime, + pub end_timestamp: Option>, pub label: String, + pub color: String, } // Struct for a row of EEG data coming OUT of the DB