From f2e65c295055f3c53a0bb51559210c581fd49f98 Mon Sep 17 00:00:00 2001 From: rizwanisready Date: Mon, 11 Mar 2024 17:23:01 +0530 Subject: [PATCH] referrals api --- accounts/api/urls.py | 3 - accounts/api/views.py | 41 ------------- .../migrations/0003_iamprincipal_player_id.py | 18 ++++++ accounts/models.py | 1 + goodtimes/settings/base.py | 1 + goodtimes/urls.py | 2 + manage_notifications/__init__.py | 0 manage_notifications/admin.py | 3 + manage_notifications/apps.py | 6 ++ manage_notifications/forms.py | 0 manage_notifications/migrations/__init__.py | 0 manage_notifications/models.py | 57 +++++++++++++++++++ manage_notifications/tests.py | 3 + manage_notifications/urls.py | 10 ++++ manage_notifications/views.py | 3 + manage_referrals/api/urls.py | 4 +- manage_referrals/api/views.py | 8 +-- manage_referrals/models.py | 6 +- 18 files changed, 110 insertions(+), 56 deletions(-) create mode 100644 accounts/migrations/0003_iamprincipal_player_id.py create mode 100644 manage_notifications/__init__.py create mode 100644 manage_notifications/admin.py create mode 100644 manage_notifications/apps.py create mode 100644 manage_notifications/forms.py create mode 100644 manage_notifications/migrations/__init__.py create mode 100644 manage_notifications/models.py create mode 100644 manage_notifications/tests.py create mode 100644 manage_notifications/urls.py create mode 100644 manage_notifications/views.py diff --git a/accounts/api/urls.py b/accounts/api/urls.py index 9ee6cec..9e18fe7 100644 --- a/accounts/api/urls.py +++ b/accounts/api/urls.py @@ -23,9 +23,6 @@ urlpatterns = [ path('profile/password-reset/', views.ProfilePasswordResetView.as_view(), name='password_reset'), # path('profile/kyc/', views.KycDocumentView.as_view(), name='pofile_kyc'), - path('referral-code//', views.ReferralCodeViews.as_view(), name='referral_code'), - path('referral-record//', views.ReferralRecordViews.as_view(), name='referral_record'), - path('google-login/', views.GoogleLoginAPIView.as_view(), name='google-login'), diff --git a/accounts/api/views.py b/accounts/api/views.py index 32c9164..4ff4d20 100644 --- a/accounts/api/views.py +++ b/accounts/api/views.py @@ -611,47 +611,6 @@ class ProfilePasswordResetView(APIView): # return ApiResponse.success(message=constants.SUCCESS) -class ReferralCodeViews(APIView): - authentication_classes = [JWTAuthentication] - permission_classes = [IsAuthenticated] - model = ReferralCode - serializer = ReferralCodeSerializer - - def get(self, request, *args, **kwargs): - referral_obj = self.model.filter_referral_code( - principal=request.user, principal_type=kwargs.get("principal_type") - ) - - serializer_obj = self.serializer(referral_obj, many=True) - - success_message = { - "status": status.HTTP_200_OK, - "message": constants.SUCCESS, - "data": serializer_obj.data, - } - return ApiResponse.success(**success_message) - - -class ReferralRecordViews(APIView): - authentication_classes = [JWTAuthentication] - permission_classes = [IsAuthenticated] - model = ReferralRecord - serializer = ReferralRecordSerializer - - def get(self, request, *args, **kwargs): - referral_obj = self.model.filter_invite_records( - referrer_principal=request.user, principal_type=kwargs.get("principal_type") - ) - - serializer_obj = self.serializer(referral_obj, many=True) - success_message = { - "status": status.HTTP_200_OK, - "message": constants.SUCCESS, - "data": {"count": referral_obj.count(), "record": serializer_obj.data}, - } - return ApiResponse.success(**success_message) - - class GoogleLoginAPIView(APIView): authentication_classes = [] permission_classes = [] diff --git a/accounts/migrations/0003_iamprincipal_player_id.py b/accounts/migrations/0003_iamprincipal_player_id.py new file mode 100644 index 0000000..48eb05a --- /dev/null +++ b/accounts/migrations/0003_iamprincipal_player_id.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.2 on 2024-03-11 11:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0002_iamprincipal_apple_id"), + ] + + operations = [ + migrations.AddField( + model_name="iamprincipal", + name="player_id", + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 57b4b04..2f3c5b2 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -254,6 +254,7 @@ class IAmPrincipal(AbstractUser): email_verified = models.BooleanField(default=False) referral_code = models.CharField(max_length=50, null=True, blank=True) apple_id = models.CharField(max_length=255, null=True, blank=True) + player_id = models.CharField(max_length=255, null=True, blank=True) referred_by = models.ForeignKey( "self", null=True, diff --git a/goodtimes/settings/base.py b/goodtimes/settings/base.py index 38e3888..af26e01 100644 --- a/goodtimes/settings/base.py +++ b/goodtimes/settings/base.py @@ -64,6 +64,7 @@ LOCAL_APPS = [ "manage_referrals", "manage_cms", "manage_communications", # for contact us, and feedback + "manage_notifications", "chat", ] diff --git a/goodtimes/urls.py b/goodtimes/urls.py index 50e16a9..be106e4 100644 --- a/goodtimes/urls.py +++ b/goodtimes/urls.py @@ -52,6 +52,8 @@ urlpatterns = [ path("subscriptions/", include("manage_subscriptions.urls")), path("api/subscriptions/", include("manage_subscriptions.api.urls")), + + path("notifications/", include("manage_notifications.urls")), # path('', include('manage_notifications.urls')), # path('api/', include("accounts.api.urls")), diff --git a/manage_notifications/__init__.py b/manage_notifications/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/manage_notifications/admin.py b/manage_notifications/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/manage_notifications/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/manage_notifications/apps.py b/manage_notifications/apps.py new file mode 100644 index 0000000..ca7245b --- /dev/null +++ b/manage_notifications/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ManageNotificationsConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "manage_notifications" diff --git a/manage_notifications/forms.py b/manage_notifications/forms.py new file mode 100644 index 0000000..e69de29 diff --git a/manage_notifications/migrations/__init__.py b/manage_notifications/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/manage_notifications/models.py b/manage_notifications/models.py new file mode 100644 index 0000000..ab60b18 --- /dev/null +++ b/manage_notifications/models.py @@ -0,0 +1,57 @@ +# from django.db import models +# from accounts.models import BaseModel, IAmPrincipal, IAmPrincipalType + + +# # Create your models here. +# class PushNotification(BaseModel): +# title = models.CharField(max_length=255) +# banner_image = models.ImageField( +# upload_to="push_notification_images/", blank=True, null=True +# ) +# principal_type = models.CharField(max_length=50) +# message = models.TextField() +# published_datetime = models.DateTimeField() + +# def __str__(self): +# return self.title + + +# class NotificationSettingsCategory(BaseModel): +# name = models.CharField(max_length=100) + +# class Meta: +# db_table = "notification_settings_category" + +# def __str__(self) -> str: +# return f"name : {self.name}" + + +# class NotificationSettings(BaseModel): +# name = models.CharField(max_length=100) +# category = models.ForeignKey( +# NotificationSettingsCategory, +# on_delete=models.CASCADE, +# related_name="notification_category", +# ) + +# class Meta: +# db_table = "notification_settings" + +# def __str__(self) -> str: +# return f"name: {self.name}" + + +# class IAmPrincipalNotificationSettings(BaseModel): +# principal = models.ForeignKey( +# IAmPrincipal, on_delete=models.CASCADE, related_name="notifications_principal" +# ) +# notification_setting = models.ForeignKey( +# NotificationSettings, on_delete=models.CASCADE +# ) +# is_enabled = models.BooleanField(default=True) + +# class Meta: +# db_table = "iam_principal_notification_settings" + +# def __str__(self): +# return f"{self.principal.first_name} - {self.notification_setting.name}" diff --git a/manage_notifications/tests.py b/manage_notifications/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/manage_notifications/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/manage_notifications/urls.py b/manage_notifications/urls.py new file mode 100644 index 0000000..0cef26b --- /dev/null +++ b/manage_notifications/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from . import views +from django.views.generic import TemplateView + + +app_name = 'manage_notifications' + +urlpatterns = [ + +] diff --git a/manage_notifications/views.py b/manage_notifications/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/manage_notifications/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/manage_referrals/api/urls.py b/manage_referrals/api/urls.py index 947609b..2811950 100644 --- a/manage_referrals/api/urls.py +++ b/manage_referrals/api/urls.py @@ -5,12 +5,12 @@ app_name = "manage_referrals_api" urlpatterns = [ path( - "referral-code//", + "referral-code/", views.ReferralCodeViews.as_view(), name="referral_code", ), path( - "referral-record//", + "referral-record/", views.ReferralRecordViews.as_view(), name="referral_record", ), diff --git a/manage_referrals/api/views.py b/manage_referrals/api/views.py index dc35a89..7d84dba 100644 --- a/manage_referrals/api/views.py +++ b/manage_referrals/api/views.py @@ -21,9 +21,7 @@ class ReferralCodeViews(APIView): serializer = ReferralCodeSerializer def get(self, request, *args, **kwargs): - referral_obj = self.model.filter_referral_code( - principal=request.user, principal_type=kwargs.get("principal_type") - ) + referral_obj = self.model.filter_referral_code(principal=request.user) serializer_obj = self.serializer(referral_obj, many=True) @@ -42,9 +40,7 @@ class ReferralRecordViews(APIView): serializer = ReferralRecordSerializer def get(self, request, *args, **kwargs): - referral_obj = self.model.filter_invite_records( - referrer_principal=request.user, principal_type=kwargs.get("principal_type") - ) + referral_obj = self.model.filter_invite_records(referrer_principal=request.user) serializer_obj = self.serializer(referral_obj, many=True) success_message = { diff --git a/manage_referrals/models.py b/manage_referrals/models.py index 1180741..c23c702 100644 --- a/manage_referrals/models.py +++ b/manage_referrals/models.py @@ -24,10 +24,8 @@ class ReferralCode(BaseModel): return f"{self.principal.first_name}" @classmethod - def filter_referral_code(cls, principal, principal_type): - return cls.objects.filter( - principal=principal, principal_type__name=principal_type - ) + def filter_referral_code(cls, principal): + return cls.objects.filter(principal=principal) @classmethod def generate_referral_code(cls, type, name):