Skip to content

Commit 51091f5

Browse files
authored
Fixes #64 - Update current models to meet new design. (#65)
* Fixes #64 - Update current models to meet new design. * Fixes #64 - Update tests * Fixes #64 - Apply PR observations Close #64
1 parent d252224 commit 51091f5

File tree

11 files changed

+100
-75
lines changed

11 files changed

+100
-75
lines changed

tests/activities/activities_namespace_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
valid_activity_data = {
1010
"name": fake.company(),
11-
"description": fake.paragraph()
11+
"description": fake.paragraph(),
12+
"tenant_id": fake.uuid4()
1213
}
1314

1415
fake_activity = ({

tests/projects/projects_namespace_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
valid_project_data = {
1212
"name": fake.company(),
1313
"description": fake.paragraph(),
14-
"type": fake.word(PROJECT_TYPE.valid_type_values()),
14+
'customer_id': fake.uuid4(),
15+
'tenant_id': fake.uuid4(),
16+
'project_type_id': fake.uuid4()
1517
}
18+
1619
fake_project = ({
1720
"id": fake.random_int(1, 9999)
1821
}).update(valid_project_data)

tests/resources.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from time_tracker_api.sql_repository import db, AuditedSQLModel
22

3+
from sqlalchemy_utils import UUIDType
4+
import uuid
5+
36

47
class PersonSQLModel(db.Model, AuditedSQLModel):
58
__tablename__ = 'test'
6-
id = db.Column(db.Integer, primary_key=True)
9+
id = db.Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
710
name = db.Column(db.String(80), unique=False, nullable=False)
811
email = db.Column(db.String(120), unique=True, nullable=False)
912
age = db.Column(db.Integer, nullable=False)

tests/time_entries/time_entries_namespace_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
fake = Faker()
88

99
valid_time_entry_input = {
10-
"project_id": fake.random_int(1, 9999),
11-
"activity_id": fake.random_int(1, 9999),
12-
"technologies": fake.words(3, ['java', 'javascript', 'python', 'azure'], unique=True),
10+
"project_id": fake.uuid4(),
11+
"activity_id": fake.uuid4(),
1312
"description": fake.paragraph(nb_sentences=2),
1413
"start_date": fake.iso8601(end_datetime=None),
1514
"end_date": fake.iso8601(end_datetime=None),
15+
"owner_id": fake.uuid4(),
16+
"tenant_id": fake.uuid4()
1617
}
1718
fake_time_entry = ({
1819
"id": fake.random_int(1, 9999),

time_tracker_api/activities/activities_model.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ class ActivityDao(CRUDDao):
77

88
def create_dao() -> ActivityDao:
99
from time_tracker_api.sql_repository import db
10-
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
10+
from time_tracker_api.sql_repository import SQLCRUDDao
11+
from sqlalchemy_utils import UUIDType
12+
import uuid
1113

12-
class ActivitySQLModel(db.Model, AuditedSQLModel):
14+
class ActivitySQLModel(db.Model):
1315
__tablename__ = 'activity'
14-
id = db.Column(db.Integer, primary_key=True)
16+
id = db.Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
1517
name = db.Column(db.String(50), unique=True, nullable=False)
1618
description = db.Column(db.String(250), unique=False, nullable=False)
19+
deleted = db.Column(UUIDType(binary=False), default=uuid.uuid4)
20+
tenant_id = db.Column(UUIDType(binary=False), default=uuid.uuid4)
1721

1822
def __repr__(self):
1923
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: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,12 @@
1414

1515
# Common models structure
1616
audit_fields = {
17-
'created_at': fields.Date(
17+
'deleted': fields.String(
1818
readOnly=True,
19-
title='Created',
20-
description='Date of creation',
21-
example=faker.iso8601(end_datetime=None),
22-
),
23-
'updated_at': fields.Date(
24-
readOnly=True,
25-
title='Updated',
26-
description='Date of update',
27-
example=faker.iso8601(end_datetime=None),
28-
),
29-
'created_by': fields.String(
30-
readOnly=True,
31-
title='Creator',
32-
max_length=64,
33-
description='User that created it',
34-
example='anonymous',
35-
),
36-
'updated_by': fields.String(
37-
readOnly=True,
38-
title='Updater',
39-
max_length=64,
40-
description='User that updated it',
41-
example='anonymous',
19+
required=True,
20+
title='Last event Identifier',
21+
description='Last event over this resource',
22+
example=faker.uuid4(),
4223
),
4324
}
4425

time_tracker_api/projects/projects_model.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ class ProjectDao(CRUDDao):
1919
def create_dao() -> ProjectDao:
2020
from time_tracker_api.sql_repository import db
2121
from time_tracker_api.database import COMMENTS_MAX_LENGTH
22-
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
22+
from time_tracker_api.sql_repository import SQLCRUDDao
23+
from sqlalchemy_utils import UUIDType
24+
import uuid
2325

24-
class ProjectSQLModel(db.Model, AuditedSQLModel):
26+
class ProjectSQLModel(db.Model):
2527
__tablename__ = 'project'
26-
id = db.Column(db.Integer, primary_key=True)
28+
id = db.Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
2729
name = db.Column(db.String(50), unique=True, nullable=False)
2830
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)
31+
project_type_id = db.Column(UUIDType(binary=False), default=uuid.uuid4)
32+
customer_id = db.Column(UUIDType(binary=False), default=uuid.uuid4)
33+
deleted = db.Column(UUIDType(binary=False), default=uuid.uuid4)
34+
tenant_id = db.Column(UUIDType(binary=False), default=uuid.uuid4)
3135

3236
def __repr__(self):
3337
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: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,27 @@ class TimeEntriesDao(CRUDDao):
1010
def create_dao() -> TimeEntriesDao:
1111
from time_tracker_api.sql_repository import db
1212
from time_tracker_api.database import COMMENTS_MAX_LENGTH
13-
from time_tracker_api.sql_repository import SQLCRUDDao, AuditedSQLModel
13+
from time_tracker_api.sql_repository import SQLCRUDDao
14+
from sqlalchemy_utils import UUIDType
15+
import uuid
1416

15-
class TimeEntrySQLModel(db.Model, AuditedSQLModel):
17+
class TimeEntrySQLModel(db.Model):
1618
__tablename__ = 'time_entry'
17-
id = db.Column(db.Integer, primary_key=True)
19+
id = db.Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4)
1820
description = db.Column(db.String(COMMENTS_MAX_LENGTH))
1921
start_date = db.Column(db.DateTime, server_default=db.func.now())
2022
end_date = db.Column(db.DateTime)
21-
project_id = db.Column(db.Integer,
23+
project_id = db.Column(UUIDType(binary=False),
2224
db.ForeignKey('project.id'),
2325
nullable=False)
24-
activity_id = db.Column(db.Integer,
26+
activity_id = db.Column(UUIDType(binary=False),
2527
db.ForeignKey('activity.id'),
2628
nullable=False)
2729
technologies = db.Column(ScalarListType())
30+
uri = db.Column(db.String(500))
31+
owner_id = db.Column(UUIDType(binary=False), default=uuid.uuid4)
32+
deleted = db.Column(UUIDType(binary=False), default=uuid.uuid4)
33+
tenant_id = db.Column(UUIDType(binary=False), default=uuid.uuid4)
2834

2935
@property
3036
def running(self):

0 commit comments

Comments
 (0)