|
| 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) |
0 commit comments