Exemplo n.º 1
0
 def update_by_id(id: int, new_description: str) -> int:
     query_found = (session.query(Reminder).filter(
         Reminder.id == id).update({"description": new_description},
                                   synchronize_session="fetch"))
     if query_found:
         session.commit()
     return query_found
Exemplo n.º 2
0
    def remove_tag_from_reminder(id: int, tag_name: str):
        tag = session.query(Tag).filter_by(tag_name=tag_name).first()
        reminder = session.query(Reminder).filter_by(id=id).first()
        if tag is not None and reminder is not None:
            reminder.tags.remove(tag)
            tag_association = session.query(reminder_tag).filter_by(
                tag_id=tag.id).all()
            if not len(tag_association):
                session.delete(tag)
            session.commit()
        else:
            # TODO
            # !! Get rid of this VIEW stuff here. MOVE IT to view.py !!
            rp.rule(
                title=
                ":no_entry: [bold white]Invalid Entry[/bold white] :no_entry:",
                style="red",
            )
            if tag is None:
                rp.print(
                    f"[bold]Tag [red]{tag_name}[/red] is not associated with given the reminder."
                )
            if reminder is None:
                rp.print(
                    f"[bold]Reminder with id [red]{id}[/red] does not exist.")

            return None
Exemplo n.º 3
0
    def delete_by_id(id: int):
        reminder: Reminder = session.query(Reminder).get(id)
        if reminder is not None:
            for tag in reminder.tags:
                reminder_tag_query = (
                    # check association table to check if tags associated with deleted reminder
                    # are associated with any other reminders. If they're not, delete them.
                    session.query(reminder_tag).filter_by(tag_id=tag.id).all())
                if len(reminder_tag_query) == 1:
                    # Tag is only associated with one reminder, the one being deleted, so delete tag too
                    session.delete(tag)

            session.delete(reminder)
            session.commit()

            return reminder

        else:
            return None
Exemplo n.º 4
0
 def tag_reminder_by_id(id: int, tag_name: str):
     reminder = session.query(Reminder).filter_by(id=id).first()
     ReminderCrud.tag_reminder([tag_name], reminder)
     session.commit()
Exemplo n.º 5
0
 def save(reminder: Reminder):
     session.add(reminder)
     session.commit()