Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: Close #85 #86 Ignore deleted objects and tweak ns constraints
  • Loading branch information
EliuX committed Apr 20, 2020
commit 3c2e9dacbd55928dcd38230172f77c5e7b98278b
2 changes: 1 addition & 1 deletion time_tracker_api/activities/activities_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ActivityDao(CRUDDao):
'partition_key': PartitionKey(path='/tenant_id'),
'unique_key_policy': {
'uniqueKeys': [
{'paths': ['/name']},
{'paths': ['/name', '/deleted']},
]
}
}
Expand Down
17 changes: 2 additions & 15 deletions time_tracker_api/activities/activities_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,13 @@
),
'description': fields.String(
title='Description',
required=False,
description='Comments about the activity',
example=faker.paragraph(),
)
})

activity_response_fields = {
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4(),
),
'tenant_id': fields.String(
required=True,
title='Identifier of Tenant',
description='Tenant this activity belongs to',
example=faker.uuid4(),
),
}
activity_response_fields = {}
activity_response_fields.update(common_fields)

activity = ns.inherit(
Expand Down
20 changes: 20 additions & 0 deletions time_tracker_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,33 @@
description="API for the TimeTracker project"
)

# For matching UUIDs
UUID_REGEX = '[0-9a-f]{8}\-[0-9a-f]{4}\-4[0-9a-f]{3}\-[89ab][0-9a-f]{3}\-[0-9a-f]{12}'

# Common models structure
common_fields = {
'id': fields.String(
title='Identifier',
readOnly=True,
required=True,
description='The unique identifier',
pattern=UUID_REGEX,
example=faker.uuid4(),
),
'tenant_id': fields.String(
title='Identifier of Tenant',
readOnly=True,
required=True,
description='Tenant it belongs to',
# pattern=UUID_REGEX, This must be confirmed
example=faker.uuid4(),
),
'deleted': fields.String(
readOnly=True,
required=True,
title='Last event Identifier',
description='Last event over this resource',
pattern=UUID_REGEX,
),
}

Expand Down
2 changes: 1 addition & 1 deletion time_tracker_api/customers/customers_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CustomerDao(CRUDDao):
'partition_key': PartitionKey(path='/tenant_id'),
'unique_key_policy': {
'uniqueKeys': [
{'paths': ['/name']},
{'paths': ['/name', '/deleted']},
]
}
}
Expand Down
19 changes: 3 additions & 16 deletions time_tracker_api/customers/customers_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,22 @@
# Customer Model
customer_input = ns.model('CustomerInput', {
'name': fields.String(
required=True,
title='Name',
required=True,
max_length=50,
description='Name of the customer',
example=faker.company(),
),
'description': fields.String(
title='Description',
required=False,
max_length=250,
description='Description about the customer',
example=faker.paragraph(),
),
})

customer_response_fields = {
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4(),
),
'tenant_id': fields.String(
required=True,
title='Identifier of Tenant',
description='Tenant this customer belongs to',
example=faker.uuid4(),
),
}
customer_response_fields = {}
customer_response_fields.update(common_fields)

customer = ns.inherit(
Expand Down
2 changes: 1 addition & 1 deletion time_tracker_api/project_types/project_types_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProjectTypeDao(CRUDDao):
'partition_key': PartitionKey(path='/tenant_id'),
'unique_key_policy': {
'uniqueKeys': [
{'paths': ['/name', '/customer_id']},
{'paths': ['/name', '/customer_id', '/deleted']},
]
}
}
Expand Down
34 changes: 13 additions & 21 deletions time_tracker_api/project_types/project_types_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask_restplus import Namespace, Resource, fields
from flask_restplus._http import HTTPStatus

from time_tracker_api.api import common_fields
from time_tracker_api.api import common_fields, UUID_REGEX
from time_tracker_api.project_types.project_types_model import create_dao

faker = Faker()
Expand All @@ -12,45 +12,37 @@
# ProjectType Model
project_type_input = ns.model('ProjectTypeInput', {
'name': fields.String(
required=True,
title='Name',
required=True,
max_length=50,
description='Name of the project type',
example=faker.random_element(["Customer","Training","Internal"]),
),
'description': fields.String(
title='Description',
required=False,
max_length=250,
description='Description about the project type',
description='Comments about the project type',
example=faker.paragraph(),
),
'customer_id': fields.String(
title='Identifier of the Customer',
description='Customer this project type belongs to',
required=False,
description='Customer this project type belongs to. '
'If not specified, it will be considered an internal project of the tenant.',
pattern=UUID_REGEX,
example=faker.uuid4(),
),
'parent_id': fields.String(
title='Identifier of Parent of the project type',
description='Defines a self reference of the model ProjectType',
title='Identifier of the parent project type',
required=False,
description='This parent node allows to created a tree-like structure for project types',
pattern=UUID_REGEX,
example=faker.uuid4(),
),
})

