Skip to content

Commit

Permalink
chore: start notifing auction viewers about auction being cancelled v…
Browse files Browse the repository at this point in the history
…ia websocket connection
  • Loading branch information
sandronadiradze committed Nov 4, 2024
1 parent ea7972a commit 39a1958
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions auction/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,9 +1263,22 @@ def post(self, request, auction_id):
self.validate_auction_status(auction)
auction.status = StatusChoices.CANCELED
auction.save()
self.notify_auction_group(auction)
transaction.on_commit(lambda: revoke_auction_bids.delay(auction.id))

return Response(
{"message": _("Auction was successfully canceled.")},
status=status.HTTP_200_OK,
)

def notify_auction_group(self, auction):
channel_layer = get_channel_layer()
data = {"auction_id": str(auction.id), "auction_status": "Cancelled"}

async_to_sync(channel_layer.group_send)(
f"auction_{str(auction.id)}",
{
"type": "auction_cancelled_notification",
"message": data,
},
)
11 changes: 11 additions & 0 deletions bid/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,14 @@ async def bookmarks_count_notification(self, event):
"bookmarks_count": event["message"],
}
)

async def auction_cancelled_notification(self, event):
"""
Handles real-time notifications for cancelled auctions.
"""
await self.send_json(
{
"type": "auction_cancelled_notification",
"data": event["message"],
}
)

0 comments on commit 39a1958

Please sign in to comment.