Skip to content

Commit

Permalink
feat: setup auctions for sending transaction to accounts service
Browse files Browse the repository at this point in the history
  • Loading branch information
sandronadiradze committed Nov 4, 2024
1 parent 800225d commit d0893e6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
47 changes: 31 additions & 16 deletions auction/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.db import DatabaseError, transaction
Expand Down Expand Up @@ -164,22 +166,6 @@ def get_queryset(self):
ordering = ordering.replace("category", "category__name")
queryset = queryset.order_by(ordering)

event_body = {
"user_id": str(self.request.user.id),
}
event_headers = {
"event_name": "Message_recieve",
"source_service": "accounts",
"target_service": "auctions",
"message_type": "delete",
"priority": "High",
"version": "1.0",
}

event_publisher.publish_event(
event_body, event_headers, routing_key="Message_recieve"
)

return queryset


Expand Down Expand Up @@ -1172,6 +1158,9 @@ def update_auction_winner(self, bid):
bid.auction.status = StatusChoices.COMPLETED
bid.auction.save()

# Send rabbitmq message to account service
self.send_event_message(bid)

return {
"message": _("Winner of this auction has successfully been declared"),
"bid_id": str(bid.id),
Expand All @@ -1180,6 +1169,32 @@ def update_auction_winner(self, bid):
"winner_author_id": str(bid.author),
}

def send_event_message(self, bid):
event_body = {
"auction_id": str(bid.auction.id),
"seller_id": str(bid.author),
"buyer_id": str(bid.auction.author),
"amount": str(bid.offer),
"date": timezone.now().strftime("%Y:%m:%d-%H:%M:%S"),
"currency": bid.auction.currency,
}

event_headers = {
"event_id": str(uuid.uuid4()),
"event_name": "declaring_auction_winner",
"source_service": "auction",
"target_service": "accounts",
"message_type": "create",
"timestamp": timezone.now().strftime("%Y:%m:%d-%H:%M:%S"),
"priority": "High",
"event_type": "declaring_auction_winner",
"version": "1.0",
}

return event_publisher.publish_event(
event_body, event_headers, routing_key="declaring_auction_winner"
)

def post(self, request, auction_id, bid_id, *args, **kwargs):
try:
bid = self.get_bid(auction_id, bid_id)
Expand Down
32 changes: 16 additions & 16 deletions locale/ka/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-04 08:27+0000\n"
"POT-Creation-Date: 2024-11-04 15:38+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -74,74 +74,74 @@ msgstr "თქვენ არ შეგიძლიათ შეცვალო
msgid "There was an error during the update of the auction. Please try again."
msgstr "აუქციონის შექმნისას პრობლემამ იჩინა თავი. გთხოვთ სცადოთ თავიდან."

#: auction/views.py:601
#: auction/views.py:613
msgid "Auction deleted successfully."
msgstr "აუქციონი წარმატებით წაიშალა."

#: auction/views.py:711
#: auction/views.py:723
#, python-brace-format
msgid "Auction with UUID {id} does not exist."
msgstr "აუქციონი მოცემული იდენტიფიკატორით {id} არ არსებობს."

#: auction/views.py:720
#: auction/views.py:732
#, python-brace-format
msgid ""
"{deleted} auctions deleted and {marked_deleted} auctions marked as deleted."
msgstr ""
"წაიშალა {deleted} აუქციონი და {marked_deleted} აუქციონი მონიშნულია, როგორც "
"წაშლილი."

#: auction/views.py:1091
#: auction/views.py:1103
msgid ""
"Only the bids with a status of either Pending or Approved can be declared as "
"winner bids."
msgstr ""
"მხოლოდ დაეფრუვებული ან მომლოდინე რეჟიმის მქონე ბიდები შეიძლება გამოცხადნენ "
"გამარჯვებულებად."

#: auction/views.py:1107
#: auction/views.py:1119
msgid "You can only declare a winner after the auction has been completed."
msgstr ""
"გამარჯვებულის გამოცხადება მხოლოდ აუქციონის დასრულების შემდეგ შეგიძლიათ."

#: auction/views.py:1149
#: auction/views.py:1165
msgid "Winner of this auction has successfully been declared"
msgstr "აუქციონის გამარჯვებული წარმატებით გამოვლინდა."

#: auction/views.py:1249
#: auction/views.py:1291
msgid "You can not cancel draft auctions."
msgstr "თქვენ არ შეგიძლიათ დრაფტ სტატუსის მქონე აუქციონის გაუქმება."

#: auction/views.py:1250
#: auction/views.py:1292
msgid "This auction is already canceled."
msgstr "ეს აუქციონი უკვე გაუქმებულია."

#: auction/views.py:1251
#: auction/views.py:1293
msgid "You can not cancel deleted auctions."
msgstr "თქვენ არ შეგიძლიათ წაშლილი აუქციონის გაუქმება."

#: auction/views.py:1253
#: auction/views.py:1295
msgid "You can not cancel auctions that have already been completed."
msgstr "თქვენ არ შეგიძლიათ გააუქომთ აუქციონი, რომელიც უკვე დასრულებულია."

#: auction/views.py:1275
#: auction/views.py:1317
msgid "Auction was successfully canceled."
msgstr "აუქციონის გაუქმება წარმატებით განხორციელდა."

#: auction/views.py:1367
#: auction/views.py:1409
msgid "You can not leave an auction that has already been completed."
msgstr "თქვენ არ შეგიძლიათ დატოვოთ აუქციონი რომელიც უკვე დასრულდა."

#: auction/views.py:1371
#: auction/views.py:1413
msgid "You can not leave an auction that has not started yet."
msgstr "თქვენ არ შეგიძლიათ დატოვოთ აუქციონი, რომელიც ჯერ არ დაწყებულა."

#: auction/views.py:1375
#: auction/views.py:1417
msgid "You can not leave an auction that has been cancelled, drafted."
msgstr ""
"თქვენ არ შეგიძლიათ გაუქმებული ან drafter სტატუსის მქონე აუქციონის დატოვება."

#: auction/views.py:1380
#: auction/views.py:1422
msgid "As a winner of an auction, you can not leave it."
msgstr "როგორც გამარჯვებული, თქვენ ვერ დატოვებთ აუქციონს."

Expand Down

0 comments on commit d0893e6

Please sign in to comment.