Skip to content

Commit 159dd08

Browse files
committed
Fixes #64 - Update current models to meet new design.
1 parent d252224 commit 159dd08

File tree

7 files changed

+78
-42
lines changed

7 files changed

+78
-42
lines changed

time_tracker_api/activities/activities_model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ def create_dao() -> ActivityDao:
99
from time_tracker_api.sql_repository import db
1010
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
1111

12-
class ActivitySQLModel(db.Model, AuditedSQLModel):
12+
class ActivitySQLModel(db.Model):
1313
__tablename__ = 'activity'
14-
id = db.Column(db.Integer, primary_key=True)
14+
id = db.Column(db.String, primary_key=True)
1515
name = db.Column(db.String(50), unique=True, nullable=False)
1616
description = db.Column(db.String(250), unique=False, nullable=False)
17+
deleted = db.Column(db.String, default=None)
18+
tenant_id = db.Column(db.String, nullable=False)
1719

1820
def __repr__(self):
1921
return '<Activity %r>' % self.name

time_tracker_api/activities/activities_namespace.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
description='Comments about the activity',
2525
example=faker.paragraph(),
2626
),
27+
'tenant_id': fields.String(
28+
required=True,
29+
title='Identifier of Tenant',
30+
description='Tenant this activity belongs to',
31+
example=faker.uuid4(),
32+
)
2733
})
2834

2935
activity_response_fields = {
@@ -32,8 +38,8 @@
3238
required=True,
3339
title='Identifier',
3440
description='The unique identifier',
35-
example=faker.random_int(1, 9999),
36-
)
41+
example=faker.uuid4(),
42+
),
3743
}
3844
activity_response_fields.update(audit_fields)
3945

time_tracker_api/api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414

1515
# Common models structure
1616
audit_fields = {
17+
'deleted': fields.String(
18+
readOnly=True,
19+
required=True,
20+
title='Last event Identifier',
21+
description='Last event over this resource',
22+
example=faker.uuid4(),
23+
),
24+
}
25+
"""
1726
'created_at': fields.Date(
1827
readOnly=True,
1928
title='Created',
@@ -41,6 +50,7 @@
4150
example='anonymous',
4251
),
4352
}
53+
"""
4454

4555
# APIs
4656
from time_tracker_api.projects import projects_namespace

time_tracker_api/projects/projects_model.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ def create_dao() -> ProjectDao:
2121
from time_tracker_api.database import COMMENTS_MAX_LENGTH
2222
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
2323

24-
class ProjectSQLModel(db.Model, AuditedSQLModel):
24+
class ProjectSQLModel(db.Model):
2525
__tablename__ = 'project'
26-
id = db.Column(db.Integer, primary_key=True)
26+
id = db.Column(db.String, primary_key=True)
2727
name = db.Column(db.String(50), unique=True, nullable=False)
2828
description = db.Column(db.String(COMMENTS_MAX_LENGTH), unique=False, nullable=False)
29-
type = db.Column(db.String(10), nullable=False)
30-
active = db.Column(db.Boolean, default=True)
29+
project_type_id = db.Column(db.String, default=None)
30+
customer_id = db.Column(db.String, nullable=False)
31+
deleted = db.Column(db.String, default=None)
32+
tenant_id = db.Column(db.String, nullable=False)
3133

3234
def __repr__(self):
3335
return '<Project %r>' % self.name

time_tracker_api/projects/projects_namespace.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,23 @@
2424
description='Description about the project',
2525
example=faker.paragraph(),
2626
),
27-
'type': fields.String(
28-
required=False,
29-
title='Type',
30-
max_length=10,
31-
description='If it is `Costumer`, `Training` or other type',
32-
enum=PROJECT_TYPE.valid_type_values(),
33-
example=faker.word(PROJECT_TYPE.valid_type_values()),
27+
'customer_id': fields.String(
28+
required=True,
29+
title='Identifier of the Customer',
30+
description='Customer this project belongs to',
31+
example=faker.uuid4(),
3432
),
35-
'active': fields.Boolean(
36-
title='Is active?',
37-
description='Whether the project is active or not',
38-
default=True,
39-
example=faker.boolean(),
33+
'tenant_id': fields.String(
34+
required=True,
35+
title='Identifier of Tenant',
36+
description='Tenant this project belongs to',
37+
example=faker.uuid4(),
4038
),
39+
'project_type_id': fields.String(
40+
title='Identifier of Project type',
41+
description='Type of the project. Used for grouping',
42+
example=faker.uuid4(),
43+
)
4144
})
4245

