Skip to content

Commit

Permalink
added support for driver and location for the update route
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsoto committed Jan 21, 2025
1 parent e283dd4 commit 8f79cf1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 6 additions & 4 deletions scylla-server/src/controllers/run_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ pub async fn new_run_with_data(
}

/// updates a run's notes with a given run id
pub async fn update_run_with_notes(
pub async fn update_run_with_data(
State(pool): State<PoolHandle>,
Path((run_id, run_notes)): Path<(i32, String)>,
Path((run_id, driver, location, run_notes)): Path<(i32, String, String, String)>,
) -> Result<Json<PublicRun>, ScyllaError> {
let mut db = pool.get().await?;
let updated_run = run_service::update_run_notes_with_run_id(&mut db, run_id, run_notes).await?;
let updated_run_data =
run_service::update_run_data_with_run_id(&mut db, run_id, driver, location, run_notes)
.await?;

Ok(Json::from(PublicRun::from(updated_run)))
Ok(Json::from(PublicRun::from(updated_run_data)))
}
4 changes: 2 additions & 2 deletions scylla-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.route("/runs/new", post(run_controller::new_run))
.route("/runs/new/{driver}/{location}/{notes}", post(run_controller::new_run_with_data))
.route(
"/runs/update/{id}/{notes}",
post(run_controller::update_run_with_notes),
"/runs/update/{id}/{driver}/{location}/{notes}",
post(run_controller::update_run_with_data),
)
// CONFIG
.route(
Expand Down
14 changes: 11 additions & 3 deletions scylla-server/src/services/run_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,26 @@ pub async fn create_run_with_data(
.await
}

/// Updates a run note with a given run id
/// Updates run data with a given run id
/// * `db` - The prisma client to make the call to
/// * `run_id` - The id of the run to search for
/// * `driver` - The driver's name
/// * `location` - The location of the runs
/// * `run_notes` - The updated run notes
/// returns: A result containing the data or the QueryError propogated by the db
pub async fn update_run_notes_with_run_id(
pub async fn update_run_data_with_run_id(
db: &mut Database<'_>,
run_id: i32,
driver: String,
location: String,
run_notes: String,
) -> Result<Run, diesel::result::Error> {
diesel::update(run.filter(runId.eq(run_id)))
.set(notes.eq(run_notes))
.set((
driverName.eq(driver),
locationName.eq(location),
notes.eq(run_notes)
))
.get_result(db)
.await
}

0 comments on commit 8f79cf1

Please sign in to comment.