Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #102 - 동일한 강아지가 동일한 날짜에 다른 이용권으로 예약되는 문제 #103

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions mung_manager/reservations/selectors/reservations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import defaultdict
from datetime import timedelta
from typing import Annotated, Any, Optional

from django.db import connection
Expand Down Expand Up @@ -318,21 +319,24 @@ def get_queryset_for_duplicate_reservation(
Returns:
list[str]: 예약 날짜 리스트를 반환하며, 존재하지 않을 경우 빈 리스트를 반환합니다.
"""
reserved_dates = (
Reservation.objects.filter(
customer_id=customer_id,
customer_pet_id=customer_pet_id,
pet_kindergarden_id=pet_kindergarden_id,
)
.exclude(
reservation_status=ReservationStatus.CANCELED.value,
)
.values_list("reserved_at", flat=True)
reservations = Reservation.objects.filter(
customer_id=customer_id,
customer_pet_id=customer_pet_id,
pet_kindergarden_id=pet_kindergarden_id,
).exclude(
reservation_status=ReservationStatus.CANCELED.value,
)

formatted_dates = [date.strftime("%Y-%m-%d") for date in reserved_dates]
formatted_dates = []
for reservation in reservations:
current_date = reservation.reserved_at.date()
end_date = reservation.end_at.date() # type: ignore

return formatted_dates
while current_date <= end_date:
formatted_dates.append(current_date.strftime("%Y-%m-%d"))
current_date += timedelta(days=1)

return list(set(formatted_dates))

def get_queryset_for_hotel_type_reservation(
self,
Expand Down
2 changes: 1 addition & 1 deletion mung_manager_commons
Loading