4346
project_response_fields = {
@@ -46,7 +49,7 @@
4649
required=True,
4750
title='Identifier',
4851
description='The unique identifier',
49-
example=faker.random_int(1, 9999),
52+
example=faker.uuid4(),
5053
)
5154
}
5255
project_response_fields.update(audit_fields)

time_tracker_api/time_entries/time_entries_model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ def create_dao() -> TimeEntriesDao:
1212
from time_tracker_api.database import COMMENTS_MAX_LENGTH
1313
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
1414

15-
class TimeEntrySQLModel(db.Model, AuditedSQLModel):
15+
class TimeEntrySQLModel(db.Model):
1616
__tablename__ = 'time_entry'
17-
id = db.Column(db.Integer, primary_key=True)
17+
id = db.Column(db.String, primary_key=True)
1818
description = db.Column(db.String(COMMENTS_MAX_LENGTH))
1919
start_date = db.Column(db.DateTime, server_default=db.func.now())
2020
end_date = db.Column(db.DateTime)
21-
project_id = db.Column(db.Integer,
21+
project_id = db.Column(db.String,
2222
db.ForeignKey('project.id'),
2323
nullable=False)
24-
activity_id = db.Column(db.Integer,
24+
activity_id = db.Column(db.String,
2525
db.ForeignKey('activity.id'),
2626
nullable=False)
2727
technologies = db.Column(ScalarListType())
28+
uri = db.Column(db.String(500))
29+
owner_id = db.Column(db.String, nullable=False)
30+
deleted = db.Column(db.String, default=None)
31+
tenant_id = db.Column(db.String, nullable=False)
2832

2933
@property
3034
def running(self):

time_tracker_api/time_entries/time_entries_namespace.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,17 @@
1414

1515
# TimeEntry Model
1616
time_entry_input = ns.model('TimeEntryInput', {
17-
'project_id': fields.Integer(
17+
'project_id': fields.String(
1818
required=True,
1919
title='Project',
2020
description='The id of the selected project',
21-
example=faker.random_int(1, 9999),
21+
example=faker.uuid4(),
2222
),
23-
'activity_id': fields.Integer(
23+
'activity_id': fields.String(
24+
required=True,
2425
title='Activity',
2526
description='The id of the selected activity',
26-
example=faker.random_int(1, 9999),
27-
),
28-
'technologies': fields.List(
29-
fields.String(
30-
required=True,
31-
title='Technologies',
32-
description='Technology names used in this time-entry',
33-
),
34-
example=faker.words(
35-
3,
36-
['java', 'elixir', 'python', 'docker'],
37-
unique=True
38-
)
27+
example=faker.uuid4(),
3928
),
4029
'description': fields.String(
4130
title='Comments',
@@ -54,14 +43,34 @@
5443
description='When the user ended doing this activity',
5544
example=faker.iso8601(end_datetime=None),
5645
),
46+
'uri': fields.String(
47+
title='Uniform Resource identifier',
48+
description='Either identifier or locator',
49+
example=faker.words(
50+
1,
51+
['http://example.com/mypage.html', '/some/page.html']
52+
),
53+
),
54+
'owner_id': fields.String(
55+
required=True,
56+
title='Owner of time entry',
57+
description='User who owns the time entry',
58+
example=faker.uuid4(),
59+
),
60+
'tenant_id': fields.String(
61+
required=True,
62+
title='Identifier of Tenant',
63+
description='Tenant this project belongs to',
64+
example=faker.uuid4(),
65+
),
5766
})
5867

5968
time_entry_response_fields = {
6069
'id': fields.String(
6170
readOnly=True,
6271
title='Identifier',
6372
description='The unique identifier',
64-
example=faker.random_int(1, 9999),
73+
example=faker.uuid4(),
6574
),
6675
'running': fields.Boolean(
6776
readOnly=True,

0 commit comments

Comments
 (0)