Skip to content

Commit

Permalink
feat: Add user domain model
Browse files Browse the repository at this point in the history
  • Loading branch information
johns10 committed Sep 8, 2024
1 parent 0d3fd9c commit 36fdea4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions domain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod db;
pub mod repository;
pub mod user;
1 change: 1 addition & 0 deletions domain/src/user/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod model;
45 changes: 45 additions & 0 deletions domain/src/user/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
pub id: Uuid,
pub username: String,
pub email: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CreateUserDto {
pub username: String,
pub email: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateUserDto {
pub username: Option<String>,
pub email: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct UserDto {
pub id: Uuid,
pub username: String,
pub email: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}

impl From<User> for UserDto {
fn from(user: User) -> Self {
Self {
id: user.id,
username: user.username,
email: user.email,
created_at: user.created_at,
updated_at: user.updated_at,
}
}
}

0 comments on commit 36fdea4

Please sign in to comment.