-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use sqlx::FromRow; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)] | ||
pub struct AccountLoginDTO { | ||
pub username: Option<String>, // 用户昵称(别名 姓名) | ||
|
||
pub password: Option<String>, // 职位 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod account_login_dto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod user_info_vo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
use serde::{Serialize, Deserialize}; | ||
use serde::ser::Serializer; | ||
use serde::de::{Deserializer, Error}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct UserInfoVO { | ||
#[serde(serialize_with = "serialize_long")] | ||
pub id: Option<i64>, // 以字符串形式序列化的 Long 类型 | ||
|
||
pub name: Option<String>, // 用户昵称(别名 姓名) | ||
|
||
pub position: Option<String>, // 职位 | ||
|
||
pub email: Option<String>, // 邮箱 | ||
|
||
pub phone_number: Option<String>, // 电话号 | ||
|
||
pub description: Option<String>, // 用户个人简介 | ||
|
||
pub user_name: Option<String>, // 用户名(登陆的账户) | ||
|
||
pub avatar: Option<String>, // 用户头像地址 | ||
|
||
pub system_language: Option<String>, // 用户语言 | ||
|
||
pub token: Option<String>, // 用户token | ||
|
||
pub expire: Option<i64>, // 过期时间(Unix 时间戳) | ||
} | ||
|
||
fn serialize_long<S>(x: &Option<i64>, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
// 以字符串形式序列化 Long 类型 | ||
match *x { | ||
Some(value) => serializer.serialize_str(&value.to_string()), | ||
None => serializer.serialize_none(), | ||
} | ||
} | ||
|
||
impl UserInfoVO { | ||
// 你可以手动实现一个 builder 模式,或者使用一些第三方库来简化这个过程(比如 `derive_builder`)。 | ||
pub fn builder() -> UserInfoVOBuilder { | ||
UserInfoVOBuilder::default() | ||
} | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct UserInfoVOBuilder { | ||
id: Option<i64>, | ||
name: Option<String>, | ||
position: Option<String>, | ||
email: Option<String>, | ||
phone_number: Option<String>, | ||
description: Option<String>, | ||
user_name: Option<String>, | ||
avatar: Option<String>, | ||
system_language: Option<String>, | ||
token: Option<String>, | ||
expire: Option<i64>, | ||
} | ||
|
||
impl UserInfoVOBuilder { | ||
pub fn id(mut self, id: i64) -> Self { | ||
self.id = Some(id); | ||
self | ||
} | ||
|
||
pub fn name(mut self, name: String) -> Self { | ||
self.name = Some(name); | ||
self | ||
} | ||
|
||
pub fn position(mut self, position: String) -> Self { | ||
self.position = Some(position); | ||
self | ||
} | ||
|
||
pub fn email(mut self, email: String) -> Self { | ||
self.email = Some(email); | ||
self | ||
} | ||
|
||
pub fn phone_number(mut self, phone_number: String) -> Self { | ||
self.phone_number = Some(phone_number); | ||
self | ||
} | ||
|
||
pub fn description(mut self, description: String) -> Self { | ||
self.description = Some(description); | ||
self | ||
} | ||
|
||
pub fn user_name(mut self, user_name: String) -> Self { | ||
self.user_name = Some(user_name); | ||
self | ||
} | ||
|
||
pub fn avatar(mut self, avatar: String) -> Self { | ||
self.avatar = Some(avatar); | ||
self | ||
} | ||
|
||
pub fn system_language(mut self, system_language: String) -> Self { | ||
self.system_language = Some(system_language); | ||
self | ||
} | ||
|
||
pub fn token(mut self, token: String) -> Self { | ||
self.token = Some(token); | ||
self | ||
} | ||
|
||
pub fn expire(mut self, expire: i64) -> Self { | ||
self.expire = Some(expire); | ||
self | ||
} | ||
|
||
pub fn build(self) -> UserInfoVO { | ||
UserInfoVO { | ||
id: self.id, | ||
name: self.name, | ||
position: self.position, | ||
email: self.email, | ||
phone_number: self.phone_number, | ||
description: self.description, | ||
user_name: self.user_name, | ||
avatar: self.avatar, | ||
system_language: self.system_language, | ||
token: self.token, | ||
expire: self.expire, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod user_service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use domain::entity::user; | ||
use domain::vo::user::user_info_vo::UserInfoVO; | ||
use domain::dto::user::account_login_dto::AccountLoginDTO; | ||
use utils::response::Response; | ||
|
||
pub struct UserService; | ||
|
||
impl UserService { | ||
pub fn new() -> Self { | ||
UserService | ||
} | ||
|
||
// pub fn user_login(&self, accountLoginDto: AccountLoginDTO) -> Result<Response<UserInfoVO>, Box<dyn std::error::Error>> { | ||
// | ||
// } | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct Response<T> { | ||
pub msg: String, | ||
pub code: String, | ||
pub data: Option<T>, | ||
} | ||
|
||
// 枚举类来定义不同的代码和消息 | ||
pub enum BaseCodeEnum { | ||
SUCCESS, | ||
ERROR, | ||
} | ||
|
||
impl BaseCodeEnum { | ||
pub fn get_code(&self) -> &str { | ||
match self { | ||
BaseCodeEnum::SUCCESS => "200", | ||
BaseCodeEnum::ERROR => "500", | ||
} | ||
} | ||
|
||
pub fn get_msg(&self) -> &str { | ||
match self { | ||
BaseCodeEnum::SUCCESS => "Success", | ||
BaseCodeEnum::ERROR => "Error", | ||
} | ||
} | ||
} | ||
|
||
impl<T> Response<T> { | ||
pub fn success(data: T) -> Self { | ||
Response { | ||
msg: BaseCodeEnum::SUCCESS.get_msg().to_string(), | ||
code: BaseCodeEnum::SUCCESS.get_code().to_string(), | ||
data: Some(data), | ||
} | ||
} | ||
|
||
pub fn fail(msg: String) -> Self { | ||
Response { | ||
msg, | ||
code: BaseCodeEnum::ERROR.get_code().to_string(), | ||
data: None, | ||
} | ||
} | ||
} |