Skip to content

Commit 520ddcb

Browse files
Added table release notifications and added business object (#192)
* Added table release notifications and added business object * Added create release notification and email on display * Update and delete release notifications * display notifications in reverse order * PR comments
1 parent 451af39 commit 520ddcb

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import List
2+
from ..models import ReleaseNotification
3+
from . import general
4+
from ..session import session
5+
from datetime import datetime
6+
7+
8+
def get(release_notification_id: str) -> ReleaseNotification:
9+
return (
10+
session.query(ReleaseNotification)
11+
.filter(ReleaseNotification.id == release_notification_id)
12+
.first()
13+
)
14+
15+
16+
def get_all() -> List[ReleaseNotification]:
17+
return (
18+
session.query(ReleaseNotification)
19+
.order_by(ReleaseNotification.created_at.desc())
20+
.all()
21+
)
22+
23+
24+
def create(
25+
link: str,
26+
config: str,
27+
created_by: str,
28+
with_commit: bool = False,
29+
) -> ReleaseNotification:
30+
release_notification = ReleaseNotification(
31+
link=link, config=config, created_by=created_by
32+
)
33+
general.add(release_notification, with_commit)
34+
return release_notification
35+
36+
37+
def update(
38+
notification_id: str,
39+
link: str,
40+
config: str,
41+
with_commit: bool = False,
42+
) -> ReleaseNotification:
43+
release_notification = get(notification_id)
44+
45+
if release_notification is None:
46+
return
47+
48+
if link is not None:
49+
release_notification.link = link
50+
if config is not None:
51+
release_notification.config = config
52+
53+
general.flush_or_commit(with_commit)
54+
return release_notification
55+
56+
57+
def delete(notification_id: str, with_commit: bool = False):
58+
release_notification = get(notification_id)
59+
general.delete(release_notification, with_commit)
60+
general.flush_or_commit(with_commit)

enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class Tablenames(Enum):
176176
)
177177
SUMS_TABLE = "sums_table"
178178
ADMIN_QUERY_MESSAGE_SUMMARY = "admin_query_message_summary"
179+
RELEASE_NOTIFICATION = "release_notification"
179180

180181
def snake_case_to_pascal_case(self):
181182
# the type name (written in PascalCase) of a table is needed to create backrefs

models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,3 +2490,17 @@ class AdminQueryMessageSummary(Base):
24902490
deleted_messages_by_user = Column(Integer, default=0)
24912491
deleted_messages_by_system = Column(Integer, default=0)
24922492
incognito_messages = Column(Integer, default=0)
2493+
2494+
2495+
class ReleaseNotification(Base):
2496+
__tablename__ = Tablenames.RELEASE_NOTIFICATION.value
2497+
__table_args__ = {"schema": "global"}
2498+
id = Column(Integer, primary_key=True, autoincrement=True)
2499+
created_at = Column(DateTime, default=sql.func.now())
2500+
created_by = Column(
2501+
UUID(as_uuid=True),
2502+
ForeignKey(f"{Tablenames.USER.value}.id", ondelete="SET NULL"),
2503+
index=True,
2504+
)
2505+
link = Column(String, nullable=False)
2506+
config = Column(JSON) # e.g. {"en": {"headline":"", "description":""}, "de": {...}}

0 commit comments

Comments
 (0)