referrals api

This commit is contained in:
rizwanisready
2024-03-11 17:23:01 +05:30
parent 30eb42baca
commit f2e65c2950
18 changed files with 110 additions and 56 deletions

View File

@@ -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/<str:principal_type>/', views.ReferralCodeViews.as_view(), name='referral_code'),
path('referral-record/<str:principal_type>/', views.ReferralRecordViews.as_view(), name='referral_record'),
path('google-login/', views.GoogleLoginAPIView.as_view(), name='google-login'),

View File

@@ -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 = []

View File

@@ -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),
),
]

View File

@@ -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,

View File

@@ -64,6 +64,7 @@ LOCAL_APPS = [
"manage_referrals",
"manage_cms",
"manage_communications", # for contact us, and feedback
"manage_notifications",
"chat",
]

View File

@@ -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")),

View File

View File

@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ManageNotificationsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "manage_notifications"

View File

View File

@@ -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}"

View File

@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -0,0 +1,10 @@
from django.urls import path
from . import views
from django.views.generic import TemplateView
app_name = 'manage_notifications'
urlpatterns = [
]

View File

@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@@ -5,12 +5,12 @@ app_name = "manage_referrals_api"
urlpatterns = [
path(
"referral-code/<str:principal_type>/",
"referral-code/",
views.ReferralCodeViews.as_view(),
name="referral_code",
),
path(
"referral-record/<str:principal_type>/",
"referral-record/",
views.ReferralRecordViews.as_view(),
name="referral_record",
),

View File

@@ -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 = {

View File

@@ -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):