From 6f565074be9c4ef6c77145adb6139f63e48cd9e9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 24 Oct 2021 13:07:01 +0200 Subject: Outsource API type definitions to library crate Signed-off-by: Matthias Beyer --- person-api-types/Cargo.toml | 9 +++++++++ person-api-types/src/lib.rs | 19 +++++++++++++++++++ service-person/Cargo.toml | 3 +++ service-person/src/main.rs | 17 +---------------- 4 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 person-api-types/Cargo.toml create mode 100644 person-api-types/src/lib.rs diff --git a/person-api-types/Cargo.toml b/person-api-types/Cargo.toml new file mode 100644 index 0000000..e1665fc --- /dev/null +++ b/person-api-types/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "person-api-types" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = "1" diff --git a/person-api-types/src/lib.rs b/person-api-types/src/lib.rs new file mode 100644 index 0000000..aa0af0a --- /dev/null +++ b/person-api-types/src/lib.rs @@ -0,0 +1,19 @@ +pub mod v1 { + pub mod person { + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct PersonCreateRequestData { + pub name: String, + pub age: i32, + + pub country: String, + pub city: String, + pub street: String, + pub number: i32, + } + + #[derive(Debug, serde::Serialize, serde::Deserialize)] + pub struct PersonCreateResponse { + pub id: i32 + } + } +} diff --git a/service-person/Cargo.toml b/service-person/Cargo.toml index 833bdd2..9740298 100644 --- a/service-person/Cargo.toml +++ b/service-person/Cargo.toml @@ -12,3 +12,6 @@ serde = "1" diesel = { version = "1.4.4", features = ["postgres", "r2d2"] } diesel_migrations = "1.4" getset = "0.1" + +person-api-types = { path = "./../person-api-types" } + diff --git a/service-person/src/main.rs b/service-person/src/main.rs index 31050e0..75964b0 100644 --- a/service-person/src/main.rs +++ b/service-person/src/main.rs @@ -13,25 +13,10 @@ mod model; mod schema; use crate::db::DbPool; +use person_api_types::v1::person::*; embed_migrations!("migrations"); -#[derive(Debug, serde::Deserialize)] -pub struct PersonCreateRequestData { - name: String, - age: i32, - - country: String, - city: String, - street: String, - number: i32, -} - -#[derive(Debug, serde::Serialize)] -pub struct PersonCreateResponse { - id: i32 -} - async fn create_person(db: web::Data, person: web::Json) -> impl Responder { log::debug!("Creating person = {:?}", person); -- cgit v1.2.3