diff --git a/Pipfile b/Pipfile index 4001758..9d192b0 100644 --- a/Pipfile +++ b/Pipfile @@ -12,6 +12,7 @@ djangorestframework = "*" drf-yasg = "*" python-dateutil = "*" django-cors-headers = "*" +tzdata = "*" [dev-packages] pre-commit = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 80b0391..abed1a4 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "3a4b33514a7d3c6ece968ef6b2e0925fdfa94aab3604d5d4940f57b24a5f9bb7" + "sha256": "91b2740f9c39e156027fcad86da6b3c59c11afd9c110c63a0cb50f7fe0511d6b" }, "pipfile-spec": 6, "requires": { @@ -137,11 +137,11 @@ }, "django-cors-headers": { "hashes": [ - "sha256:5fbd58a6fb4119d975754b2bc090f35ec160a8373f276612c675b00e8a138739", - "sha256:684180013cc7277bdd8702b80a3c5a4b3fcae4abb2bf134dceb9f5dfe300228e" + "sha256:a971cd4c75b29974068cc36b5c595698822f1e0edd5f1b32ea42ea37326ad4aa", + "sha256:e3cbd247a1a835da4cf71a70d4214378813ea7e08337778b82cb2c1bc19d28d6" ], "index": "pypi", - "version": "==3.14.0" + "version": "==4.0.0" }, "django-extensions": { "hashes": [ @@ -306,11 +306,11 @@ }, "requests": { "hashes": [ - "sha256:10e94cc4f3121ee6da529d358cdaeaff2f1c409cd377dbc72b825852f2f7e294", - "sha256:239d7d4458afcb28a692cdd298d87542235f4ca8d36d03a15bfc128a6559a2f4" + "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f", + "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1" ], "markers": "python_version >= '3.7'", - "version": "==2.30.0" + "version": "==2.31.0" }, "ruamel.yaml": { "hashes": [ @@ -378,6 +378,14 @@ "markers": "python_version >= '3.5'", "version": "==0.4.4" }, + "tzdata": { + "hashes": [ + "sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a", + "sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda" + ], + "index": "pypi", + "version": "==2023.3" + }, "uritemplate": { "hashes": [ "sha256:4346edfc5c3b79f694bccd6d6099a322bbeb628dbf2cd86eea55a456ce5124f0", @@ -398,11 +406,11 @@ "develop": { "astroid": { "hashes": [ - "sha256:a1b8543ef9d36ea777194bc9b17f5f8678d2c56ee6a45b2c2f17eec96f242347", - "sha256:c81e1c7fbac615037744d067a9bb5f9aeb655edf59b63ee8b59585475d6f80d8" + "sha256:078e5212f9885fa85fbb0cf0101978a336190aadea6e13305409d099f71b2324", + "sha256:1039262575027b441137ab4a62a793a9b43defb42c32d5670f38686207cd780f" ], "markers": "python_full_version >= '3.7.2'", - "version": "==2.15.4" + "version": "==2.15.5" }, "autoflake": { "hashes": [ @@ -459,6 +467,14 @@ "markers": "python_version >= '3.7'", "version": "==8.1.3" }, + "colorama": { + "hashes": [ + "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", + "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" + ], + "markers": "sys_platform == 'win32'", + "version": "==0.4.6" + }, "dill": { "hashes": [ "sha256:a07ffd2351b8c678dfc4a856a3005f8067aea51d6ba6c700796a4d9e280f39f0", @@ -558,11 +574,11 @@ }, "nodeenv": { "hashes": [ - "sha256:27083a7b96a25f2f5e1d8cb4b6317ee8aeda3bdd121394e5ac54e498028a042e", - "sha256:e0e7f7dfb85fc5394c6fe1e8fa98131a2473e04311a45afb6508f7cf1836fa2b" + "sha256:d51e0c37e64fbf47d017feac3145cdbb58836d7eee8c6f6d3b6880c5456227d2", + "sha256:df865724bb3c3adc86b3876fa209771517b0cfe596beff01a92700e0e8be4cec" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6'", - "version": "==1.7.0" + "version": "==1.8.0" }, "packaging": { "hashes": [ @@ -582,19 +598,19 @@ }, "platformdirs": { "hashes": [ - "sha256:47692bc24c1958e8b0f13dd727307cff1db103fca36399f457da8e05f222fdc4", - "sha256:7954a68d0ba23558d753f73437c55f89027cf8f5108c19844d4b82e5af396335" + "sha256:412dae91f52a6f84830f39a8078cecd0e866cb72294a5c66808e74d5e88d251f", + "sha256:e2378146f1964972c03c085bb5662ae80b2b8c06226c54b2ff4aa9483e8a13a5" ], "markers": "python_version >= '3.7'", - "version": "==3.5.0" + "version": "==3.5.1" }, "pre-commit": { "hashes": [ - "sha256:218e9e3f7f7f3271ebc355a15598a4d3893ad9fc7b57fe446db75644543323b9", - "sha256:733f78c9a056cdd169baa6cd4272d51ecfda95346ef8a89bf93712706021b907" + "sha256:66e37bec2d882de1f17f88075047ef8962581f83c234ac08da21a0c58953d1f0", + "sha256:8056bc52181efadf4aac792b1f4f255dfd2fb5a350ded7335d251a68561e8cb6" ], "index": "pypi", - "version": "==3.3.1" + "version": "==3.3.2" }, "pyflakes": { "hashes": [ @@ -660,11 +676,11 @@ }, "setuptools": { "hashes": [ - "sha256:23aaf86b85ca52ceb801d32703f12d77517b2556af839621c641fca11287952b", - "sha256:f104fa03692a2602fa0fec6c6a9e63b6c8a968de13e17c026957dd1f53d80990" + "sha256:5df61bf30bb10c6f756eb19e7c9f3b473051f48db77fddbe06ff2ca307df9a6f", + "sha256:62642358adc77ffa87233bc4d2354c4b2682d214048f500964dbe760ccedf102" ], "markers": "python_version >= '3.7'", - "version": "==67.7.2" + "version": "==67.8.0" }, "tomli": { "hashes": [ diff --git a/src/company_back/__pycache__/__init__.cpython-310.pyc b/src/company_back/__pycache__/__init__.cpython-310.pyc index 5d4cd6e..acb77b4 100644 Binary files a/src/company_back/__pycache__/__init__.cpython-310.pyc and b/src/company_back/__pycache__/__init__.cpython-310.pyc differ diff --git a/src/company_back/__pycache__/settings.cpython-310.pyc b/src/company_back/__pycache__/settings.cpython-310.pyc index 2b5b5db..fea6b0a 100644 Binary files a/src/company_back/__pycache__/settings.cpython-310.pyc and b/src/company_back/__pycache__/settings.cpython-310.pyc differ diff --git a/src/company_back/__pycache__/urls.cpython-310.pyc b/src/company_back/__pycache__/urls.cpython-310.pyc index e3b6052..da92edc 100644 Binary files a/src/company_back/__pycache__/urls.cpython-310.pyc and b/src/company_back/__pycache__/urls.cpython-310.pyc differ diff --git a/src/company_back/admin.py b/src/company_back/admin.py index 1e58f21..14afa44 100644 --- a/src/company_back/admin.py +++ b/src/company_back/admin.py @@ -1,13 +1,10 @@ from django.contrib import admin -from company_back.models import Balance, Chat, Country, Gift, Match, Media, Message, Purchase, User +from company_back.models import Chat, Country, Match, Media, Message, User admin.site.register(Country) -admin.site.register(Balance) admin.site.register(Media) -admin.site.register(Gift) admin.site.register(User) -admin.site.register(Purchase) admin.site.register(Match) admin.site.register(Chat) admin.site.register(Message) diff --git a/src/company_back/balance/__init__.py b/src/company_back/balance/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/company_back/balance/serializers.py b/src/company_back/balance/serializers.py deleted file mode 100644 index 14d9b97..0000000 --- a/src/company_back/balance/serializers.py +++ /dev/null @@ -1,9 +0,0 @@ -from rest_framework import serializers - -from company_back.models import Balance - - -class BalanceSerializer(serializers.ModelSerializer): - class Meta: - model = Balance - fields = "__all__" diff --git a/src/company_back/balance/views.py b/src/company_back/balance/views.py deleted file mode 100644 index 1ccc140..0000000 --- a/src/company_back/balance/views.py +++ /dev/null @@ -1,46 +0,0 @@ -from django.forms import model_to_dict -from rest_framework import status - -from rest_framework.permissions import AllowAny -from rest_framework.response import Response -from rest_framework.decorators import action -from rest_framework.viewsets import ModelViewSet -from company_back.models import Balance -from .serializers import BalanceSerializer - - -class BalanceViewSet(ModelViewSet): - permission_classes = [AllowAny] - - serializer_class = BalanceSerializer - - queryset = Balance.objects.all() - - @action(methods=["get"], detail=False) - def get_own(self, request): - user = request.user - if user.is_anonymous: - return Response(status=status.HTTP_401_UNAUTHORIZED) - balance_id = user.balance_id - if user.balance_id is None: - new_balance = Balance.objects.create(amount=0) - serializer = self.serializer_class(data=model_to_dict(new_balance)) - serializer.is_valid(raise_exception=True) - serializer.save() - balance_id = serializer.data["id"] - setattr(user, "balance_id", balance_id) - user.save() - return Response(serializer.data, status=status.HTTP_200_OK) - balance = Balance.objects.get(id=balance_id) - serializer = self.serializer_class(data=model_to_dict(balance)) - serializer.is_valid(raise_exception=True) - - return Response(serializer.data, status=status.HTTP_200_OK) - - @action(methods=["post"], detail=False) - def add_to_balance(self, request): - balance = request.user.balance - amount = request.data.get("amount") - setattr(balance, "amount", balance.amount + amount) - balance.save() - return Response(model_to_dict(balance), status=status.HTTP_201_CREATED) diff --git a/src/company_back/gifts/__init__.py b/src/company_back/gifts/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/company_back/gifts/serializers.py b/src/company_back/gifts/serializers.py deleted file mode 100644 index e05c007..0000000 --- a/src/company_back/gifts/serializers.py +++ /dev/null @@ -1,17 +0,0 @@ -from rest_framework import serializers -from company_back.media.serializers import MediaSerializer - -from company_back.models import Gift - - -class GiftsSerializer(serializers.ModelSerializer): - class Meta: - model = Gift - fields = "__all__" - - def to_representation(self, instance): - image = instance.image - representation = super().to_representation(instance) - representation["image"] = MediaSerializer(image).data["url"] - - return representation diff --git a/src/company_back/gifts/views.py b/src/company_back/gifts/views.py deleted file mode 100644 index ff96eee..0000000 --- a/src/company_back/gifts/views.py +++ /dev/null @@ -1,12 +0,0 @@ -from rest_framework.permissions import AllowAny -from rest_framework.viewsets import ModelViewSet -from company_back.models import Gift -from .serializers import GiftsSerializer - - -class GiftsViewSet(ModelViewSet): - permission_classes = [AllowAny] - - serializer_class = GiftsSerializer - - queryset = Gift.objects.all() diff --git a/src/company_back/migrations/0007_remove_gift_image_remove_purchase_balance_and_more.py b/src/company_back/migrations/0007_remove_gift_image_remove_purchase_balance_and_more.py new file mode 100644 index 0000000..3428a70 --- /dev/null +++ b/src/company_back/migrations/0007_remove_gift_image_remove_purchase_balance_and_more.py @@ -0,0 +1,46 @@ +# Generated by Django 4.2.1 on 2023-05-23 17:49 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('company_back', '0006_alter_purchase_gift_alter_purchase_reciever'), + ] + + operations = [ + migrations.RemoveField( + model_name='gift', + name='image', + ), + migrations.RemoveField( + model_name='purchase', + name='balance', + ), + migrations.RemoveField( + model_name='purchase', + name='gift', + ), + migrations.RemoveField( + model_name='purchase', + name='reciever', + ), + migrations.RemoveField( + model_name='message', + name='gift', + ), + migrations.RemoveField( + model_name='user', + name='balance', + ), + migrations.DeleteModel( + name='Balance', + ), + migrations.DeleteModel( + name='Gift', + ), + migrations.DeleteModel( + name='Purchase', + ), + ] diff --git a/src/company_back/migrations/__pycache__/0001_initial.cpython-310.pyc b/src/company_back/migrations/__pycache__/0001_initial.cpython-310.pyc deleted file mode 100644 index bf7ff93..0000000 Binary files a/src/company_back/migrations/__pycache__/0001_initial.cpython-310.pyc and /dev/null differ diff --git a/src/company_back/migrations/__pycache__/__init__.cpython-310.pyc b/src/company_back/migrations/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 140401e..0000000 Binary files a/src/company_back/migrations/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/src/company_back/models.py b/src/company_back/models.py index ef3c53a..2ed4dfa 100644 --- a/src/company_back/models.py +++ b/src/company_back/models.py @@ -9,7 +9,7 @@ from django.contrib.auth.models import AbstractBaseUser from django.utils.translation import gettext_lazy as _ -from company_back.const import MatchStatus, MessageStatus, PurchaseStatus, Role +from company_back.const import MatchStatus, MessageStatus, Role from company_back.managers import CustomUserManager @@ -17,18 +17,10 @@ class Country(models.Model): name = models.CharField(max_length=128) -class Balance(models.Model): - amount = models.IntegerField(default=0, blank=True, null=False) - - class Media(models.Model): url = models.CharField(max_length=1024) -class Gift(models.Model): - image = models.OneToOneField(Media, on_delete=models.CASCADE) - price = models.IntegerField(default=0, blank=True, null=False) - class User(AbstractBaseUser): firstName = models.CharField(max_length=64) @@ -36,7 +28,6 @@ class User(AbstractBaseUser): phone = models.CharField(max_length=32, default=None, blank=True, null=True) email = models.EmailField(_("email address"), unique=True) role = models.CharField(max_length=16, default=Role.USER.value, blank=True, null=False) - balance = models.OneToOneField(Balance, on_delete=models.SET_NULL, default=None, blank=True, null=True) avatar = models.OneToOneField(Media, on_delete=models.SET_NULL, default=None, blank=True, null=True) gender = models.CharField(max_length=32, default=None, blank=True, null=True) birthDate = models.DateField() @@ -74,10 +65,9 @@ def token(self): return self.generate_jwt_token() def generate_jwt_token(self): - exp_date = dt.now() + timedelta(days=1) token = jwt.encode( - {"id": self.pk, "exp": int(exp_date.strftime("%s"))}, + {"id": self.pk}, settings.SECRET_KEY, algorithm="HS256", ) @@ -88,14 +78,6 @@ def __str__(self): return str(self.email) -class Purchase(models.Model): - balance = models.ForeignKey(Balance, on_delete=models.SET_NULL, default=None, blank=True, null=True) - gift = models.ForeignKey(Gift, on_delete=models.CASCADE) - reciever = models.ForeignKey(User, related_name="gifts", on_delete=models.CASCADE) - status = models.CharField(max_length=16, default=PurchaseStatus.PENDING.value, blank=True, null=False) - date = models.DateField(blank=True, null=True, auto_now=True) - - class Match(models.Model): status = models.CharField(max_length=16, default=MatchStatus.PENDING.value, blank=True, null=False) initiator = models.ForeignKey(User, on_delete=models.CASCADE, related_name="initiator") @@ -114,4 +96,3 @@ class Message(models.Model): message = models.CharField(max_length=256) date = models.DateTimeField(blank=True, null=True, auto_now=True) status = models.CharField(max_length=16, default=MessageStatus.SENT.value, blank=True, null=False) - gift = models.ForeignKey(Gift, on_delete=models.CASCADE, default=None, blank=True, null=True) diff --git a/src/company_back/profile/serializers.py b/src/company_back/profile/serializers.py index 8834923..56ae8f9 100644 --- a/src/company_back/profile/serializers.py +++ b/src/company_back/profile/serializers.py @@ -5,11 +5,10 @@ from company_back.countries.serializers import CountrySerializer from company_back.media.serializers import MediaSerializer from company_back.models import User -from company_back.purchase.serializers import RecievedGiftSerializer + class ProfileSerializer(serializers.ModelSerializer): - gifts = RecievedGiftSerializer(many=True, read_only=True) class Meta: model = User @@ -24,7 +23,7 @@ class Meta: "birthDate", "country", "timezone", - "gifts", + ] read_only_fields = ["id"] diff --git a/src/company_back/purchase/__init__.py b/src/company_back/purchase/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/company_back/purchase/serializers.py b/src/company_back/purchase/serializers.py deleted file mode 100644 index 24df081..0000000 --- a/src/company_back/purchase/serializers.py +++ /dev/null @@ -1,23 +0,0 @@ -from rest_framework import serializers - -from company_back.gifts.serializers import GiftsSerializer -from company_back.models import Purchase - - -class PurchaseSerializer(serializers.ModelSerializer): - class Meta: - model = Purchase - fields = "__all__" - read_only_fields = ["status", "date"] - extra_kwargs = {"balance": {"required": False}} - - -class RecievedGiftSerializer(serializers.ModelSerializer): - class Meta: - model = Purchase - fields = ["gift"] - read_only_fields = ["gift"] - - def to_representation(self, instance): - gift = instance.gift - return GiftsSerializer().to_representation(gift) diff --git a/src/company_back/purchase/views.py b/src/company_back/purchase/views.py deleted file mode 100644 index 7d211a4..0000000 --- a/src/company_back/purchase/views.py +++ /dev/null @@ -1,27 +0,0 @@ -from rest_framework import status - -from rest_framework.permissions import AllowAny -from rest_framework.response import Response -from rest_framework.decorators import action -from rest_framework.viewsets import ModelViewSet -from company_back.models import Purchase -from .serializers import PurchaseSerializer - - -class PurchseViewSet(ModelViewSet): - permission_classes = [AllowAny] - - serializer_class = PurchaseSerializer - - queryset = Purchase.objects.all() - - @action(methods=["post"], detail=False) - def make_purchase(self, request): - user = request.user - balance_id = user.balance.id - data = dict(request.data) - data["balance"] = balance_id - serializer = self.serializer_class(data=data) - serializer.is_valid(raise_exception=True) - serializer.save() - return Response(serializer.data, status=status.HTTP_201_CREATED) diff --git a/src/company_back/urls.py b/src/company_back/urls.py index 81e9cf2..927d29a 100644 --- a/src/company_back/urls.py +++ b/src/company_back/urls.py @@ -7,14 +7,11 @@ from drf_yasg import openapi from company_back.auth.views import LoginAPIView, RegisterAPIView, LogoutAPIView -from company_back.balance.views import BalanceViewSet from company_back.chats.views import ChatsViewSet from company_back.countries.views import CountriesViewSet -from company_back.gifts.views import GiftsViewSet from company_back.matches.views import CreateMatchAPIView, MatchesViewSet from company_back.messages.views import MessagesViewSet from company_back.profile.views import ProfileViewSet -from company_back.purchase.views import PurchseViewSet from company_back.users.views import UsersViewSet auth_register = RegisterAPIView.as_view() @@ -37,13 +34,6 @@ countries = CountriesViewSet.as_view({"get": "list"}) -gifts_get_list = GiftsViewSet.as_view({"get": "list"}) -gifts_get = GiftsViewSet.as_view({"get": "retrieve"}) - -balance_get = BalanceViewSet.as_view({"get": "get_own"}) -balance_add = BalanceViewSet.as_view({"post": "add_to_balance"}) - -purchase = PurchseViewSet.as_view({"post": "make_purchase"}) schema_view = get_schema_view( @@ -76,9 +66,4 @@ path("chats", chats), path("messages/", messages_get), path("countries", countries), - path("gifts", gifts_get_list), - path("gifts/", gifts_get), - path("balance", balance_get), - path("balance/add", balance_add), - path("purchase", purchase), ]