Skip to content

Commit

Permalink
Merge pull request #1 from JKearnsl/jk-0411
Browse files Browse the repository at this point in the history
update 0.1.1
  • Loading branch information
JKearnsl authored Jul 27, 2024
2 parents a5c50a4 + c03380c commit 0e91bc2
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 414 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tobox"
version = "0.1.0"
version = "0.1.1"
authors = ["JKearnsl <[email protected]>"]
edition = "2021"

Expand Down Expand Up @@ -42,4 +42,5 @@ sqlx = { version = "^0.7", features = [
"sqlite",
"sqlx-sqlite",
"chrono"
] }
] }
regex = "1.10.5"
4 changes: 1 addition & 3 deletions src/tobox/domain/models/box.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use uuid::Uuid;


pub type BoxId = Uuid;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Box {
pub id: BoxId,
pub name: String,
pub created_at: DateTime<Utc>
}
}
3 changes: 2 additions & 1 deletion src/tobox/domain/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod r#box;
pub mod object;
pub mod user;
pub mod permission;
pub mod role;
pub mod role;
pub mod token_pair;
9 changes: 7 additions & 2 deletions src/tobox/domain/models/object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use uuid::Uuid;

pub type ObjectId = Uuid;
Expand All @@ -9,6 +9,11 @@ pub type ObjectId = Uuid;
pub struct Object {
pub id: ObjectId,
pub name: String,
pub path: String,
pub hash: String,
pub size: u64,
pub content_type: String,
pub metadata: HashMap<String, String>,
pub created_at: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
pub updated_at: Option<DateTime<Utc>>
}
27 changes: 27 additions & 0 deletions src/tobox/domain/models/permission.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use strum_macros::{Display, EnumIter};
use crate::domain::models::r#box::BoxId;

pub type PermissionTextId = String;

#[derive(Display, EnumIter)]
pub enum Permission {
Expand All @@ -19,4 +22,28 @@ pub enum Permission {

GetPermission,
LinkRolePermission,

GetBox,
CreateBox,
UpdateBox,
DeleteBox,

#[strum(serialize = "UpdateSpecificBox({0})")]
UpdateSpecificBox(BoxId),
#[strum(serialize = "DeleteSpecificBox({0})")]
DeleteSpecificBox(BoxId),

GetObject,
CreateObject,
UpdateObject,
DeleteObject,

#[strum(serialize = "GetSpecificObject({0})")]
GetSpecificObject(BoxId),
#[strum(serialize = "CreateSpecificObject({0})")]
CreateSpecificObject(BoxId),
#[strum(serialize = "UpdateSpecificObject({0})")]
UpdateSpecificObject(BoxId),
#[strum(serialize = "DeleteSpecificObject({0})")]
DeleteSpecificObject(BoxId)
}
2 changes: 1 addition & 1 deletion src/tobox/domain/models/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub struct Role {
pub description: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
}
}
10 changes: 10 additions & 0 deletions src/tobox/domain/models/token_pair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::{Deserialize, Serialize};

use crate::domain::models::user::UserId;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TokenPair {
pub public: String,
pub enc_private: String,
pub user_id: UserId
}
20 changes: 2 additions & 18 deletions src/tobox/domain/models/user.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, EnumString, Display)]
#[serde(rename_all = "lowercase")]
#[strum(serialize_all = "lowercase")]
pub enum UserState {
Active,
Inactive,
Banned,
Deleted,
}

pub type UserId = Uuid;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct User {
pub id: UserId,
pub username: String,
pub email: String,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub state: UserState,
pub hashed_password: String,
pub created_at: DateTime<Utc>,
pub updated_at: Option<DateTime<Utc>>,
}
pub created_at: DateTime<Utc>
}
27 changes: 0 additions & 27 deletions src/tobox/domain/services/access_log.rs

This file was deleted.

24 changes: 24 additions & 0 deletions src/tobox/domain/services/box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use chrono::Utc;
use uuid::Uuid;

use crate::domain::models::r#box::Box;

pub struct BoxService { }

impl BoxService {

pub fn create_box(&self, name: String) -> Box {
Box {
id: Uuid::new_v4(),
name,
created_at: Utc::now(),
}
}

pub fn update_box(&self, r#box: Box, new_name: String) -> Box {
Box {
name: new_name,
..r#box
}
}
}
38 changes: 0 additions & 38 deletions src/tobox/domain/services/external.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/tobox/domain/services/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod access;
pub mod user;
pub mod validator;
pub mod session;
pub mod token_pair;
pub mod role;
pub mod access_log;
pub mod permission;
pub mod external;
pub mod r#box;
pub mod object;
48 changes: 48 additions & 0 deletions src/tobox/domain/services/object.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::collections::HashMap;
use chrono::Utc;
use uuid::Uuid;

use crate::domain::models::object::Object;

pub struct ObjectService { }

impl ObjectService {

pub fn create_box(
&self,
name: String,
path: String,
hash: String,
size: u64,
content_type: String,
metadata: HashMap<String, String>,
) -> Object {
Object {
id: Uuid::new_v4(),
name,
path,
hash,
size,
content_type,
metadata,
created_at: Utc::now(),
updated_at: None,
}
}

pub fn update_box(
&self,
object: Object,
new_name: String,
new_path: String,
new_metadata: HashMap<String, String>,
) -> Object {
Object {
name: new_name,
path: new_path,
metadata: new_metadata,
updated_at: Some(Utc::now()),
..object
}
}
}
41 changes: 0 additions & 41 deletions src/tobox/domain/services/permission.rs

This file was deleted.

Loading

0 comments on commit 0e91bc2

Please sign in to comment.