project_type_response_fields = {
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4(),
),
'tenant_id': fields.String(
required=True,
title='Identifier of Tenant',
description='Tenant this project type belongs to',
example=faker.uuid4(),
),
}
project_type_response_fields = {}
project_type_response_fields.update(common_fields)

project_type = ns.inherit(
Expand Down
2 changes: 1 addition & 1 deletion time_tracker_api/projects/projects_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ProjectDao(CRUDDao):
'partition_key': PartitionKey(path='/tenant_id'),
'unique_key_policy': {
'uniqueKeys': [
{'paths': ['/name', '/customer_id']},
{'paths': ['/name', '/customer_id', '/deleted']},
]
}
}
Expand Down
34 changes: 13 additions & 21 deletions time_tracker_api/projects/projects_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flask_restplus import Namespace, Resource, fields
from flask_restplus._http import HTTPStatus

from time_tracker_api.api import common_fields
from time_tracker_api.api import common_fields, UUID_REGEX
from time_tracker_api.projects.projects_model import create_dao

faker = Faker()
Expand All @@ -20,38 +20,30 @@
),
'description': fields.String(
title='Description',
required=False,
max_length=250,
description='Description about the project',
example=faker.paragraph(),
),
'customer_id': fields.String(
required=True,
title='Identifier of the Customer',
description='Customer this project belongs to',
required=False,
description='Customer this project type belongs to. '
'If not specified, it will be considered an internal project of the tenant.',
pattern=UUID_REGEX,
example=faker.uuid4(),
),
'project_type_id': fields.String(
title='Identifier of Project type',
description='Type of the project. Used for grouping',
example=faker.uuid4(),
)
})

project_response_fields = {
'id': fields.String(
readOnly=True,
required=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4(),
),
'tenant_id': fields.String(
title='Identifier of the project type',
required=False,
title='Identifier of Tenant',
description='Tenant this project belongs to',
description='This id allows to created a tree-like structure for projects, '
'grouped by project types',
pattern=UUID_REGEX,
example=faker.uuid4(),
),
}
})

project_response_fields = {}
project_response_fields.update(common_fields)

project = ns.inherit(
Expand Down
37 changes: 14 additions & 23 deletions time_tracker_api/time_entries/time_entries_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from commons.data_access_layer.cosmos_db import current_datetime, datetime_str
from commons.data_access_layer.database import COMMENTS_MAX_LENGTH
from time_tracker_api.api import common_fields
from time_tracker_api.api import common_fields, UUID_REGEX
from time_tracker_api.time_entries.time_entries_model import create_dao

faker = Faker()
Expand All @@ -19,12 +19,21 @@
title='Project',
required=True,
description='The id of the selected project',
pattern=UUID_REGEX,
example=faker.uuid4(),
),
'start_date': fields.DateTime(
dt_format='iso8601',
title='Start date',
required=True,
description='When the user started doing this activity',
example=datetime_str(current_datetime() - timedelta(days=1)),
),
'activity_id': fields.String(
title='Activity',
required=True,
required=False,
description='The id of the selected activity',
pattern=UUID_REGEX,
example=faker.uuid4(),
),
'description': fields.String(
Expand All @@ -34,13 +43,6 @@
example=faker.paragraph(nb_sentences=2),
max_length=COMMENTS_MAX_LENGTH,
),
'start_date': fields.DateTime(
dt_format='iso8601',
title='Start date',
required=True,
description='When the user started doing this activity',
example=datetime_str(current_datetime() - timedelta(days=1)),
),
'end_date': fields.DateTime(
dt_format='iso8601',
title='End date',
Expand All @@ -50,7 +52,9 @@
),
'uri': fields.String(
title='Uniform Resource identifier',
description='Either identifier or locator',
description='Either identifier or locator of a resource in the Internet that helps to understand'
' what this time entry was about. For example, A Jira ticket, a Github issue, a Google document.',
required=False,
example=faker.random_element([
'https://github.com/ioet/time-tracker-backend/issues/51',
'#54',
Expand All @@ -75,25 +79,12 @@
})

time_entry_response_fields = {
'id': fields.String(
readOnly=True,
title='Identifier',
description='The unique identifier',
example=faker.uuid4(),
),
'running': fields.Boolean(
readOnly=True,
title='Is it running?',
description='Whether this time entry is currently running or not',
example=faker.boolean(),
),
'tenant_id': fields.String(
required=True,
readOnly=True,
title='Identifier of Tenant',
description='Tenant this project belongs to',
example=faker.uuid4(),
),
'owner_id': fields.String(
required=True,
readOnly=True,
Expand Down