Skip to content

Commit

Permalink
Merge pull request #206 from MikiEremiki/develop
Browse files Browse the repository at this point in the history
feat: Добавлен функционал для фильтрации мероприятий по типу, месяцу и актуальности
  • Loading branch information
MikiEremiki authored Oct 16, 2024
2 parents dec0dce + 047224c commit 876b5fa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
14 changes: 14 additions & 0 deletions src/db/db_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,20 @@ async def get_schedule_events_by_theater_ids_actual(
return result.scalars().all()


async def get_schedule_events_by_theater_and_month_and_types_actual(
session: AsyncSession,
theater_event_ids: List[int],
type_event_ids: List[int]
):
query = select(ScheduleEvent).where(
ScheduleEvent.theater_event_id.in_(theater_event_ids),
ScheduleEvent.type_event_id.in_(type_event_ids),
ScheduleEvent.datetime_event >= datetime.now()
).order_by(ScheduleEvent.datetime_event)
result = await session.execute(query)
return result.scalars().all()


async def get_actual_schedule_events_by_date(
session: AsyncSession, date_event: date):
query = select(ScheduleEvent).where(
Expand Down
20 changes: 15 additions & 5 deletions src/handlers/reserve_hl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
send_message_about_list_waiting,
remove_button_from_last_message,
create_and_send_payment, processing_successful_payment,
get_theater_and_schedule_events_by_month,
get_theater_and_schedule_events_by_month, get_schedule_events_by_month,
)
from db.db_googlesheets import (
load_clients_data,
Expand Down Expand Up @@ -188,12 +188,19 @@ async def choice_date(update: Update, context: ContextTypes.DEFAULT_TYPE):
await query.answer()

theater_event_id = int(query.data)

reserve_user_data = context.user_data['reserve_user_data']
number_of_month_str = reserve_user_data['number_of_month_str']
theater_event = await db_postgres.get_theater_event(
context.session, theater_event_id)
schedule_events = await db_postgres.get_schedule_events_by_theater_ids_actual(
context.session, [theater_event_id])
command = context.user_data['command']
type_event_ids = await get_type_event_ids_by_command(command)
schedule_events = await (
db_postgres.get_schedule_events_by_theater_and_month_and_types_actual(
context.session,
[theater_event_id],
type_event_ids
))
schedule_events = await get_schedule_events_by_month(schedule_events,
number_of_month_str)

keyboard = await create_kbd_for_date_in_reserve(schedule_events)
reply_markup = await create_replay_markup(
Expand All @@ -214,6 +221,9 @@ async def choice_date(update: Update, context: ContextTypes.DEFAULT_TYPE):
flag_christmas_tree = True
if event.flag_santa:
flag_santa = True

theater_event = await db_postgres.get_theater_event(
context.session, theater_event_id)
full_name = get_full_name_event(theater_event.name,
theater_event.flag_premier,
theater_event.min_age_child,
Expand Down
35 changes: 22 additions & 13 deletions src/handlers/sub_hl.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ async def get_theater_and_schedule_events_by_month(context, schedule_events,
return tuple(enum_theater_events), schedule_events_filter_by_month


async def get_schedule_events_by_month(schedule_events,
number_of_month_str):
schedule_events_filter_by_month = []
for event in schedule_events:
if event.datetime_event.month == int(number_of_month_str):
schedule_events_filter_by_month.append(event)
return schedule_events_filter_by_month


async def remove_button_from_last_message(update, context):
message_id = context.user_data['common_data']['message_id_buy_info']
try:
Expand Down Expand Up @@ -307,17 +316,17 @@ async def create_and_send_payment(
full_name_for_desc = full_name[:len_for_name]
description = f'Билет на мероприятие {full_name_for_desc} {date_event} в {time_event}'
param = create_param_payment(
price=chose_price,
description=' '.join([description, ticket_name_for_desc]),
email=email,
payment_method_type=context.config.yookassa.payment_method_type,
chat_id=update.effective_chat.id,
message_id=message.message_id,
ticket_ids='|'.join(str(v) for v in ticket_ids),
choose_schedule_event_ids='|'.join(
str(v) for v in choose_schedule_event_ids),
command=command
)
price=chose_price,
description=' '.join([description, ticket_name_for_desc]),
email=email,
payment_method_type=context.config.yookassa.payment_method_type,
chat_id=update.effective_chat.id,
message_id=message.message_id,
ticket_ids='|'.join(str(v) for v in ticket_ids),
choose_schedule_event_ids='|'.join(
str(v) for v in choose_schedule_event_ids),
command=command
)
idempotency_id = uuid.uuid4()
try:
payment = Payment.create(param, idempotency_id)
Expand Down Expand Up @@ -440,7 +449,7 @@ async def processing_successful_payment(
client_data['name_adult'],
'+7' + client_data['phone'],
original_child_text,
])
])
text += '\n\n'

if '_admin' in command:
Expand Down Expand Up @@ -811,7 +820,7 @@ async def send_approve_reject_message_to_admin_in_webhook(
client_data['name_adult'],
'+7' + client_data['phone'],
original_child_text,
])
])
text += '\n\n'
for ticket_id in ticket_ids:
text += f'#ticket_id <code>{ticket_id}</code>'
Expand Down

0 comments on commit 876b5fa

Please sign in to comment.