Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easy back for all of us #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ djangorestframework = "*"
drf-yasg = "*"
python-dateutil = "*"
django-cors-headers = "*"
tzdata = "*"

[dev-packages]
pre-commit = "*"
Expand Down
60 changes: 38 additions & 22 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/company_back/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file modified src/company_back/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file modified src/company_back/__pycache__/urls.cpython-310.pyc
Binary file not shown.
5 changes: 1 addition & 4 deletions src/company_back/admin.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file.
9 changes: 0 additions & 9 deletions src/company_back/balance/serializers.py

This file was deleted.

46 changes: 0 additions & 46 deletions src/company_back/balance/views.py

This file was deleted.

Empty file removed src/company_back/gifts/__init__.py
Empty file.
17 changes: 0 additions & 17 deletions src/company_back/gifts/serializers.py

This file was deleted.

12 changes: 0 additions & 12 deletions src/company_back/gifts/views.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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',
),
]
Binary file not shown.
Binary file not shown.
23 changes: 2 additions & 21 deletions src/company_back/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,25 @@
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


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)
lastName = models.CharField(max_length=64, default=None, blank=True, null=True)
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()
Expand Down Expand Up @@ -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",
)
Expand All @@ -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")
Expand All @@ -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)
5 changes: 2 additions & 3 deletions src/company_back/profile/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,7 +23,7 @@ class Meta:
"birthDate",
"country",
"timezone",
"gifts",

]

read_only_fields = ["id"]
Expand Down
Empty file.
Loading