Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Template_Categories table #2193

Merged
merged 38 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4bab291
Draft migration to add TemplateCategories table
whabanks Jun 11, 2024
da56d60
Fix prop logic for template_process_type
whabanks Jun 11, 2024
e7346fd
Add indexes, unique constraints
whabanks Jun 12, 2024
70334b0
Add CRUD methods for TemplateCategories
whabanks Jun 13, 2024
0430b4b
Insert low, med, high default categories during migration
whabanks Jun 13, 2024
28637f2
Fix prop logic for template_process_type again
whabanks Jun 13, 2024
b76744e
WIP: Add API endpoints for interacting with TemplateCategories
whabanks Jun 13, 2024
e34dc4a
Implement dao and api to update process_type
whabanks Jun 17, 2024
6a291fc
Address PR comments
whabanks Jun 17, 2024
fcb3550
Finish adding needed api endpoints
whabanks Jun 17, 2024
d8799ac
Chore: logic cleanup
whabanks Jun 17, 2024
6da3eaa
First batch of unit tests & bug fixes
whabanks Jun 18, 2024
a0fd757
Implement filtering when fetching all categories
whabanks Jun 19, 2024
e172bb7
Add lazy join on TemplateCategory
whabanks Jun 19, 2024
8a374c2
Clean up dao tests
whabanks Jun 19, 2024
46d0130
Add tests for deleting a template category
whabanks Jun 19, 2024
98c93bf
Add API tests, squash bugs
whabanks Jun 20, 2024
c7cab45
Fix pre-existing tests
whabanks Jun 24, 2024
6055586
Misc. fixes
whabanks Jun 24, 2024
231128f
We definitely didn't want that FK on templatehistory...
whabanks Jun 24, 2024
654d6b3
Merge branch 'main' into feat/add-template-categories-table
whabanks Jun 24, 2024
33006d7
Logic cleanups
whabanks Jun 24, 2024
8e0afa2
Rename migration
whabanks Jun 25, 2024
f927c99
Add tests for models
whabanks Jun 25, 2024
041a647
Add tests that were missed for template rest and dao
whabanks Jun 25, 2024
0be6d19
Rename /template/category to /template-category
whabanks Jun 25, 2024
44ad1f1
various fixes
whabanks Jun 25, 2024
d1c5c4e
Merge branch 'main' into feat/add-template-categories-table
jzbahrai Jun 27, 2024
1c84439
Re-word dao_delete_template_category_by_id
whabanks Jul 2, 2024
b7f33df
Merge branch 'main' into feat/add-template-categories-table
whabanks Jul 2, 2024
119cac4
Merge branch 'main' into feat/add-template-categories-table
whabanks Jul 2, 2024
1c342e1
Merge branch 'main' into feat/add-template-categories-table
jzbahrai Jul 3, 2024
3c37d1d
Add created_at and updated_at fields
whabanks Jul 3, 2024
38bc4e6
Add default value for created at, fix tests
whabanks Jul 3, 2024
5e1a947
Quick fix
whabanks Jul 3, 2024
ce80c82
Fix column defaults
whabanks Jul 3, 2024
ac90f0d
Fix silly typo..
whabanks Jul 3, 2024
d182ffe
Remove unneeded assert
whabanks Jul 3, 2024
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
2 changes: 2 additions & 0 deletions app/dao/template_categories_dao.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
from datetime import datetime

from flask import current_app
Fixed Show fixed Hide fixed

Expand Down Expand Up @@ -69,6 +70,7 @@ def dao_delete_template_category_by_id(template_category_id, cascade=False):
else template_category.email_process_type
)
template.category = dao_get_template_category_by_id(default_category_id)
template.updated_at = datetime.utcnow
db.session.add(template)

db.session.delete(template_category)
Expand Down
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ class TemplateCategory(BaseModel):
sms_process_type = db.Column(db.String(200), nullable=False)
email_process_type = db.Column(db.String(200), nullable=False)
hidden = db.Column(db.Boolean, nullable=False, default=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow)
updated_at = db.Column(db.DateTime, onupdate=datetime.datetime.utcnow)

def serialize(self):
return {
Expand All @@ -1055,6 +1057,8 @@ def serialize(self):
"sms_process_type": self.sms_process_type,
"email_process_type": self.email_process_type,
"hidden": self.hidden,
"created_at": self.created_at,
"updated_at": self.updated_at,
}

@classmethod
Expand Down
10 changes: 6 additions & 4 deletions migrations/versions/0454_add_template_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@ def upgrade():
sa.Column("sms_process_type", sa.String(length=255), nullable=False),
sa.Column("email_process_type", sa.String(length=255), nullable=False),
sa.Column("hidden", sa.Boolean(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
whabanks marked this conversation as resolved.
Show resolved Hide resolved
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.UniqueConstraint("name_en"),
sa.UniqueConstraint("name_fr"),
)

# Insert the generic low, medium, and high categories
op.execute(
"INSERT INTO template_categories (id, name_en, name_fr, sms_process_type, email_process_type, hidden) VALUES ('{}', 'Low Category (Bulk)', 'Catégorie Basse (En Vrac)', 'low', 'low', true)".format(
current_app.config["DEFAULT_TEMPLATE_CATEGORY_LOW"]
"INSERT INTO template_categories (id, name_en, name_fr, sms_process_type, email_process_type, hidden, created_at) VALUES ('{}', 'Low Category (Bulk)', 'Catégorie Basse (En Vrac)', 'low', 'low', true, now())".format(
current_app.config["DEFAULT_TEMPLATE_CATEGORY_LOW"],
)
)
op.execute(
"INSERT INTO template_categories (id, name_en, name_fr, sms_process_type, email_process_type, hidden) VALUES ('{}', 'Medium Category (Normal)', 'Catégorie Moyenne (Normale)', 'low', 'low', true)".format(
"INSERT INTO template_categories (id, name_en, name_fr, sms_process_type, email_process_type, hidden, created_at) VALUES ('{}', 'Medium Category (Normal)', 'Catégorie Moyenne (Normale)', 'low', 'low', true, now())".format(
current_app.config["DEFAULT_TEMPLATE_CATEGORY_MEDIUM"]
)
)
op.execute(
"INSERT INTO template_categories (id, name_en, name_fr, sms_process_type, email_process_type, hidden) VALUES ('{}', 'High Category (Priority)', 'Catégorie Haute (Priorité)', 'low', 'low', true)".format(
"INSERT INTO template_categories (id, name_en, name_fr, sms_process_type, email_process_type, hidden, created_at) VALUES ('{}', 'High Category (Priority)', 'Catégorie Haute (Priorité)', 'low', 'low', true, now())".format(
current_app.config["DEFAULT_TEMPLATE_CATEGORY_HIGH"]
)
)
Expand Down
2 changes: 2 additions & 0 deletions tests/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ def create_sample_template(
data["postage"] = "second"
if category:
data["category"] = category
else:
data.update({"template_category_id": current_app.config["DEFAULT_TEMPLATE_CATEGORY_LOW"]})
template = Template(**data)
dao_create_template(template)

Expand Down
Loading