From b01b33f7d1d147beaf56215c620344273432cb81 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 3 Oct 2022 22:20:01 +0200 Subject: [PATCH] add core models --- Cargo.lock | 1 + como_domain/Cargo.toml | 2 +- como_domain/src/item/mod.rs | 21 +++++++++++++++++++++ como_domain/src/item/requests.rs | 6 ++++++ como_domain/src/item/responses.rs | 3 +++ como_domain/src/lib.rs | 2 ++ como_domain/src/projects/mod.rs | 11 +++++++++++ como_domain/src/projects/requests.rs | 6 ++++++ como_domain/src/projects/responses.rs | 3 +++ como_domain/src/users/mod.rs | 2 +- como_domain/src/users/responses.rs | 3 +++ 11 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 como_domain/src/item/mod.rs create mode 100644 como_domain/src/item/requests.rs create mode 100644 como_domain/src/item/responses.rs create mode 100644 como_domain/src/projects/requests.rs create mode 100644 como_domain/src/projects/responses.rs diff --git a/Cargo.lock b/Cargo.lock index cbbb48c..2b54c4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2452,6 +2452,7 @@ checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f" dependencies = [ "getrandom", "rand", + "serde", ] [[package]] diff --git a/como_domain/Cargo.toml b/como_domain/Cargo.toml index e95d23f..f6b02b6 100644 --- a/como_domain/Cargo.toml +++ b/como_domain/Cargo.toml @@ -9,4 +9,4 @@ edition = "2021" anyhow = "1.0.60" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.68" -uuid = { version = "1.1.2", features = ["v4", "fast-rng"] } +uuid = { version = "1.1.2", features = ["v4", "fast-rng", "serde"] } diff --git a/como_domain/src/item/mod.rs b/como_domain/src/item/mod.rs new file mode 100644 index 0000000..99f565a --- /dev/null +++ b/como_domain/src/item/mod.rs @@ -0,0 +1,21 @@ +pub mod requests; +pub mod responses; + +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +#[derive(Debug, Deserialize, Serialize)] +pub enum ItemState { + Created, + Done, + Archived, + Deleted, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct ItemDto { + pub id: Uuid, + pub title: String, + pub description: Option, + pub state: ItemState, +} diff --git a/como_domain/src/item/requests.rs b/como_domain/src/item/requests.rs new file mode 100644 index 0000000..1a5cf78 --- /dev/null +++ b/como_domain/src/item/requests.rs @@ -0,0 +1,6 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct CreateItemDto { + pub name: String, +} diff --git a/como_domain/src/item/responses.rs b/como_domain/src/item/responses.rs new file mode 100644 index 0000000..65f45a5 --- /dev/null +++ b/como_domain/src/item/responses.rs @@ -0,0 +1,3 @@ +use super::ItemDto; + +pub type CreatedItemDto = ItemDto; diff --git a/como_domain/src/lib.rs b/como_domain/src/lib.rs index 913bd46..6823a88 100644 --- a/como_domain/src/lib.rs +++ b/como_domain/src/lib.rs @@ -1 +1,3 @@ +pub mod item; +pub mod projects; pub mod users; diff --git a/como_domain/src/projects/mod.rs b/como_domain/src/projects/mod.rs index e69de29..ba68ade 100644 --- a/como_domain/src/projects/mod.rs +++ b/como_domain/src/projects/mod.rs @@ -0,0 +1,11 @@ +pub mod requests; +pub mod responses; + +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +#[derive(Debug, Serialize, Deserialize)] +pub struct ProjectDto { + pub id: Uuid, + pub name: String, +} diff --git a/como_domain/src/projects/requests.rs b/como_domain/src/projects/requests.rs new file mode 100644 index 0000000..9e414b7 --- /dev/null +++ b/como_domain/src/projects/requests.rs @@ -0,0 +1,6 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +pub struct CreateProjectDto { + pub name: String, +} diff --git a/como_domain/src/projects/responses.rs b/como_domain/src/projects/responses.rs new file mode 100644 index 0000000..f12d9ff --- /dev/null +++ b/como_domain/src/projects/responses.rs @@ -0,0 +1,3 @@ +use super::ProjectDto; + +pub type CreatedProjectDto = ProjectDto; diff --git a/como_domain/src/users/mod.rs b/como_domain/src/users/mod.rs index 96d0662..cd1febc 100644 --- a/como_domain/src/users/mod.rs +++ b/como_domain/src/users/mod.rs @@ -1,11 +1,11 @@ pub mod requests; +pub mod responses; use serde::{Deserialize, Serialize}; use uuid::Uuid; #[derive(Serialize, Deserialize, Debug)] pub struct UserDto { - #[serde(skip_serializing, skip_deserializing)] pub id: Uuid, pub username: String, pub email: String, diff --git a/como_domain/src/users/responses.rs b/como_domain/src/users/responses.rs index e69de29..025ad92 100644 --- a/como_domain/src/users/responses.rs +++ b/como_domain/src/users/responses.rs @@ -0,0 +1,3 @@ +use super::UserDto; + +pub type UserCreatedDto = UserDto;