-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_entries.py
More file actions
58 lines (46 loc) · 1.52 KB
/
validate_entries.py
File metadata and controls
58 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from http import HTTPStatus
from azure.cosmos.exceptions import CosmosResourceNotFoundError
from time_tracker_api.projects import projects_model
from time_tracker_api.activities import activities_model
def are_related_entry_entities_valid(project_id: str, activity_id: str):
if not project_id:
return {
"is_valid": False,
"status_code": HTTPStatus.BAD_REQUEST,
"message": "Project id can not be empty",
}
if not activity_id:
return {
"is_valid": False,
"status_code": HTTPStatus.BAD_REQUEST,
"message": "Activity id can not be empty",
}
exists_project = exists_related_entity(
project_id, projects_model.create_dao()
)
if not exists_project:
return {
"is_valid": False,
"status_code": HTTPStatus.BAD_REQUEST,
"message": "Related Project does not exists",
}
exists_activity = exists_related_entity(
activity_id, activities_model.create_dao()
)
if not exists_activity:
return {
"is_valid": False,
"status_code": HTTPStatus.BAD_REQUEST,
"message": "Related Activity does not exists",
}
return {
"is_valid": True,
"status_code": HTTPStatus.OK,
"message": "Related entry entities valid",
}
def exists_related_entity(related_id: str, dao):
try:
dao.get(related_id)
return True
except CosmosResourceNotFoundError:
return False