31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from sqlalchemy.orm import Session
|
|
|
|
from src.api.models.subscription import Subscription
|
|
from src.api.schemas.subscription import FlightData
|
|
from src.api.schemas.subscription import Subscription as SubscriptionPydantic
|
|
|
|
|
|
def get_subscriptions(db: Session, user_id: int):
|
|
return db.query(Subscription).filter(Subscription.user_id == user_id).all()
|
|
|
|
|
|
def create_subscription(db: Session, subscription: SubscriptionPydantic):
|
|
db_subscription = Subscription(
|
|
user_id=subscription.user_id,
|
|
flight_id=subscription.flight_id,
|
|
)
|
|
db.add(db_subscription)
|
|
db.commit()
|
|
db.refresh(db_subscription)
|
|
return db_subscription
|
|
|
|
|
|
def remove_subscription(db: Session, user_id: int, flight_id: int):
|
|
db.query(Subscription).filter(Subscription.user_id == user_id
|
|
and Subscription.flight_id == flight_id).delete()
|
|
db.commit()
|
|
|
|
|
|
def send_subscriptions(db: Session, flight: FlightData):
|
|
return db.query(Subscription).filter(Subscription.flight_id == flight.id).all()
|