11import abc
22from dataclasses import dataclass , field
33from typing import List , Callable
4+ from flask import jsonify
45
56from azure .cosmos import PartitionKey
67from flask_restplus ._http import HTTPStatus
1819from commons .data_access_layer .database import EventContext
1920
2021from time_tracker_api .time_entries .custom_modules import worked_time
22+ from time_tracker_api .time_entries .custom_modules .utils import (
23+ add_project_name_to_time_entries ,
24+ )
25+ from time_tracker_api .projects import projects_model
2126from time_tracker_api .database import CRUDDao , APICosmosDBDao
2227from time_tracker_api .security import current_user_id
2328
@@ -106,6 +111,24 @@ def create_sql_date_range_filter(date_range: dict) -> str:
106111 else :
107112 return ''
108113
114+ def find (
115+ self ,
116+ id : str ,
117+ event_context : EventContext ,
118+ peeker : 'function' = None ,
119+ visible_only = True ,
120+ mapper : Callable = None ,
121+ ):
122+ time_entry = CosmosDBRepository .find (
123+ self , id , event_context , peeker , visible_only , mapper ,
124+ )
125+
126+ project_dao = projects_model .create_dao ()
127+ project = project_dao .get (time_entry .project_id )
128+ setattr (time_entry , 'project_name' , project .name )
129+
130+ return time_entry
131+
109132 def find_all (
110133 self ,
111134 event_context : EventContext ,
@@ -119,14 +142,18 @@ def find_all(
119142
120143 custom_params = self .generate_params (date_range )
121144
122- return CosmosDBRepository .find_all (
145+ time_entries = CosmosDBRepository .find_all (
123146 self ,
124147 event_context = event_context ,
125148 conditions = conditions ,
126149 custom_sql_conditions = custom_sql_conditions ,
127150 custom_params = custom_params ,
128151 )
129152
153+ projects = project_dao .get_all ()
154+ add_project_name_to_time_entries (time_entries , projects )
155+ return time_entries
156+
130157 def on_create (self , new_item_data : dict , event_context : EventContext ):
131158 CosmosDBRepository .on_create (self , new_item_data , event_context )
132159
0 commit comments