diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-11-14 18:17:32 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-11-14 18:17:32 +0200 |
commit | 5c9261b0e7a30f4354cf7c779b8a650a0f1db10d (patch) | |
tree | 02d981054bd4d23d3f5efb059e8d611c83dae9fc | |
parent | 08cec7ca854f2b8b36bc8089f84675546c1a4866 (diff) | |
download | native-ci-simulation-5c9261b0e7a30f4354cf7c779b8a650a0f1db10d.tar.gz |
POST includes commit to build
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index a70ba44..b9a4a8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,11 @@ use axum::{ - extract::State, + extract::{self, State}, http::StatusCode, response::IntoResponse, routing::{get, post}, Json, Router, }; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::sync::{Arc, Mutex}; @@ -33,19 +33,30 @@ struct RunCounter { next: Arc<Mutex<usize>>, } +#[derive(Deserialize)] +struct Start { + commit: String, +} + #[derive(Serialize)] struct Run { id: String, + commit: String, } -async fn create_run(State(counter): State<RunCounter>) -> (StatusCode, impl IntoResponse) { +async fn create_run( + State(counter): State<RunCounter>, + extract::Json(start): extract::Json<Start>, +) -> (StatusCode, impl IntoResponse) { let mut next = counter.next.lock().expect("mutex was poisoned"); let id = *next; *next += 1; + ( StatusCode::CREATED, Json(Run { id: format!("{}", id), + commit: start.commit, }), ) } |