diff --git a/browser-domain/src/components/Landing/Landing.tsx b/browser-domain/src/components/Landing/Landing.tsx index f257991..e7bc58f 100644 --- a/browser-domain/src/components/Landing/Landing.tsx +++ b/browser-domain/src/components/Landing/Landing.tsx @@ -21,7 +21,7 @@ const LandingPage: React.FC = () => {
diff --git a/subscription-domain/subscription-manager/src/api/cruds/subscription.py b/subscription-domain/subscription-manager/src/api/cruds/subscription.py index ae59c9c..d87b6a1 100644 --- a/subscription-domain/subscription-manager/src/api/cruds/subscription.py +++ b/subscription-domain/subscription-manager/src/api/cruds/subscription.py @@ -40,5 +40,10 @@ def remove_subscription(db: Session, user_id: int, flight_id: int): db.commit() +def remove_subscriptions(db: Session, user_id: int): + db.query(Subscription).filter(Subscription.user_id == user_id).delete() + db.commit() + + def send_subscriptions(db: Session, flight: FlightData): return db.query(Subscription).filter(Subscription.flight_id == flight.id).all() diff --git a/subscription-domain/subscription-manager/src/api/routes/notifications.py b/subscription-domain/subscription-manager/src/api/routes/notifications.py index c453361..b93bd9a 100644 --- a/subscription-domain/subscription-manager/src/api/routes/notifications.py +++ b/subscription-domain/subscription-manager/src/api/routes/notifications.py @@ -14,6 +14,7 @@ from src.api.utils.messages import ( get_flight_message, get_invalid_message, get_start_message, + get_stop_message, ) router = APIRouter() @@ -44,9 +45,14 @@ async def create_chat( background_tasks.add_task(telegram.send_message, chat_id, msg) elif action == "/stop": chat_id = str(message["chat"]["id"]) - user_id = notif_crud.get_user_from_chat(db=db, chat_id=chat_id).user_id - subs_crud.remove_subscriptions(user_id) + user = notif_crud.get_user_from_chat(db=db, chat_id=chat_id) + if user is None: + return Response(status_code=204) + user_id = user.user_id + subs_crud.remove_subscriptions(db=db, user_id=user_id) notif_crud.remove_chat(db=db, chat_id=chat_id) + msg = get_stop_message(str(user_id)) + background_tasks.add_task(telegram.send_message, chat_id, msg) elif action == "/flight": chat_id = str(message["chat"]["id"]) flight_id = int(message["text"].partition(" ")[2]) diff --git a/subscription-domain/subscription-manager/src/api/utils/messages.py b/subscription-domain/subscription-manager/src/api/utils/messages.py index e325c59..9c1bac5 100644 --- a/subscription-domain/subscription-manager/src/api/utils/messages.py +++ b/subscription-domain/subscription-manager/src/api/utils/messages.py @@ -42,3 +42,7 @@ def get_start_message(): "\n/flight NUMBER (e.g., /flight 1) for flight details" "\n/stop to stop receiving updates." ) + + +def get_stop_message(user_id): + return f"You have successfully stopped receiving updates. Type /start {user_id} to resume updates."