summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-10-22 20:32:07 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-10-24 12:02:00 +0200
commitc658f2ed24fd672b17b077db1bd659e2be830b1d (patch)
tree1fd1346935ce0260b7d41768c3a70f18955e4f63
parent14b981c63d558969bc29b25ca40e8b249d072ebb (diff)
Move "model" types to model.rs
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--service-person/src/main.rs22
-rw-r--r--service-person/src/model.rs32
2 files changed, 34 insertions, 20 deletions
diff --git a/service-person/src/main.rs b/service-person/src/main.rs
index 81be674..759050d 100644
--- a/service-person/src/main.rs
+++ b/service-person/src/main.rs
@@ -2,28 +2,10 @@ use std::str::FromStr;
use anyhow::Context;
use actix_web::{web, App, HttpServer, HttpResponse, Result};
-use serde::Deserialize;
-#[derive(Debug, Deserialize)]
-struct Name(String);
+mod model;
-#[derive(Debug, Deserialize)]
-struct Age(usize);
-
-#[derive(Debug, Deserialize)]
-struct Address {
- street: String,
- number: String,
- city: String,
- country: String,
-}
-
-#[derive(Debug, Deserialize)]
-struct Person {
- name: Name,
- age: Age,
- addr: Address,
-}
+use model::*;
async fn create_person(person: web::Json<Person>) -> Result<HttpResponse> {
log::debug!("Creating person = {:?}", person);
diff --git a/service-person/src/model.rs b/service-person/src/model.rs
new file mode 100644
index 0000000..aa81312
--- /dev/null
+++ b/service-person/src/model.rs
@@ -0,0 +1,32 @@
+use serde::Deserialize;
+
+#[derive(Debug, Deserialize)]
+pub struct Name(String);
+
+#[derive(Debug, Deserialize)]
+pub struct Age(usize);
+
+#[derive(Debug, Deserialize)]
+pub struct Street(String);
+
+#[derive(Debug, Deserialize)]
+pub struct City(String);
+
+#[derive(Debug, Deserialize)]
+pub struct Country(String);
+
+#[derive(Debug, Deserialize)]
+pub struct Address {
+ country: Country,
+ city: City,
+ street: Street,
+ number: usize,
+}
+
+#[derive(Debug, Deserialize)]
+pub struct Person {
+ name: Name,
+ age: Age,
+ addr: Address,
+}
+