Skip to content

Commit

Permalink
Rename ReservationDeleteMutation endpoint in the GraphQL API
Browse files Browse the repository at this point in the history
Deprecated `deleteReservation` endpoint in favour of the more descriptive `deleteTentativeReservation`
  • Loading branch information
ranta authored and matti-lamppu committed Nov 21, 2024
1 parent 2779a79 commit edfcd61
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/test_graphql_api/test_reservation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

CREATE_MUTATION = build_mutation("createReservation", "ReservationCreateMutation")
UPDATE_MUTATION = build_mutation("updateReservation", "ReservationUpdateMutation")
DELETE_MUTATION = build_mutation("deleteReservation", "ReservationDeleteMutation", fields="deleted")
DELETE_MUTATION = build_mutation("deleteTentativeReservation", "ReservationDeleteTentativeMutation", fields="deleted")
ADJUST_MUTATION = build_mutation("adjustReservationTime", "ReservationAdjustTimeMutation")
APPROVE_MUTATION = build_mutation("approveReservation", "ReservationApproveMutation")
DENY_MUTATION = build_mutation("denyReservation", "ReservationDenyMutation")
Expand Down
2 changes: 2 additions & 0 deletions tilavarauspalvelu/api/graphql/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
ReservationConfirmMutation,
ReservationCreateMutation,
ReservationDeleteMutation,
ReservationDeleteTentativeMutation,
ReservationDenyMutation,
ReservationRefundMutation,
ReservationRequiresHandlingMutation,
Expand Down Expand Up @@ -111,6 +112,7 @@
"ReservationConfirmMutation",
"ReservationCreateMutation",
"ReservationDeleteMutation",
"ReservationDeleteTentativeMutation",
"ReservationDenyMutation",
"ReservationRefundMutation",
"ReservationRequiresHandlingMutation",
Expand Down
6 changes: 5 additions & 1 deletion tilavarauspalvelu/api/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
ReservationConfirmMutation,
ReservationCreateMutation,
ReservationDeleteMutation,
ReservationDeleteTentativeMutation,
ReservationDenyMutation,
ReservationRefundMutation,
ReservationRequiresHandlingMutation,
Expand Down Expand Up @@ -343,7 +344,10 @@ class Mutation(graphene.ObjectType):
confirm_reservation = ReservationConfirmMutation.Field()
cancel_reservation = ReservationCancellationMutation.Field()
deny_reservation = ReservationDenyMutation.Field()
delete_reservation = ReservationDeleteMutation.Field()
delete_reservation = ReservationDeleteMutation.Field( # TODO: Remove this after frontend is updated.
deprecation_reason="Renamed to 'deleteTentativeReservation'."
)
delete_tentative_reservation = ReservationDeleteTentativeMutation.Field()
approve_reservation = ReservationApproveMutation.Field()
refund_reservation = ReservationRefundMutation.Field()
require_handling_for_reservation = ReservationRequiresHandlingMutation.Field()
Expand Down
15 changes: 12 additions & 3 deletions tilavarauspalvelu/api/graphql/types/reservation/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,19 @@ class Meta:
permission_classes = [StaffReservationModifyPermission]


class ReservationDeleteMutation(DeleteMutation):
class ReservationDeleteTentativeMutation(DeleteMutation):
"""Used only for deleting a reservation before it is confirmed."""

class Meta:
model = Reservation
permission_classes = [ReservationPermission]

@classmethod
def validate_deletion(cls, reservation: Reservation, user: AnyUser) -> None:
# Check Reservation state
if reservation.state not in ReservationStateChoice.states_that_can_be_cancelled:
if reservation.state not in ReservationStateChoice.states_that_can_be_deleted:
msg = (
f"Reservation which is not in {ReservationStateChoice.states_that_can_be_cancelled} "
f"Reservation which is not in {ReservationStateChoice.states_that_can_be_deleted} "
f"state cannot be deleted."
)
raise ValidationError(msg)
Expand Down Expand Up @@ -175,3 +177,10 @@ def validate_deletion(cls, reservation: Reservation, user: AnyUser) -> None:
pass

payment_order.actions.set_order_as_cancelled()


class ReservationDeleteMutation(ReservationDeleteTentativeMutation):
# TODO: Remove after frontend is updated to use ReservationDeleteTentativeMutation
class Meta:
model = Reservation
permission_classes = [ReservationPermission]
3 changes: 2 additions & 1 deletion tilavarauspalvelu/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ def states_that_can_change_to_deny(self) -> list[str]:
]

@classproperty
def states_that_can_be_cancelled(self) -> list[str]:
def states_that_can_be_deleted(self) -> list[str]:
# "Alustava varaus" / "tentative reservation"
return [ # type: ignore[return-type]
ReservationStateChoice.CREATED.value,
ReservationStateChoice.WAITING_FOR_PAYMENT.value,
Expand Down

0 comments on commit edfcd61

Please sign in to comment.