linted the code.

This commit is contained in:
didier amyot committed 2023-02-25 22:10:18 -05:00
1 parent 0c171171c2
commit f4170610b0
12 files changed
+84 -57

No files matched your search

+21 -9
View File
@@ -7,18 +7,24 @@ use crate::db::users::{list_users, User};
use crate::util::CustomResult;
#[derive(Serialize, Debug)]
pub struct Page<T> where T: Serialize {
pub struct Page<T>
where
T: Serialize,
{
total_number_of_page: usize,
current_page_number: usize,
content: Vec<T>,
}
impl<T> Page<T> where T: Serialize{
pub fn all_of(data: Vec<T>) -> Page<T>{
Page{
impl<T> Page<T>
where
T: Serialize,
{
pub fn all_of(data: Vec<T>) -> Page<T> {
Page {
total_number_of_page: 0,
current_page_number: 10,
content: data
content: data,
}
}
}
@@ -26,12 +32,15 @@ impl<T> Page<T> where T: Serialize{
#[derive(Deserialize, Serialize, Debug)]
pub struct UserDTO {
name: String,
id: String, // todo: should be of type UserId
id: String, // todo: should be of type UserId
}
impl UserDTO {
fn from_entity(user: &User) -> UserDTO {
return UserDTO { name: user.get_name(), id: user.id().to_string() }
return UserDTO {
name: user.get_name(),
id: user.id().to_string(),
};
}
}
@@ -45,8 +54,11 @@ impl UserService<'_> {
}
pub fn list_users(self) -> CustomResult<Page<UserDTO>> {
let users = list_users(self.conn)?.iter().map(UserDTO::from_entity).collect();
let users = list_users(self.conn)?
.iter()
.map(UserDTO::from_entity)
.collect();
let ret = Page::all_of(users);
return Ok(ret)
return Ok(ret);
}
}