From c62357fd3e742235e27c7b0eaa6cfbb84c22a4ae Mon Sep 17 00:00:00 2001 From: David Westgate Date: Wed, 24 Apr 2024 13:05:09 -0700 Subject: [PATCH] added serde dep; added questions.rs --- Cargo.lock | 9 +++++---- Cargo.toml | 1 + src/question.rs | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 src/question.rs diff --git a/Cargo.lock b/Cargo.lock index ba935d8..ca0a6c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -733,6 +733,7 @@ name = "rust-web" version = "0.1.0" dependencies = [ "axum", + "serde", "tokio", "warp", ] @@ -769,18 +770,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index d85ee70..bbd9458 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,6 @@ edition = "2021" [dependencies] axum = "0.7.5" +serde = "1.0.198" tokio = { version = "1.2", features = ["full"] } warp = "0.3.7" diff --git a/src/question.rs b/src/question.rs new file mode 100644 index 0000000..96ea397 --- /dev/null +++ b/src/question.rs @@ -0,0 +1,25 @@ +struct Question { + id: QuestionId, + title: String, + content: String, + tags: Option>, +} + +struct QuestionId(String); + +impl Question{ + fn new(id: QuestionId, title: String, content: String, tags: Option>) -> Self { + Question { + id, + title, + content, + tags, + } + } +} + +impl IntoResponse for &Question { + fn into_response(self) -> Response { + (StatusCode::OK, Json(&self)).into_response() + } +} \ No newline at end of file