summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-10-24 13:07:01 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-10-24 13:25:02 +0200
commit6f565074be9c4ef6c77145adb6139f63e48cd9e9 (patch)
tree298ba5f2d27481a29438b325ec376e70e248a941
parent968dabc3653b7c19327021befb8b05ae806362fa (diff)
Outsource API type definitions to library crate
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--person-api-types/Cargo.toml9
-rw-r--r--person-api-types/src/lib.rs19
-rw-r--r--service-person/Cargo.toml3
-rw-r--r--service-person/src/main.rs17
4 files changed, 32 insertions, 16 deletions
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<DbPool>, person: web::Json<PersonCreateRequestData>) -> impl Responder {
log::debug!("Creating person = {:?}", person);