-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Bill2015/develop-resource-rename-the-file
Add feature that can rename the file from resource page
- Loading branch information
Showing
21 changed files
with
311 additions
and
38 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
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
8 changes: 8 additions & 0 deletions
8
src-tauri/src/modules/resource/application/command/rename_file/dto.rs
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,8 @@ | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct ResourceRenameFileDto { | ||
pub id: String, | ||
|
||
pub new_name: Option<String>, | ||
} |
67 changes: 67 additions & 0 deletions
67
src-tauri/src/modules/resource/application/command/rename_file/mod.rs
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,67 @@ | ||
use anyhow::Error; | ||
use async_trait::async_trait; | ||
use serde::Deserialize; | ||
|
||
use crate::command_from_dto; | ||
use crate::modules::resource::domain::{ResourceGenericError, ResourceID}; | ||
use crate::modules::resource::repository::ResourceRepository; | ||
use crate::modules::common::application::ICommandHandler; | ||
|
||
mod dto; | ||
pub use dto::*; | ||
|
||
#[derive(Deserialize)] | ||
pub struct ResourceRenameFileCommand { | ||
pub id: String, | ||
|
||
pub new_name: Option<String>, | ||
} | ||
command_from_dto!(ResourceRenameFileCommand, ResourceRenameFileDto); | ||
|
||
// ===================================== | ||
pub struct ResourceRenameFileHandler<'a> { | ||
resource_repo: &'a ResourceRepository<'a>, | ||
} | ||
|
||
impl<'a> ResourceRenameFileHandler<'a> { | ||
pub fn register(resource_repo: &'a ResourceRepository) -> Self { | ||
Self { resource_repo } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl ICommandHandler<ResourceRenameFileCommand> for ResourceRenameFileHandler<'_> { | ||
|
||
fn get_name() -> String { | ||
String::from("Create Resource Command") | ||
} | ||
|
||
type Output = ResourceID; | ||
|
||
async fn execute(&self, command: ResourceRenameFileCommand) -> Result<Self::Output, Error> { | ||
let ResourceRenameFileCommand { | ||
id, | ||
new_name, | ||
} = command; | ||
|
||
// find by id | ||
let mut resource = self.resource_repo | ||
.find_by_id(id) | ||
.await | ||
.or(Err(ResourceGenericError::DBInternalError()))? | ||
.ok_or(ResourceGenericError::IdNotFound())?; | ||
|
||
// rename the file | ||
resource.rename_file(new_name)?; | ||
|
||
// save | ||
let result = self.resource_repo | ||
.save(resource) | ||
.await; | ||
|
||
match result { | ||
Ok(value) => Ok(value.take_id()), | ||
_ => Err(ResourceGenericError::DBInternalError().into()), | ||
} | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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 @@ | ||
{ | ||
"Main": { | ||
"name": "name", | ||
"description": "description" | ||
}, | ||
"Icons": { | ||
"rename": "Rename the file by current name" | ||
} | ||
} |
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 @@ | ||
{ | ||
"Main": { | ||
"name": "名稱", | ||
"description": "描述" | ||
}, | ||
"Icons": { | ||
"rename": "使用現在的名稱重新命名此檔案" | ||
} | ||
} |
Oops, something went wrong.