1+ import dataclasses
2+ import json
3+ import typing
4+
5+ import azure .functions as func
6+
7+ from ... import _domain
8+ from ... import _infrastructure
9+
10+ _JSON_PATH = (
11+ 'time_entries/_infrastructure/_data_persistence/time_entries_data.json'
12+ )
13+
14+ def create_time_entry (req : func .HttpRequest ) -> func .HttpResponse :
15+
16+ time_entry_dao = _infrastructure .TimeEntriesJsonDao (_JSON_PATH )
17+ time_entry_service = _domain .TimeEntryService (time_entry_dao )
18+ use_case = _domain ._use_cases .CreateTimeEntryUseCase (time_entry_service )
19+
20+ time_entry_data = req .get_json ()
21+
22+ time_entry_to_create = _domain .TimeEntry (
23+ id = None ,
24+ start_date = time_entry_data ["start_date" ],
25+ owner_id = time_entry_data ["owner_id" ],
26+ description = time_entry_data ["description" ],
27+ activity_id = time_entry_data ["activity_id" ],
28+ uri = time_entry_data ["uri" ],
29+ technologies = time_entry_data ["technologies" ],
30+ end_date = time_entry_data ["end_date" ],
31+ deleted = time_entry_data ["deleted" ],
32+ timezone_offset = time_entry_data ["timezone_offset" ],
33+ project_id = time_entry_data ["project_id" ]
34+ )
35+
36+ created_time_entry = use_case .create_time_entry (time_entry_to_create .__dict__ )
37+
38+ if not created_time_entry :
39+ return func .HttpResponse (
40+ body = json .dumps ({'error' : 'time_entry could not be created' }),
41+ status_code = 500 ,
42+ mimetype = "application/json"
43+ )
44+
45+ return func .HttpResponse (
46+ body = json .dumps (created_time_entry .__dict__ ),
47+ status_code = 201 ,
48+ mimetype = "application/json"
49+ )
0 commit comments