37
crates/como_domain/src/common/mod.rs
Normal file
37
crates/como_domain/src/common/mod.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
pub mod user;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Context {
|
||||
values: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
values: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_value(&self, key: impl Into<String>, value: impl Into<String>) -> Self {
|
||||
let mut values = self.values.clone();
|
||||
|
||||
let _ = values.insert(key.into(), value.into());
|
||||
|
||||
Self { values }
|
||||
}
|
||||
|
||||
pub fn with_value_mut(
|
||||
&mut self,
|
||||
key: impl Into<String>,
|
||||
value: impl Into<String>,
|
||||
) -> &mut Self {
|
||||
self.values.insert(key.into(), value.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get(&self, key: impl AsRef<str>) -> Option<&str> {
|
||||
self.values.get(key.as_ref()).map(|s| s.as_str())
|
||||
}
|
||||
}
|
23
crates/como_domain/src/common/user.rs
Normal file
23
crates/como_domain/src/common/user.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use crate::Context;
|
||||
|
||||
pub trait ContextUserExt {
|
||||
fn set_user_id(&self, user_id: impl Into<String>) -> Context;
|
||||
fn set_user_id_mut(&mut self, user_id: impl Into<String>) -> &mut Context;
|
||||
fn get_user_id(&self) -> Option<String>;
|
||||
}
|
||||
|
||||
const USER_ID_KEY: &str = "user_id";
|
||||
|
||||
impl ContextUserExt for Context {
|
||||
fn set_user_id(&self, user_id: impl Into<String>) -> Context {
|
||||
self.with_value(USER_ID_KEY, user_id)
|
||||
}
|
||||
|
||||
fn set_user_id_mut(&mut self, user_id: impl Into<String>) -> &mut Context {
|
||||
self.with_value_mut(USER_ID_KEY, user_id)
|
||||
}
|
||||
|
||||
fn get_user_id(&self) -> Option<String> {
|
||||
self.get(USER_ID_KEY).map(|s| s.to_string())
|
||||
}
|
||||
}
|
24
crates/como_domain/src/item/mod.rs
Normal file
24
crates/como_domain/src/item/mod.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
pub mod queries;
|
||||
pub mod requests;
|
||||
pub mod responses;
|
||||
|
||||
use async_graphql::{Enum, InputObject};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, Enum, Copy)]
|
||||
pub enum ItemState {
|
||||
Created,
|
||||
Done,
|
||||
Archived,
|
||||
Deleted,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject)]
|
||||
pub struct ItemDto {
|
||||
pub id: Uuid,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub state: ItemState,
|
||||
pub project_id: Uuid,
|
||||
}
|
13
crates/como_domain/src/item/queries.rs
Normal file
13
crates/como_domain/src/item/queries.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use async_graphql::InputObject;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject)]
|
||||
pub struct GetItemQuery {
|
||||
pub item_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject)]
|
||||
pub struct GetItemsQuery {
|
||||
pub project_id: Uuid,
|
||||
}
|
21
crates/como_domain/src/item/requests.rs
Normal file
21
crates/como_domain/src/item/requests.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use async_graphql::InputObject;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::ItemState;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject)]
|
||||
pub struct CreateItemDto {
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub project_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject)]
|
||||
pub struct UpdateItemDto {
|
||||
pub id: Uuid,
|
||||
pub title: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub state: Option<ItemState>,
|
||||
pub project_id: Option<Uuid>,
|
||||
}
|
3
crates/como_domain/src/item/responses.rs
Normal file
3
crates/como_domain/src/item/responses.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
use super::ItemDto;
|
||||
|
||||
pub type CreatedItemDto = ItemDto;
|
6
crates/como_domain/src/lib.rs
Normal file
6
crates/como_domain/src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
pub mod common;
|
||||
pub mod item;
|
||||
pub mod projects;
|
||||
pub mod users;
|
||||
|
||||
pub use common::*;
|
17
crates/como_domain/src/projects/mod.rs
Normal file
17
crates/como_domain/src/projects/mod.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
pub mod mutation;
|
||||
pub mod queries;
|
||||
pub mod requests;
|
||||
pub mod responses;
|
||||
|
||||
use async_graphql::{InputObject, SimpleObject};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject, SimpleObject)]
|
||||
pub struct ProjectDto {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
|
||||
pub user_id: String,
|
||||
}
|
8
crates/como_domain/src/projects/mutation.rs
Normal file
8
crates/como_domain/src/projects/mutation.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use async_graphql::InputObject;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject)]
|
||||
pub struct CreateProjectMutation {
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
}
|
8
crates/como_domain/src/projects/queries.rs
Normal file
8
crates/como_domain/src/projects/queries.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use async_graphql::InputObject;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, InputObject)]
|
||||
pub struct GetProjectQuery {
|
||||
pub project_id: Uuid,
|
||||
}
|
6
crates/como_domain/src/projects/requests.rs
Normal file
6
crates/como_domain/src/projects/requests.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CreateProjectDto {
|
||||
pub name: String,
|
||||
}
|
3
crates/como_domain/src/projects/responses.rs
Normal file
3
crates/como_domain/src/projects/responses.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
use super::ProjectDto;
|
||||
|
||||
pub type CreatedProjectDto = ProjectDto;
|
17
crates/como_domain/src/users/mod.rs
Normal file
17
crates/como_domain/src/users/mod.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
pub mod requests;
|
||||
pub mod responses;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct UserDto {
|
||||
pub id: Uuid,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct User {
|
||||
pub id: String,
|
||||
}
|
8
crates/como_domain/src/users/requests.rs
Normal file
8
crates/como_domain/src/users/requests.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct CreateUserDto {
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
}
|
3
crates/como_domain/src/users/responses.rs
Normal file
3
crates/como_domain/src/users/responses.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
use super::UserDto;
|
||||
|
||||
pub type UserCreatedDto = UserDto;
|
Reference in New Issue
Block a user