1+ from time_entries ._infrastructure import ActivitiesJsonDao
2+ from time_entries ._domain import ActivityService , _use_cases
3+
4+ import azure .functions as func
5+ import json
6+ import logging
7+
8+ JSON_PATH = (
9+ 'V2/time_entries/_infrastructure/_data_persistence/activities_data.json'
10+ )
11+
12+ new_activity = {
13+ 'id' : 'c61a4a49-3364-49a3-a666-0c5f2d15072b' ,
14+ 'name' : 'Activity Demo create' ,
15+ 'tenant_id' : 'cc925a5d-9644-4a4f-8d99-0bee49aadd05' ,
16+ 'description' : 'test demo create an new activity' ,
17+ 'status' : 'active' ,
18+ 'deleted' : 'b4327ba6-9f96-49ee-a9ac-3c1edf525172' ,
19+ }
20+
21+ def create_activity (req : func .HttpRequest ) -> func .HttpResponse :
22+ logging .info (
23+ 'Python HTTP trigger function processed a request to create an activity.'
24+ )
25+ #activity_id = req.route_params.get('id')
26+ status_code = 200
27+
28+ if status_code == 200 :
29+ response = _create_activity (new_activity )
30+ if response == b'Not Found' :
31+ status_code = 404
32+ else :
33+ response = b'Not Found'
34+
35+ return func .HttpResponse (
36+ body = response , status_code = status_code , mimetype = "application/json"
37+ )
38+
39+ def _create_activity (activity_data : dict ) -> str :
40+ activity_use_case = _use_cases .CreateActivityUseCase (
41+ _create_activity_service (JSON_PATH )
42+ )
43+ activity = activity_use_case .create_activity (activity_data )
44+ return json .dumps (activity .__dict__ ) if activity else b'Not Found'
45+
46+ def _create_activity_service (path : str ):
47+ activity_json = ActivitiesJsonDao (path )
48+ return ActivityService (activity_json )
0 commit comments