Skip to content

Commit

Permalink
Merge pull request #3 from JKearnsl/jk-1320
Browse files Browse the repository at this point in the history
update 0.1.3
  • Loading branch information
JKearnsl authored Aug 3, 2024
2 parents 2da1253 + ca396d9 commit 7ee0926
Show file tree
Hide file tree
Showing 58 changed files with 400 additions and 735 deletions.
13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tobox"
version = "0.1.2"
version = "0.1.3"
authors = ["JKearnsl <[email protected]>"]
edition = "2021"

Expand All @@ -17,22 +17,20 @@ tokio = { version = "^1.39", features = [
] }
tokio-stream = "^0.1"
actix-web = { version = "^4.8", features = ["rustls-0_23"] }
actix-files = "^0.6"
actix-multipart = "^0.7"
rustls = "^0.23"
rustls-pemfile = "^2.1"
regex = "^1.10"
log = "^0.4"
env_logger = "^0.11"

# Data
serde = { version = "^1.0", features = ["derive"] }
serde_yaml = "^0.9.34-deprecated"
derive_more = "^0.99"
async-trait = "^0.1"
uuid = { version = "^1.10", features = [
"v4",
"serde",
"fast-rng",
"macro-diagnostics"
] }
nanoid = "^0.4"
chrono = "^0.4"
strum = "^0.26"
strum_macros = "^0.26"
Expand All @@ -45,4 +43,3 @@ sqlx = { version = "^0.8", features = [
"sqlx-sqlite",
"chrono"
] }
regex = "^1.10"
42 changes: 4 additions & 38 deletions src/tobox/application/box/create.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::collections::HashMap;

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde::Serialize;

use crate::application::common::box_gateway::BoxGateway;
use crate::application::common::exceptions::{ApplicationError, ErrorContent};
Expand All @@ -13,15 +11,9 @@ use crate::domain::services::access::AccessService;
use crate::domain::services::r#box::BoxService;
use crate::domain::services::validator::ValidatorService;

#[derive(Debug, Deserialize)]
pub struct CreateBoxDTO {
pub name: String
}

#[derive(Debug, Serialize)]
pub struct CreateBoxResultDTO{
id: BoxId,
name: String,
created_at: DateTime<Utc>
}

Expand All @@ -33,8 +25,8 @@ pub struct CreateBox<'a> {
pub id_provider: Box<dyn IdProvider>,
}

impl Interactor<CreateBoxDTO, CreateBoxResultDTO> for CreateBox<'_> {
async fn execute(&self, data: CreateBoxDTO) -> Result<CreateBoxResultDTO, ApplicationError> {
impl Interactor<(), CreateBoxResultDTO> for CreateBox<'_> {
async fn execute(&self, _data: ()) -> Result<CreateBoxResultDTO, ApplicationError> {

match self.access_service.ensure_can_create_box(
self.id_provider.is_auth(),
Expand All @@ -54,39 +46,13 @@ impl Interactor<CreateBoxDTO, CreateBoxResultDTO> for CreateBox<'_> {
)
}
};

let mut validator_err_map: HashMap<String, String> = HashMap::new();
self.validator.validate_username(&data.name).unwrap_or_else(|e| {
validator_err_map.insert("name".to_string(), e.to_string());
});

if !validator_err_map.is_empty() {
return Err(
ApplicationError::InvalidData(
ErrorContent::Map(validator_err_map)
)
)
}

match self.box_gateway.get_box_by_name_not_sensitive(&data.name).await {
Some(_) => {
validator_err_map.insert("name".to_string(), "Name is already taken".to_string());
return Err(
ApplicationError::InvalidData(
ErrorContent::Map(validator_err_map)
)
)
},
None => ()
}

let r#box = self.box_service.create_box(data.name);
let r#box = self.box_service.create_box();

self.box_gateway.save_box(&r#box).await;

Ok(CreateBoxResultDTO {
id: r#box.id,
name: r#box.name,
created_at: r#box.created_at
})
}
Expand Down
2 changes: 0 additions & 2 deletions src/tobox/application/box/get_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct GetBoxListDTO {
#[derive(Debug, Serialize)]
pub struct BoxItem {
pub id: BoxId,
pub name: String,
pub created_at: DateTime<Utc>,
}

Expand Down Expand Up @@ -94,7 +93,6 @@ impl Interactor<GetBoxListDTO, GetBoxListResultDTO> for GetBoxList<'_> {

Ok(boxes.into_iter().map(|b| BoxItem {
id: b.id,
name: b.name,
created_at: b.created_at,
}).collect())
}
Expand Down
17 changes: 0 additions & 17 deletions src/tobox/application/common/access_log_gateway.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/tobox/application/common/box_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use crate::domain::models::r#box::{Box as BoxDomain, BoxId};

#[async_trait]
pub trait BoxReader {
async fn get_box_by_id(&self, box_id: &BoxId) -> Option<BoxDomain>;
async fn get_box(&self, box_id: &BoxId) -> Option<BoxDomain>;
async fn get_boxes(&self) -> Vec<BoxDomain>;
async fn get_boxes_range(&self, limit: &u64, offset: &u64) -> Vec<BoxDomain>;
async fn get_box_by_name_not_sensitive(&self, name: &String) -> Option<BoxDomain>;
}

