Skip to content

Commit 3c2e9da

Browse files
author
EliuX
committed
fix: Close #85 #86 Ignore deleted objects and tweak ns constraints
1 parent a844168 commit 3c2e9da

File tree

10 files changed

+69
-100
lines changed

10 files changed

+69
-100
lines changed

time_tracker_api/activities/activities_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ActivityDao(CRUDDao):
1515
'partition_key': PartitionKey(path='/tenant_id'),
1616
'unique_key_policy': {
1717
'uniqueKeys': [
18-
{'paths': ['/name']},
18+
{'paths': ['/name', '/deleted']},
1919
]
2020
}
2121
}

time_tracker_api/activities/activities_namespace.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,13 @@
2020
),
2121
'description': fields.String(
2222
title='Description',
23+
required=False,
2324
description='Comments about the activity',
2425
example=faker.paragraph(),
2526
)
2627
})
2728

28-
activity_response_fields = {
29-
'id': fields.String(
30-
readOnly=True,
31-
required=True,
32-
title='Identifier',
33-
description='The unique identifier',
34-
example=faker.uuid4(),
35-
),
36-
'tenant_id': fields.String(
37-
required=True,
38-
title='Identifier of Tenant',
39-
description='Tenant this activity belongs to',
40-
example=faker.uuid4(),
41-
),
42-
}
29+
activity_response_fields = {}
4330
activity_response_fields.update(common_fields)
4431

4532
activity = ns.inherit(

time_tracker_api/api.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,33 @@
1515
description="API for the TimeTracker project"
1616
)
1717

18+
# For matching UUIDs
19+
UUID_REGEX = '[0-9a-f]{8}\-[0-9a-f]{4}\-4[0-9a-f]{3}\-[89ab][0-9a-f]{3}\-[0-9a-f]{12}'
20+
1821
# Common models structure
1922
common_fields = {
23+
'id': fields.String(
24+
title='Identifier',
25+
readOnly=True,
26+
required=True,
27+
description='The unique identifier',
28+
pattern=UUID_REGEX,
29+
example=faker.uuid4(),
30+
),
31+
'tenant_id': fields.String(
32+
title='Identifier of Tenant',
33+
readOnly=True,
34+
required=True,
35+
description='Tenant it belongs to',
36+
# pattern=UUID_REGEX, This must be confirmed
37+
example=faker.uuid4(),
38+
),
2039
'deleted': fields.String(
2140
readOnly=True,
2241
required=True,
2342
title='Last event Identifier',
2443
description='Last event over this resource',
44+
pattern=UUID_REGEX,
2545
),
2646
}
2747

time_tracker_api/customers/customers_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CustomerDao(CRUDDao):
1515
'partition_key': PartitionKey(path='/tenant_id'),
1616
'unique_key_policy': {
1717
'uniqueKeys': [
18-
{'paths': ['/name']},
18+
{'paths': ['/name', '/deleted']},
1919
]
2020
}
2121
}

time_tracker_api/customers/customers_namespace.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,22 @@
1212
# Customer Model
1313
customer_input = ns.model('CustomerInput', {
1414
'name': fields.String(
15-
required=True,
1615
title='Name',
16+
required=True,
1717
max_length=50,
1818
description='Name of the customer',
1919
example=faker.company(),
2020
),
2121
'description': fields.String(
2222
title='Description',
23+
required=False,
2324
max_length=250,
2425
description='Description about the customer',
2526
example=faker.paragraph(),
2627
),
2728
})
2829

29-
customer_response_fields = {
30-
'id': fields.String(
31-
readOnly=True,
32-
required=True,
33-
title='Identifier',
34-
description='The unique identifier',
35-
example=faker.uuid4(),
36-
),
37-
'tenant_id': fields.String(
38-
required=True,
39-
title='Identifier of Tenant',
40-
description='Tenant this customer belongs to',
41-
example=faker.uuid4(),
42-
),
43-
}
30+
customer_response_fields = {}
4431
customer_response_fields.update(common_fields)
4532

