Coverage for src/app/controllers/get_template_list_controller.py: 58%

12 statements  

« prev     ^ index     » next       coverage.py v7.7.0, created at 2025-04-03 00:51 +0200

1from usecases.get_template_list_useCase import GetTemplateListUseCase 

2from dto.template_dto import TemplateDTO 

3from models.template_model import TemplateModel 

4 

5class GetTemplateListController: 

6 

7 def __init__(self, get_template_list_use_case: GetTemplateListUseCase): 

8 self.get_template_list_use_case = get_template_list_use_case 

9 

10 def get_template_list(self) -> list[TemplateDTO]: 

11 """ 

12 Get all templates from the database. 

13 Returns: 

14 list[TemplateDTO]: A list of templates retrieved from the database. 

15 """ 

16 try: 

17 

18 templates_result = self.get_template_list_use_case.get_template_list() 

19 

20 return [ 

21 TemplateDTO( 

22 id=template.get_id(), 

23 question=template.get_question(), 

24 answer=template.get_answer(), 

25 author_id=template.get_author_id(), 

26 last_modified=template.get_last_modified() 

27 ) 

28 for template in templates_result 

29 ] 

30 

31 except Exception as e: 

32 raise e