1- use std:: sync:: Arc ;
21use crate :: core:: traits:: * ;
3- use crate :: infrastructure:: { repositories:: * , config:: AppConfig , UtilityService } ;
2+ use crate :: infrastructure:: { UtilityService , config:: AppConfig , repositories:: * } ;
3+ use std:: sync:: Arc ;
44
55/// Application service that provides dependency injection and orchestrates the system
66pub struct ApplicationService {
77 pub config : Arc < AppConfig > ,
88 // pub use_cases: Arc<super::UseCases>,
9-
9+
1010 // Domain services
1111 // pub transfer_service: Arc<TransferDomainService>,
1212 // pub peer_service: Arc<PeerDomainService>,
1313 // pub file_service: Arc<FileDomainService>,
14-
14+
1515 // Repositories
1616 pub file_repository : Arc < dyn FileRepository > ,
1717 pub transfer_repository : Arc < dyn TransferRepository > ,
@@ -24,7 +24,7 @@ impl ApplicationService {
2424 // Validate and prepare configuration
2525 config. validate ( ) ?;
2626 config. ensure_directories ( ) ?;
27-
27+
2828 let config = Arc :: new ( config) ;
2929
3030 // Create repositories
@@ -53,9 +53,7 @@ pub struct FileSystemService {
5353
5454impl FileSystemService {
5555 pub fn new ( config : Arc < AppConfig > ) -> Self {
56- Self {
57- _config : config,
58- }
56+ Self { _config : config }
5957 }
6058}
6159
@@ -64,7 +62,7 @@ impl FileService for FileSystemService {
6462 async fn add_file ( & self , path : & str ) -> DomainResult < crate :: core:: domain:: File > {
6563 let ( name, size) = self . get_file_metadata ( path) . await ?;
6664 let hash = self . calculate_file_hash ( path) . await ?;
67-
65+
6866 Ok ( crate :: core:: domain:: File {
6967 id : crate :: core:: domain:: FileId :: new ( ) ,
7068 name,
@@ -85,43 +83,43 @@ impl FileService for FileSystemService {
8583 async fn get_file_metadata ( & self , path : & str ) -> DomainResult < ( String , u64 ) > {
8684 let path_buf = std:: path:: Path :: new ( path) ;
8785 let metadata = tokio:: fs:: metadata ( path) . await ?;
88-
86+
8987 let name = path_buf
9088 . file_name ( )
9189 . ok_or ( "Invalid filename" ) ?
9290 . to_string_lossy ( )
9391 . to_string ( ) ;
94-
92+
9593 Ok ( ( name, metadata. len ( ) ) )
9694 }
9795
9896 async fn read_file_chunk ( & self , path : & str , offset : u64 , size : usize ) -> DomainResult < Vec < u8 > > {
9997 use tokio:: io:: { AsyncReadExt , AsyncSeekExt } ;
100-
98+
10199 let mut file = tokio:: fs:: File :: open ( path) . await ?;
102100 file. seek ( std:: io:: SeekFrom :: Start ( offset) ) . await ?;
103-
101+
104102 let mut buffer = vec ! [ 0u8 ; size] ;
105103 let bytes_read = file. read ( & mut buffer) . await ?;
106104 buffer. truncate ( bytes_read) ;
107-
105+
108106 Ok ( buffer)
109107 }
110108
111109 async fn write_file_chunk ( & self , path : & str , offset : u64 , data : & [ u8 ] ) -> DomainResult < ( ) > {
112- use tokio:: io:: { AsyncWriteExt , AsyncSeekExt } ;
113-
110+ use tokio:: io:: { AsyncSeekExt , AsyncWriteExt } ;
111+
114112 let mut file = tokio:: fs:: OpenOptions :: new ( )
115113 . create ( true )
116114 . write ( true )
117115 . truncate ( false )
118116 . open ( path)
119117 . await ?;
120-
118+
121119 file. seek ( std:: io:: SeekFrom :: Start ( offset) ) . await ?;
122120 file. write_all ( data) . await ?;
123121 file. flush ( ) . await ?;
124-
122+
125123 Ok ( ( ) )
126124 }
127- }
125+ }
0 commit comments