4633
customer = ns.inherit(

time_tracker_api/project_types/project_types_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ProjectTypeDao(CRUDDao):
1515
'partition_key': PartitionKey(path='/tenant_id'),
1616
'unique_key_policy': {
1717
'uniqueKeys': [
18-
{'paths': ['/name', '/customer_id']},
18+
{'paths': ['/name', '/customer_id', '/deleted']},
1919
]
2020
}
2121
}

time_tracker_api/project_types/project_types_namespace.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from flask_restplus import Namespace, Resource, fields
33
from flask_restplus._http import HTTPStatus
44

5-
from time_tracker_api.api import common_fields
5+
from time_tracker_api.api import common_fields, UUID_REGEX
66
from time_tracker_api.project_types.project_types_model import create_dao
77

88
faker = Faker()
@@ -12,45 +12,37 @@
1212
# ProjectType Model
1313
project_type_input = ns.model('ProjectTypeInput', {
1414
'name': fields.String(
15-
required=True,
1615
title='Name',
16+
required=True,
1717
max_length=50,
1818
description='Name of the project type',
1919
example=faker.random_element(["Customer","Training","Internal"]),
2020
),
2121
'description': fields.String(
2222
title='Description',
23+
required=False,
2324
max_length=250,
24-
description='Description about the project type',
25+
description='Comments about the project type',
2526
example=faker.paragraph(),
2627
),
2728
'customer_id': fields.String(
2829
title='Identifier of the Customer',
29-
description='Customer this project type belongs to',
30+
required=False,
31+
description='Customer this project type belongs to. '
32+
'If not specified, it will be considered an internal project of the tenant.',
33+
pattern=UUID_REGEX,
3034
example=faker.uuid4(),
3135
),
3236
'parent_id': fields.String(
33-
title='Identifier of Parent of the project type',
34-
description='Defines a self reference of the model ProjectType',
37+
title='Identifier of the parent project type',
38+
required=False,
39+
description='This parent node allows to created a tree-like structure for project types',
40+
pattern=UUID_REGEX,
3541
example=faker.uuid4(),
3642
),
3743
})
3844

39-
project_type_response_fields = {
40-
'id': fields.String(
41-
readOnly=True,
42-
required=True,
43-
title='Identifier',
44-
description='The unique identifier',
45-
example=faker.uuid4(),
46-
),
47-
'tenant_id': fields.String(
48-
required=True,
49-
title='Identifier of Tenant',
50-
description='Tenant this project type belongs to',
51-
example=faker.uuid4(),
52-
),
53-
}
45+
project_type_response_fields = {}
5446
project_type_response_fields.update(common_fields)
5547

5648
project_type = ns.inherit(

time_tracker_api/projects/projects_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ProjectDao(CRUDDao):
1515
'partition_key': PartitionKey(path='/tenant_id'),
1616
'unique_key_policy': {
1717
'uniqueKeys': [
18-
{'paths': ['/name', '/customer_id']},
18+
{'paths': ['/name', '/customer_id', '/deleted']},
1919
]
2020
}
2121
}

time_tracker_api/projects/projects_namespace.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from flask_restplus import Namespace, Resource, fields
33
from flask_restplus._http import HTTPStatus
44

5-
from time_tracker_api.api import common_fields
5+
from time_tracker_api.api import common_fields, UUID_REGEX
66
from time_tracker_api.projects.projects_model import create_dao
77

