referrals api
This commit is contained in:
@@ -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'),
|
||||
|
||||
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
18
accounts/migrations/0003_iamprincipal_player_id.py
Normal file
18
accounts/migrations/0003_iamprincipal_player_id.py
Normal 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),
|
||||
),
|
||||
]
|
||||
@@ -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,
|
||||
|
||||
@@ -64,6 +64,7 @@ LOCAL_APPS = [
|
||||
"manage_referrals",
|
||||
"manage_cms",
|
||||
"manage_communications", # for contact us, and feedback
|
||||
"manage_notifications",
|
||||
"chat",
|
||||
]
|
||||
|
||||
|
||||
@@ -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")),
|
||||
|
||||
0
manage_notifications/__init__.py
Normal file
0
manage_notifications/__init__.py
Normal file
3
manage_notifications/admin.py
Normal file
3
manage_notifications/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
manage_notifications/apps.py
Normal file
6
manage_notifications/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ManageNotificationsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "manage_notifications"
|
||||
0
manage_notifications/forms.py
Normal file
0
manage_notifications/forms.py
Normal file
0
manage_notifications/migrations/__init__.py
Normal file
0
manage_notifications/migrations/__init__.py
Normal file
57
manage_notifications/models.py
Normal file
57
manage_notifications/models.py
Normal 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}"
|
||||
3
manage_notifications/tests.py
Normal file
3
manage_notifications/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
10
manage_notifications/urls.py
Normal file
10
manage_notifications/urls.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
|
||||
app_name = 'manage_notifications'
|
||||
|
||||
urlpatterns = [
|
||||
|
||||
]
|
||||
3
manage_notifications/views.py
Normal file
3
manage_notifications/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
@@ -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",
|
||||
),
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user