Can upload files
This commit is contained in:
		
							
								
								
									
										47
									
								
								moneymgr_backend/src/models/files.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								moneymgr_backend/src/models/files.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
use crate::models::users::UserID;
 | 
			
		||||
use crate::schema::*;
 | 
			
		||||
use diesel::prelude::*;
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq, Eq)]
 | 
			
		||||
pub struct FileID(pub i32);
 | 
			
		||||
 | 
			
		||||
#[derive(Queryable, Debug, serde::Serialize)]
 | 
			
		||||
pub struct File {
 | 
			
		||||
    id: i32,
 | 
			
		||||
    pub time_create: i64,
 | 
			
		||||
    pub mime_type: String,
 | 
			
		||||
    pub sha512: String,
 | 
			
		||||
    pub file_size: i32,
 | 
			
		||||
    pub file_name: String,
 | 
			
		||||
    user_id: i32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl File {
 | 
			
		||||
    pub fn id(&self) -> FileID {
 | 
			
		||||
        FileID(self.id)
 | 
			
		||||
    }
 | 
			
		||||
    pub fn file_path(&self) -> String {
 | 
			
		||||
        format!("blob/{}/{}", self.user_id, self.sha512)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn user_id(&self) -> UserID {
 | 
			
		||||
        UserID(self.id)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Insertable)]
 | 
			
		||||
#[diesel(table_name = files)]
 | 
			
		||||
pub struct NewFile<'a> {
 | 
			
		||||
    pub time_create: i64,
 | 
			
		||||
    pub mime_type: &'a str,
 | 
			
		||||
    pub sha512: &'a str,
 | 
			
		||||
    pub file_size: i32,
 | 
			
		||||
    pub file_name: &'a str,
 | 
			
		||||
    pub user_id: i32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl NewFile<'_> {
 | 
			
		||||
    pub fn file_path(&self) -> String {
 | 
			
		||||
        format!("blob/{}/{}", self.user_id, self.sha512)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
pub mod accounts;
 | 
			
		||||
pub mod files;
 | 
			
		||||
pub mod tokens;
 | 
			
		||||
pub mod users;
 | 
			
		||||
 
 | 
			
		||||
@@ -32,7 +32,7 @@ pub struct Token {
 | 
			
		||||
    pub right_account: bool,
 | 
			
		||||
    pub right_movement: bool,
 | 
			
		||||
    pub right_inbox: bool,
 | 
			
		||||
    pub right_attachment: bool,
 | 
			
		||||
    pub right_file: bool,
 | 
			
		||||
    pub right_auth: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -76,6 +76,6 @@ pub struct NewToken<'a> {
 | 
			
		||||
    pub right_account: bool,
 | 
			
		||||
    pub right_movement: bool,
 | 
			
		||||
    pub right_inbox: bool,
 | 
			
		||||
    pub right_attachment: bool,
 | 
			
		||||
    pub right_file: bool,
 | 
			
		||||
    pub right_auth: bool,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user