88
faker = Faker()
@@ -20,38 +20,30 @@
2020
),
2121
'description': fields.String(
2222
title='Description',
23+
required=False,
2324
max_length=250,
2425
description='Description about the project',
2526
example=faker.paragraph(),
2627
),
2728
'customer_id': fields.String(
28-
required=True,
2929
title='Identifier of the Customer',
30-
description='Customer this project belongs to',
30+
required=False,
31+
description='Customer this project type belongs to. '
32+
'If not specified, it will be considered an internal project of the tenant.',
33+
pattern=UUID_REGEX,
3134
example=faker.uuid4(),
3235
),
3336
'project_type_id': fields.String(
34-
title='Identifier of Project type',
35-
description='Type of the project. Used for grouping',
36-
example=faker.uuid4(),
37-
)
38-
})
39-
40-
project_response_fields = {
41-
'id': fields.String(
42-
readOnly=True,
43-
required=True,
44-
title='Identifier',
45-
description='The unique identifier',
46-
example=faker.uuid4(),
47-
),
48-
'tenant_id': fields.String(
37+
title='Identifier of the project type',
4938
required=False,
50-
title='Identifier of Tenant',
51-
description='Tenant this project belongs to',
39+
description='This id allows to created a tree-like structure for projects, '
40+
'grouped by project types',
41+
pattern=UUID_REGEX,
5242
example=faker.uuid4(),
5343
),
54-
}
44+
})
45+
46+
project_response_fields = {}
5547
project_response_fields.update(common_fields)
5648

5749
project = ns.inherit(

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from commons.data_access_layer.cosmos_db import current_datetime, datetime_str
88
from commons.data_access_layer.database import COMMENTS_MAX_LENGTH
9-
from time_tracker_api.api import common_fields
9+
from time_tracker_api.api import common_fields, UUID_REGEX
1010
from time_tracker_api.time_entries.time_entries_model import create_dao
1111

1212
faker = Faker()
@@ -19,12 +19,21 @@
1919
title='Project',
2020
required=True,
2121
description='The id of the selected project',
22+
pattern=UUID_REGEX,
2223
example=faker.uuid4(),
2324
),
25+
'start_date': fields.DateTime(
26+
dt_format='iso8601',
27+
title='Start date',
28+
required=True,
29+
description='When the user started doing this activity',
30+
example=datetime_str(current_datetime() - timedelta(days=1)),
31+
),
2432
'activity_id': fields.String(
2533
title='Activity',
26-
required=True,
34+
required=False,
2735
description='The id of the selected activity',
36+
pattern=UUID_REGEX,
2837
example=faker.uuid4(),
2938
),
3039
'description': fields.String(
@@ -34,13 +43,6 @@
3443
example=faker.paragraph(nb_sentences=2),
3544
max_length=COMMENTS_MAX_LENGTH,
3645
),
37-
'start_date': fields.DateTime(
38-
dt_format='iso8601',
39-
title='Start date',
40-
required=True,
41-
description='When the user started doing this activity',
42-
example=datetime_str(current_datetime() - timedelta(days=1)),
43-
),
4446
'end_date': fields.DateTime(
4547
dt_format='iso8601',
4648
title='End date',
@@ -50,7 +52,9 @@
5052
),
5153
'uri': fields.String(
5254
title='Uniform Resource identifier',
53-
description='Either identifier or locator',
55+
description='Either identifier or locator of a resource in the Internet that helps to understand'
56+
' what this time entry was about. For example, A Jira ticket, a Github issue, a Google document.',
57+
required=False,
5458
example=faker.random_element([
5559
'https://github.com/ioet/time-tracker-backend/issues/51',
5660
'#54',
@@ -75,25 +79,12 @@
7579
})
7680

7781
time_entry_response_fields = {
78-
'id': fields.String(
79-
readOnly=True,
80-
title='Identifier',
81-
description='The unique identifier',
82-
example=faker.uuid4(),
83-
),
8482
'running': fields.Boolean(
8583
readOnly=True,
8684
title='Is it running?',
8785
description='Whether this time entry is currently running or not',
8886
example=faker.boolean(),
8987
),
90-
'tenant_id': fields.String(
91-
required=True,
92-
readOnly=True,
93-
title='Identifier of Tenant',
94-
description='Tenant this project belongs to',
95-
example=faker.uuid4(),
96-
),
9788
'owner_id': fields.String(
9889
required=True,
9990
readOnly=True,

0 commit comments

Comments
 (0)