Coverage for src/app/services/add_file_service.py: 100%
24 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-03 00:42 +0200
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-03 00:42 +0200
1from services.split_file_service import SplitFileService
2from services.add_chunks_service import AddChunksService
3from models.file_model import FileModel
4from models.file_chunk_model import FileChunkModel
6class AddFileService:
7 """
8 Service class to manage file addition.
9 """
10 def __init__(self, split_file_service: SplitFileService, add_chunks_service: AddChunksService):
11 self.split_file_service = split_file_service
12 self.add_chunks_service = add_chunks_service
14 def load_file(self, file: FileModel):
15 """
16 Load a file and process its chunks.
17 """
18 try:
19 chunks = self.split_file(file)
20 self.load_chunks(chunks)
21 except Exception as e:
22 raise e
24 def split_file(self, file: FileModel) -> list[FileChunkModel]:
25 """
26 Split the file into chunks.
27 """
28 try:
29 return self.split_file_service.split_file(file)
30 except Exception as e:
31 raise e
33 def load_chunks(self, chunks: list[FileChunkModel]):
34 """
35 Load the file chunks.
36 """
37 try:
38 self.add_chunks_service.load_chunks(chunks)
39 except Exception as e:
40 raise e