diff --git a/backend/Pipfile b/backend/Pipfile index 1f2f551..89ab621 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -8,23 +8,26 @@ django = ">=4.2.6" djangorestframework = ">=3.14.0" django-environ = ">=0.11.2" psycopg2-binary = ">=2.9.9" -boto3 = ">=1.29.6" +boto3 = ">=1.34.47" django-storages = ">=1.14.2" djangorestframework-simplejwt = ">=5.3.1" -cryptography = ">=42.0.2" +cryptography = ">=42.0.3" requests = ">=2.31.0" -pyjwt = ">=2.8.0" +PyJWT = ">=2.8.0" django-cors-headers = ">=4.3.1" zappa = ">=0.58.0" -pandas = ">=2.2.1" +pandas = ">=2.0.3" gunicorn = "*" drf-jwt = ">=1.19.2" django-cognito-jwt = ">=0.0.4" +channels = ">=4.1.0" +daphne = ">=4.1.0" +asgiref = ">=3.8.1" [dev-packages] flake8 = ">=6.1.0" isort = ">=5.12.0" -black = ">=23.10.0" +black = ">=23.11.0" [requires] python_version = "3.10" diff --git a/backend/Pipfile.lock b/backend/Pipfile.lock index 8f3b54d..fcdbb5d 100644 --- a/backend/Pipfile.lock +++ b/backend/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "67d8d019dd9a5474bf2adfcddabc6a9e9faafc3f19ebfe44e11916c01f1b98b8" + "sha256": "48096edbeae49abcf796580aea29c9b2920b4f323ff62fccdca51d04f89640ba" }, "pipfile-spec": 6, "requires": { @@ -29,25 +29,48 @@ "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47", "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590" ], + "index": "pypi", "markers": "python_version >= '3.8'", "version": "==3.8.1" }, + "attrs": { + "hashes": [ + "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30", + "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1" + ], + "markers": "python_version >= '3.7'", + "version": "==23.2.0" + }, + "autobahn": { + "hashes": [ + "sha256:ec9421c52a2103364d1ef0468036e6019ee84f71721e86b36fe19ad6966c1181" + ], + "markers": "python_version >= '3.9'", + "version": "==23.6.2" + }, + "automat": { + "hashes": [ + "sha256:c3164f8742b9dc440f3682482d32aaff7bb53f71740dd018533f9de286b64180", + "sha256:e56beb84edad19dcc11d30e8d9b895f75deeb5ef5e96b84a467066b3b84bb04e" + ], + "version": "==22.10.0" + }, "boto3": { "hashes": [ - "sha256:ba5d2104bba4370766036d64ad9021eb6289d154265852a2a821ec6a5e816faa", - "sha256:eaec72fda124084105a31bcd67eafa1355b34df6da70cadae0c0f262d8a4294f" + "sha256:004dad209d37b3d2df88f41da13b7ad702a751904a335fac095897ff7a19f82b", + "sha256:18224d206a8a775bcaa562d22ed3d07854934699190e12b52fcde87aac76a80e" ], "index": "pypi", "markers": "python_version >= '3.8'", - "version": "==1.34.75" + "version": "==1.34.81" }, "botocore": { "hashes": [ - "sha256:06113ee2587e6160211a6bd797e135efa6aa21b5bde97bf455c02f7dff40203c", - "sha256:1d7f683d99eba65076dfb9af3b42fa967c64f11111d9699b65757420902aa002" + "sha256:85f6fd7c5715eeef7a236c50947de00f57d72e7439daed1125491014b70fab01", + "sha256:f79bf122566cc1f09d71cc9ac9fcf52d47ba48b761cbc3f064017b36a3c40eb8" ], "markers": "python_version >= '3.8'", - "version": "==1.34.75" + "version": "==1.34.81" }, "certifi": { "hashes": [ @@ -122,6 +145,15 @@ ], "version": "==1.3.0" }, + "channels": { + "hashes": [ + "sha256:a3c4419307f582c3f71d67bfb6eff748ae819c2f360b9b141694d84f242baa48", + "sha256:e0ed375719f5c1851861f05ed4ce78b0166f9245ca0ecd836cb77d4bb531489d" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==4.1.0" + }, "charset-normalizer": { "hashes": [ "sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027", @@ -226,6 +258,14 @@ "markers": "python_version >= '3.7'", "version": "==8.1.7" }, + "constantly": { + "hashes": [ + "sha256:3fd9b4d1c3dc1ec9757f3c52aef7e53ad9323dbe39f51dfd4c43853b68dfa3f9", + "sha256:aa92b70a33e2ac0bb33cd745eb61776594dc48764b06c35e0efd050b7f1c7cbd" + ], + "markers": "python_version >= '3.8'", + "version": "==23.10.4" + }, "cryptography": { "hashes": [ "sha256:0270572b8bd2c833c3981724b8ee9747b3ec96f699a9665470018594301439ee", @@ -265,14 +305,23 @@ "markers": "python_version >= '3.7'", "version": "==42.0.5" }, + "daphne": { + "hashes": [ + "sha256:7228cd6a3ca5a9b11c9a1c1c0414dab1bfb4ddc55ff234b545db8d71f6c24938", + "sha256:882fab39d0b90c6b2709b38116c95f660b6cf236600115dd7c13161fb98b3448" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==4.1.0" + }, "django": { "hashes": [ - "sha256:5c7d748ad113a81b2d44750ccc41edc14e933f56581683db548c9257e078cc83", - "sha256:5fb37580dcf4a262f9258c1f4373819aacca906431f505e4688e37f3a99195df" + "sha256:4bd01a8c830bb77a8a3b0e7d8b25b887e536ad17a81ba2dce5476135c73312bd", + "sha256:916423499d75d62da7aa038d19aef23d23498d8df229775eb0a6309ee1013775" ], "index": "pypi", "markers": "python_version >= '3.10'", - "version": "==5.0.3" + "version": "==5.0.4" }, "django-cognito-jwt": { "hashes": [ @@ -358,6 +407,13 @@ ], "version": "==3.1.0" }, + "hyperlink": { + "hashes": [ + "sha256:427af957daa58bc909471c6c40f74c5450fa123dd093fc53efd2e91d2705a56b", + "sha256:e6b14c37ecb73e89c77d78cdb4c2cc8f3fb59a885c5b3f819ff4ed80f25af1b4" + ], + "version": "==21.0.0" + }, "idna": { "hashes": [ "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", @@ -366,6 +422,13 @@ "markers": "python_version >= '3.5'", "version": "==3.6" }, + "incremental": { + "hashes": [ + "sha256:912feeb5e0f7e0188e6f42241d2f450002e11bbc0937c65865045854c24c0bd0", + "sha256:b864a1f30885ee72c5ac2835a761b8fe8aa9c28b9395cacf27286602688d3e51" + ], + "version": "==22.10.0" + }, "jmespath": { "hashes": [ "sha256:02e2e4cc71b5bcab88332eebf907519190dd9e6e82107fa7f83b1003a6252980", @@ -626,6 +689,22 @@ "markers": "python_version >= '3.7'", "version": "==2.9.9" }, + "pyasn1": { + "hashes": [ + "sha256:3a35ab2c4b5ef98e17dfdec8ab074046fbda76e281c5a706ccd82328cfc8f64c", + "sha256:cca4bb0f2df5504f02f6f8a775b6e416ff9b0b3b16f7ee80b5a3153d9b804473" + ], + "markers": "python_version >= '3.8'", + "version": "==0.6.0" + }, + "pyasn1-modules": { + "hashes": [ + "sha256:831dbcea1b177b28c9baddf4c6d1013c24c3accd14a1873fffaa6a2e905f17b6", + "sha256:be04f15b66c206eed667e0bb5ab27e2b1855ea54a842e5037738099e8ca4ae0b" + ], + "markers": "python_version >= '3.8'", + "version": "==0.4.0" + }, "pycparser": { "hashes": [ "sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6", @@ -639,10 +718,16 @@ "sha256:57e28d156e3d5c10088e0c68abb90bfac3df82b40a71bd0daa20c65ccd5c23de", "sha256:59127c392cc44c2da5bb3192169a91f429924e17aff6534d70fdc02ab3e04320" ], - "index": "pypi", "markers": "python_version >= '3.7'", "version": "==2.8.0" }, + "pyopenssl": { + "hashes": [ + "sha256:17ed5be5936449c5418d1cd269a1a9e9081bc54c17aed272b45856a3d3dc86ad", + "sha256:cabed4bfaa5df9f1a16c0ef64a0cb65318b5cd077a7eda7d6970131ca2f41a6f" + ], + "version": "==24.1.0" + }, "python-dateutil": { "hashes": [ "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", @@ -740,6 +825,21 @@ "markers": "python_version >= '3.8'", "version": "==0.10.1" }, + "service-identity": { + "hashes": [ + "sha256:6829c9d62fb832c2e1c435629b0a8c476e1929881f28bee4d20bc24161009221", + "sha256:a28caf8130c8a5c1c7a6f5293faaf239bbfb7751e4862436920ee6f2616f568a" + ], + "version": "==24.1.0" + }, + "setuptools": { + "hashes": [ + "sha256:0ff4183f8f42cd8fa3acea16c45205521a4ef28f73c6391d8a25e92893134f2e", + "sha256:c21c49fb1042386df081cb5d86759792ab89efca84cf114889191cd09aacc80c" + ], + "markers": "python_version >= '3.8'", + "version": "==69.2.0" + }, "six": { "hashes": [ "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", @@ -787,13 +887,32 @@ "markers": "python_version >= '3.8'", "version": "==4.7.0" }, + "twisted": { + "extras": [ + "tls" + ], + "hashes": [ + "sha256:039f2e6a49ab5108abd94de187fa92377abe5985c7a72d68d0ad266ba19eae63", + "sha256:6b38b6ece7296b5e122c9eb17da2eeab3d98a198f50ca9efd00fb03e5b4fd4ae" + ], + "markers": "python_full_version >= '3.8.0'", + "version": "==24.3.0" + }, + "txaio": { + "hashes": [ + "sha256:aaea42f8aad50e0ecfb976130ada140797e9dcb85fad2cf72b0f37f8cefcb490", + "sha256:f9a9216e976e5e3246dfd112ad7ad55ca915606b60b84a757ac769bd404ff704" + ], + "markers": "python_version >= '3.7'", + "version": "==23.1.1" + }, "typing-extensions": { "hashes": [ - "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475", - "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb" + "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0", + "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a" ], "markers": "python_version < '3.11'", - "version": "==4.10.0" + "version": "==4.11.0" }, "tzdata": { "hashes": [ @@ -835,6 +954,48 @@ "index": "pypi", "markers": "python_version >= '3.7'", "version": "==0.58.0" + }, + "zope-interface": { + "hashes": [ + "sha256:02adbab560683c4eca3789cc0ac487dcc5f5a81cc48695ec247f00803cafe2fe", + "sha256:14e02a6fc1772b458ebb6be1c276528b362041217b9ca37e52ecea2cbdce9fac", + "sha256:25e0af9663eeac6b61b231b43c52293c2cb7f0c232d914bdcbfd3e3bd5c182ad", + "sha256:2606955a06c6852a6cff4abeca38346ed01e83f11e960caa9a821b3626a4467b", + "sha256:396f5c94654301819a7f3a702c5830f0ea7468d7b154d124ceac823e2419d000", + "sha256:3b240883fb43160574f8f738e6d09ddbdbf8fa3e8cea051603d9edfd947d9328", + "sha256:3b6c62813c63c543a06394a636978b22dffa8c5410affc9331ce6cdb5bfa8565", + "sha256:4ae9793f114cee5c464cc0b821ae4d36e1eba961542c6086f391a61aee167b6f", + "sha256:4bce517b85f5debe07b186fc7102b332676760f2e0c92b7185dd49c138734b70", + "sha256:4d45d2ba8195850e3e829f1f0016066a122bfa362cc9dc212527fc3d51369037", + "sha256:4dd374927c00764fcd6fe1046bea243ebdf403fba97a937493ae4be2c8912c2b", + "sha256:506f5410b36e5ba494136d9fa04c548eaf1a0d9c442b0b0e7a0944db7620e0ab", + "sha256:59f7374769b326a217d0b2366f1c176a45a4ff21e8f7cebb3b4a3537077eff85", + "sha256:5ee9789a20b0081dc469f65ff6c5007e67a940d5541419ca03ef20c6213dd099", + "sha256:6fc711acc4a1c702ca931fdbf7bf7c86f2a27d564c85c4964772dadf0e3c52f5", + "sha256:75d2ec3d9b401df759b87bc9e19d1b24db73083147089b43ae748aefa63067ef", + "sha256:76e0531d86523be7a46e15d379b0e975a9db84316617c0efe4af8338dc45b80c", + "sha256:8af82afc5998e1f307d5e72712526dba07403c73a9e287d906a8aa2b1f2e33dd", + "sha256:8f5d2c39f3283e461de3655e03faf10e4742bb87387113f787a7724f32db1e48", + "sha256:97785604824981ec8c81850dd25c8071d5ce04717a34296eeac771231fbdd5cd", + "sha256:a3046e8ab29b590d723821d0785598e0b2e32b636a0272a38409be43e3ae0550", + "sha256:abb0b3f2cb606981c7432f690db23506b1db5899620ad274e29dbbbdd740e797", + "sha256:ac7c2046d907e3b4e2605a130d162b1b783c170292a11216479bb1deb7cadebe", + "sha256:af27b3fe5b6bf9cd01b8e1c5ddea0a0d0a1b8c37dc1c7452f1e90bf817539c6d", + "sha256:b386b8b9d2b6a5e1e4eadd4e62335571244cb9193b7328c2b6e38b64cfda4f0e", + "sha256:b66335bbdbb4c004c25ae01cc4a54fd199afbc1fd164233813c6d3c2293bb7e1", + "sha256:d54f66c511ea01b9ef1d1a57420a93fbb9d48a08ec239f7d9c581092033156d0", + "sha256:de125151a53ecdb39df3cb3deb9951ed834dd6a110a9e795d985b10bb6db4532", + "sha256:de7916380abaef4bb4891740879b1afcba2045aee51799dfd6d6ca9bdc71f35f", + "sha256:e2fefad268ff5c5b314794e27e359e48aeb9c8bb2cbb5748a071757a56f6bb8f", + "sha256:e7b2bed4eea047a949296e618552d3fed00632dc1b795ee430289bdd0e3717f3", + "sha256:e87698e2fea5ca2f0a99dff0a64ce8110ea857b640de536c76d92aaa2a91ff3a", + "sha256:ede888382882f07b9e4cd942255921ffd9f2901684198b88e247c7eabd27a000", + "sha256:f444de0565db46d26c9fa931ca14f497900a295bd5eba480fc3fad25af8c763e", + "sha256:fa994e8937e8ccc7e87395b7b35092818905cf27c651e3ff3e7f29729f5ce3ce", + "sha256:febceb04ee7dd2aef08c2ff3d6f8a07de3052fc90137c507b0ede3ea80c21440" + ], + "markers": "python_version >= '3.7'", + "version": "==6.2" } }, "develop": { @@ -959,11 +1120,11 @@ }, "typing-extensions": { "hashes": [ - "sha256:69b1a937c3a517342112fb4c6df7e72fc39a38e7891a5730ed4985b5214b5475", - "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb" + "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0", + "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a" ], "markers": "python_version < '3.11'", - "version": "==4.10.0" + "version": "==4.11.0" } } } diff --git a/backend/auction/migrations/0003_alter_auctionverifieduser_cognito_user_id.py b/backend/auction/migrations/0003_alter_auctionverifieduser_cognito_user_id.py new file mode 100644 index 0000000..6f4a123 --- /dev/null +++ b/backend/auction/migrations/0003_alter_auctionverifieduser_cognito_user_id.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.7 on 2024-04-08 06:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("auction", "0002_auction_end_time_auction_start_time_auctionday_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="auctionverifieduser", + name="cognito_user_id", + field=models.CharField(max_length=2500), + ), + ] diff --git a/backend/auction/models.py b/backend/auction/models.py index d747a17..86ecf72 100644 --- a/backend/auction/models.py +++ b/backend/auction/models.py @@ -56,7 +56,7 @@ def save(self, *args, **kwargs): class AuctionVerifiedUser(MainModel): - cognito_user_id = models.CharField(max_length=255, null=False, blank=False) + cognito_user_id = models.CharField(max_length=2500, null=False, blank=False) auction = models.ForeignKey(Auction, on_delete=models.CASCADE) is_verified = models.BooleanField(default=False) diff --git a/backend/bid/apps.py b/backend/bid/apps.py index 8f7600f..8ffee1f 100644 --- a/backend/bid/apps.py +++ b/backend/bid/apps.py @@ -4,3 +4,6 @@ class BidConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "bid" + + def ready(self): + import bid.signals diff --git a/backend/bid/consumer.py b/backend/bid/consumer.py new file mode 100644 index 0000000..a976d27 --- /dev/null +++ b/backend/bid/consumer.py @@ -0,0 +1,35 @@ +import json + +from asgiref.sync import async_to_sync +from channels.generic.websocket import AsyncWebsocketConsumer + + +class BidConsumer(AsyncWebsocketConsumer): + async def connect(self): + self.group_name = "bid_updates" + await self.channel_layer.group_add(self.group_name, self.channel_name) + await self.accept() + + async def disconnect(self, close_code): + await self.channel_layer.group_discard(self.group_name, self.channel_name) + + async def receive(self, text_data): + text_data_json = json.loads(text_data) + message = text_data_json.get("message") + if message: + await self.send(text_data=json.dumps({"message": message})) + + async def bid_update(self, event): + bid_data = event["bid_data"] + + bid_data["id"] = str(bid_data["id"]) + + await self.send( + text_data=json.dumps({"type": "bid.update", "bid_data": bid_data}) + ) + + async def bid_delete(self, event): + bid_id = event["bid_id"] + await self.send( + text_data=json.dumps({"type": "bid.delete", "bid_id": str(bid_id)}) + ) diff --git a/backend/bid/migrations/0002_alter_bid_bidder.py b/backend/bid/migrations/0002_alter_bid_bidder.py new file mode 100644 index 0000000..21da55f --- /dev/null +++ b/backend/bid/migrations/0002_alter_bid_bidder.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.7 on 2024-04-08 06:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("bid", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="bid", + name="bidder", + field=models.CharField(max_length=500), + ), + ] diff --git a/backend/bid/models.py b/backend/bid/models.py index fbb54db..363e0a2 100644 --- a/backend/bid/models.py +++ b/backend/bid/models.py @@ -12,7 +12,7 @@ class Bid(MainModel): """ amount = models.IntegerField(null=False) - bidder = models.CharField(null=False, max_length=255) + bidder = models.CharField(null=False, max_length=500) auction = models.ForeignKey(Auction, on_delete=models.PROTECT) content_type = models.ForeignKey(ContentType, on_delete=models.PROTECT) object_id = models.UUIDField() diff --git a/backend/bid/routing.py b/backend/bid/routing.py new file mode 100644 index 0000000..1f0a17b --- /dev/null +++ b/backend/bid/routing.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import consumer + +websocket_urlpatterns = [ + path("ws/bid_updates/", consumer.BidConsumer.as_asgi()), +] diff --git a/backend/bid/signals.py b/backend/bid/signals.py new file mode 100644 index 0000000..a825361 --- /dev/null +++ b/backend/bid/signals.py @@ -0,0 +1,44 @@ +# signals.py +import json + +from asgiref.sync import async_to_sync +from channels.layers import get_channel_layer +from django.db.models.signals import post_delete, post_save +from django.dispatch import receiver + +from auction.models import AuctionDay + +from .models import Bid + +channel_layer = get_channel_layer() + + +@receiver(post_save, sender=Bid) +def bid_updated(sender, instance, **kwargs): + current_date = instance.auction.start_date.date() + auction_day = AuctionDay.objects.filter( + auction=instance.auction, date=current_date + ).first() + + bid_data = { + "id": str(instance.id), + "amount": instance.amount, + "auction_id": str(instance.auction.id), + "auction_day_id": str(auction_day.id) if auction_day else None, + "vehicle_id": str(instance.object_id), + "bidder": str(instance.bidder), + } + async_to_sync(channel_layer.group_send)( + "bid_updates", {"type": "bid.update", "bid_data": bid_data} + ) + + +@receiver(post_delete, sender=Bid) +def bid_deleted(sender, instance, **kwargs): + async_to_sync(channel_layer.group_send)( + "bid_updates", + { + "type": "bid.delete", + "bid_id": instance.id, + }, + ) diff --git a/backend/bid/urls.py b/backend/bid/urls.py index 44a68e7..eae5fbe 100644 --- a/backend/bid/urls.py +++ b/backend/bid/urls.py @@ -1,6 +1,7 @@ from django.contrib import admin from django.urls import include, path +from . import consumer from .views import BidDetailApiView, BidListApiView urlpatterns = [ diff --git a/backend/bid/views.py b/backend/bid/views.py index dcd134d..4ad0985 100644 --- a/backend/bid/views.py +++ b/backend/bid/views.py @@ -1,7 +1,7 @@ from django.contrib.contenttypes.models import ContentType from rest_framework import status from rest_framework.generics import get_object_or_404 -from rest_framework.permissions import IsAuthenticated +from rest_framework.permissions import AllowAny, IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView @@ -87,7 +87,7 @@ def post(self, request, *args, **kwargs): .order_by("-amount") .first() ) - if highest_bid and amount <= highest_bid.amount: + if highest_bid and int(amount) <= highest_bid.amount: return Response( {"error": "Your bid must be higher than the current highest bid."}, status=status.HTTP_400_BAD_REQUEST, diff --git a/backend/core/asgi.py b/backend/core/asgi.py index 361ea22..888a8a7 100644 --- a/backend/core/asgi.py +++ b/backend/core/asgi.py @@ -1,16 +1,24 @@ -""" -ASGI config for backend project. - -It exposes the ASGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ -""" - +# mysite/asgi.py import os +from channels.auth import AuthMiddlewareStack +from channels.routing import ProtocolTypeRouter, URLRouter +from channels.security.websocket import AllowedHostsOriginValidator from django.core.asgi import get_asgi_application +import bid.routing + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings") +# Initialize Django ASGI application early to ensure the AppRegistry +# is populated before importing code that may import ORM models. +django_asgi_app = get_asgi_application() + -application = get_asgi_application() +application = ProtocolTypeRouter( + { + "http": django_asgi_app, + "websocket": AllowedHostsOriginValidator( + AuthMiddlewareStack(URLRouter(bid.routing.websocket_urlpatterns)) + ), + } +) diff --git a/backend/core/settings.py b/backend/core/settings.py index 620b0d9..a68d744 100644 --- a/backend/core/settings.py +++ b/backend/core/settings.py @@ -36,6 +36,7 @@ # Application definition INSTALLED_APPS = [ + "daphne", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", @@ -50,8 +51,11 @@ "user", "vehicle", "bid", + "channels", ] +ASGI_APPLICATION = "core.asgi.application" +CHANNEL_LAYERS = {"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}} # AWS S3 Configuration AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID") AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY") @@ -124,7 +128,6 @@ } } - # Password validation # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 33cd9a7..deb42ea 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -6421,9 +6421,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001607", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001607.tgz", - "integrity": "sha512-WcvhVRjXLKFB/kmOFVwELtMxyhq3iM/MvmXcyCe2PNf166c39mptscOc/45TTS96n2gpNV2z7+NakArTWZCQ3w==", + "version": "1.0.30001608", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001608.tgz", + "integrity": "sha512-cjUJTQkk9fQlJR2s4HMuPMvTiRggl0rAVMtthQuyOlDWuqHXqN8azLq+pi8B2TjwKJ32diHjUqRIKeFX4z1FoA==", "funding": [ { "type": "opencollective",