#[async_trait]
Expand Down
11 changes: 7 additions & 4 deletions src/tobox/application/common/file_storage_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use async_trait::async_trait;
use crate::domain::models::file_info::FileInfo;
use crate::domain::models::file_stream::FileStream;

#[async_trait]
Expand All @@ -23,13 +24,15 @@ pub trait FileStorageWriter {
///
/// Content-type, filesize and hash are calculated during file upload, it justifies the
/// existence of this function
async fn save_file<T: Into<String>>(
async fn save_file<F: Into<String>, CT: Into<String>>(
&self,
filename: &T,
content_type: Option<&T>,
filename: &F,
content_type: Option<&CT>,
size_range: Option<(u64, u64)>,
bytes: &dyn FileStream
) -> String;
) -> FileInfo;

async fn rename_file<T: Into<String>, U: Into<String>>(&self, filename: &T, new_filename: &U);
}

#[async_trait]
Expand Down
4 changes: 2 additions & 2 deletions src/tobox/application/common/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use async_trait::async_trait;
#[async_trait]
pub trait Hasher: Send + Sync {
async fn hash<T: Into<String>>(&self, value: T) -> String;
async fn verify<T: Into<String>>(&self, value: T, hash: T) -> bool;
}
async fn verify<T: Into<String>, U: Into<String>>(&self, value: T, hash: U) -> bool;
}
3 changes: 1 addition & 2 deletions src/tobox/application/common/object_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use crate::domain::models::object::{Object as ObjectDomain, ObjectId};

#[async_trait]
pub trait ObjectReader {
async fn get_object_by_id(&self, object_id: &ObjectId) -> Option<ObjectDomain>;
async fn get_object(&self, object_id: &ObjectId) -> Option<ObjectDomain>;
async fn get_objects(&self) -> Vec<ObjectDomain>;
async fn get_objects_range(&self, limit: &u64, offset: &u64) -> Vec<ObjectDomain>;
async fn get_object_by_name_and_path(&self, name: &String, path: &String) -> Option<ObjectDomain>;
}

#[async_trait]
Expand Down
12 changes: 5 additions & 7 deletions src/tobox/application/common/permission_gateway.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use async_trait::async_trait;

use crate::domain::models::permission::{Permission as PermissionDomain, PermissionId, PermissionTextId};
use crate::domain::models::permission::{Permission as PermissionDomain, PermissionId, PermissionTag};
use crate::domain::models::role::RoleId;
use crate::domain::models::service::ServiceId;
use crate::domain::models::user::UserId;

#[async_trait]
pub trait PermissionReader {
async fn get_permission_by_id(&self, permission_id: &PermissionId) -> Option<PermissionDomain>;
async fn get_permissions_by_service_id(&self, service_id: &ServiceId) -> Vec<PermissionDomain>;
async fn get_permissions_by_ids(&self, permission_ids: &Vec<PermissionId>) -> Option<Vec<PermissionDomain>>;
async fn get_permissions_by_text_ids(&self, permission_text_ids: &Vec<PermissionTextId>) -> Option<Vec<PermissionDomain>>;
async fn get_permissions_list(&self, limit: &u64, offset: &u64) -> Vec<PermissionDomain>;
async fn get_permission(&self, permission_id: &PermissionId) -> Option<PermissionDomain>;
async fn get_permissions(&self, permission_ids: &Vec<PermissionId>) -> Option<Vec<PermissionDomain>>;
async fn get_permissions_by_tags(&self, permission_tags: &Vec<PermissionTag>) -> Option<Vec<PermissionDomain>>;
async fn get_permissions_range(&self, limit: &u64, offset: &u64) -> Vec<PermissionDomain>;
async fn get_role_permissions(&self, role_id: &RoleId) -> Vec<PermissionDomain>;
async fn get_user_permissions(&self, user_id: &UserId) -> Vec<PermissionDomain>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tobox/application/common/role_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::domain::models::user::UserId;
#[async_trait]
pub trait RoleReader {
async fn get_role(&self, role_id: &RoleId) -> Option<RoleDomain>;
async fn get_roles_by_ids(&self, role_ids: &Vec<RoleId>) -> Option<Vec<RoleDomain>>;
async fn get_roles(&self, role_ids: &Vec<RoleId>) -> Option<Vec<RoleDomain>>;
async fn get_roles_range(
&self,
limit: &u64,
Expand Down
23 changes: 0 additions & 23 deletions src/tobox/application/common/service_gateway.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/tobox/application/common/user_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::domain::models::user::{User as UserDomain, UserId};

#[async_trait]
pub trait UserReader {
async fn get_user_by_id(&self, user_id: &UserId) -> Option<UserDomain>;
async fn get_users_by_ids(&self, user_ids: &Vec<UserId>) -> Option<Vec<UserDomain>>;
async fn get_users_list(&self, limit: &u64, offset: &u64) -> Vec<UserDomain>;
async fn get_user(&self, user_id: &UserId) -> Option<UserDomain>;
async fn get_users(&self, user_ids: &Vec<UserId>) -> Option<Vec<UserDomain>>;
async fn get_users_range(&self, limit: &u64, offset: &u64) -> Vec<UserDomain>;
async fn get_user_by_username_not_sensitive(&self, username: &String) -> Option<UserDomain>;
}

Expand Down
Loading

0 comments on commit 7ee0926

Please sign in to comment.