1
1
import abc
2
2
from dataclasses import dataclass , field
3
3
from typing import List , Callable
4
+ from flask import jsonify
4
5
5
6
from azure .cosmos import PartitionKey
6
7
from flask_restplus ._http import HTTPStatus
18
19
from commons .data_access_layer .database import EventContext
19
20
20
21
from 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
21
26
from time_tracker_api .database import CRUDDao , APICosmosDBDao
22
27
from time_tracker_api .security import current_user_id
23
28
@@ -106,6 +111,24 @@ def create_sql_date_range_filter(date_range: dict) -> str:
106
111
else :
107
112
return ''
108
113
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
+
109
132
def find_all (
110
133
self ,
111
134
event_context : EventContext ,
@@ -119,14 +142,18 @@ def find_all(
119
142
120
143
custom_params = self .generate_params (date_range )
121
144
122
- return CosmosDBRepository .find_all (
145
+ time_entries = CosmosDBRepository .find_all (
123
146
self ,
124
147
event_context = event_context ,
125
148
conditions = conditions ,
126
149
custom_sql_conditions = custom_sql_conditions ,
127
150
custom_params = custom_params ,
128
151
)
129
152
153
+ projects = project_dao .get_all ()
154
+ add_project_name_to_time_entries (time_entries , projects )
155
+ return time_entries
156
+
130
157
def on_create (self , new_item_data : dict , event_context : EventContext ):
131
158
CosmosDBRepository .on_create (self , new_item_data , event_context )
132
159
0 commit comments