async def get_cinema_hall_list(): async with db.transaction(): cinema_hall_list = await CinemaHall.query.order_by(CinemaHall.id).gino.all() cinema_hall_list = [ CinemaHallOut.from_model(cinema) for cinema in cinema_hall_list ] return cinema_hall_list
async def get_booking_list(): async with db.transaction(): booking_list = await Booking.query.order_by(Booking.id).gino.all() booking_list = [ BookingOut.from_model(booking) for booking in booking_list ] return booking_list
async def get_cinema_hall(cinema_id: int, cinema_hall_id: int): async with db.transaction(): cinema_hall = await CinemaHall.query.where( and_(CinemaHall.id == cinema_hall_id, CinemaHall.id_cinema == cinema_id) ).gino.first() if not cinema_hall: raise HTTPException(status_code=404, detail="Cinema hall not found") return CinemaHallOut.from_model(cinema_hall)
async def get_cinema_hall_list(cinema_id: int): async with db.transaction(): cinema_hall_list = await CinemaHall.query.where( CinemaHall.id_cinema == cinema_id ).gino.all() cinema_hall_list = [ CinemaHallOut.from_model(cinema) for cinema in cinema_hall_list ] return cinema_hall_list
async def get_film_show_list(start_date: str = None, end_date: str = None): start_date, end_date = validate_date(start_date), validate_date(end_date) async with db.transaction(): query = FilmShow.query if start_date: query = query.where(FilmShow.start_time >= datetime.combine( start_date, DAY_END_TIME)) if end_date: query = query.where(FilmShow.end_time < datetime.combine( end_date + timedelta(days=1), DAY_END_TIME)) film_show_list = await query.order_by(FilmShow.id).gino.all() film_show_list = [ FilmShowOut.from_model(film_show) for film_show in film_show_list ] return film_show_list
async def get_film_show_list(cinema_id: int, cinema_hall_id: int): async with db.transaction(): cinema = await Cinema.query.where(Cinema.id == cinema_id).gino.first() if not cinema: raise HTTPException(status_code=404, detail="Cinema not found") cinema_hall = await CinemaHall.query.where( and_(CinemaHall.id == cinema_hall_id, CinemaHall.id_cinema == cinema_id) ).gino.first() if not cinema_hall: raise HTTPException(status_code=404, detail="Cinema hall not found") film_show = await FilmShow.query.where( FilmShow.id_hall == cinema_hall.id ).gino.all() if not film_show: raise HTTPException(status_code=404, detail="Film show not found") film_show_list = [FilmShowOut.from_model(show) for show in film_show] return film_show_list
async def get_film_list(): async with db.transaction(): film_list = await Film.query.order_by(Film.id).gino.all() film_list = [FilmOut.from_model(film) for film in film_list] return film_list