Skip to content

Commit

Permalink
#250 - notes can be NULL + added to PublicRun
Browse files Browse the repository at this point in the history
  • Loading branch information
bracyw committed Nov 28, 2024
1 parent 0532c39 commit 119d3db
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions angular-client/src/utils/types.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type Run = {
locationName: string;
driverName: string;
time: Date;
notes: string;
};

export type Coordinate = {
Expand Down
10 changes: 7 additions & 3 deletions scylla-server/migrations/2024-11-10-031516_create_all/down.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
-- This file should undo anything in `up.sql`
DROP TABLE "run";
-- Drop Foreign Keys
ALTER TABLE "data" DROP CONSTRAINT "data_runId_fkey";
ALTER TABLE "data" DROP CONSTRAINT "data_dataTypeName_fkey";

-- Drop Tables
DROP TABLE "data";
DROP TABLE "dataType";
DROP TABLE "dataType";
DROP TABLE "run";
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE "run" (
"latitude" DOUBLE PRECISION,
"longitude" DOUBLE PRECISION,
"driverName" TEXT,
"notes" TEXT NOT NULL,
"notes" TEXT,
"time" TIMESTAMPTZ NOT NULL,

CONSTRAINT "run_pkey" PRIMARY KEY ("id")
Expand Down
2 changes: 1 addition & 1 deletion scylla-server/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ pub struct Run {
pub latitude: Option<f64>,
pub longitude: Option<f64>,
pub driverName: Option<String>,
pub notes: String,
pub notes: Option<String>,
pub time: DateTime<Utc>,
}
8 changes: 6 additions & 2 deletions scylla-server/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ diesel::table! {
latitude -> Nullable<Float8>,
longitude -> Nullable<Float8>,
driverName -> Nullable<Text>,
notes -> Text,
notes -> Nullable<Text>,
time -> Timestamptz,
}
}

diesel::joinable!(data -> dataType (dataTypeName));
diesel::joinable!(data -> run (runId));

diesel::allow_tables_to_appear_in_same_query!(data, dataType, run,);
diesel::allow_tables_to_appear_in_same_query!(
data,
dataType,
run,
);
4 changes: 2 additions & 2 deletions scylla-server/src/services/run_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn create_run(
timestamp: DateTime<Utc>,
) -> Result<Run, diesel::result::Error> {
diesel::insert_into(run)
.values((time.eq(timestamp), notes.eq("A")))
.values(time.eq(timestamp))
.get_result(db)
}

Expand All @@ -44,7 +44,7 @@ pub async fn create_run_with_id(
run_id: i32,
) -> Result<Run, diesel::result::Error> {
diesel::insert_into(run)
.values((time.eq(timestamp), id.eq(run_id), notes.eq("A")))
.values((time.eq(timestamp), id.eq(run_id)))
.get_result(db)
}

Expand Down
2 changes: 2 additions & 0 deletions scylla-server/src/transformers/run_transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct PublicRun {
pub driver_name: String,
#[serde(rename = "time")]
pub time_ms: i64,
pub notes: String,
}

impl From<crate::models::Run> for PublicRun {
Expand All @@ -19,6 +20,7 @@ impl From<crate::models::Run> for PublicRun {
location_name: value.locationName.unwrap_or_default(),
driver_name: value.driverName.clone().unwrap_or_default(),
time_ms: value.time.timestamp_millis(),
notes: value.notes.unwrap_or_default(),
}
}
}

0 comments on commit 119d3db

Please sign in to comment.