From 1cbe9b47d2a8767e79e69993c3cad0416c97cc04 Mon Sep 17 00:00:00 2001 From: Shaheen Hyder K Date: Thu, 15 Feb 2024 04:10:13 +0530 Subject: [PATCH 1/2] added coupon verify --- api/dashboard/coupon/coupon_view.py | 12 ++++++++++++ api/dashboard/coupon/urls.py | 7 +++++++ api/dashboard/urls.py | 3 ++- db/user.py | 13 +++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 api/dashboard/coupon/coupon_view.py create mode 100644 api/dashboard/coupon/urls.py diff --git a/api/dashboard/coupon/coupon_view.py b/api/dashboard/coupon/coupon_view.py new file mode 100644 index 00000000..b597d2d5 --- /dev/null +++ b/api/dashboard/coupon/coupon_view.py @@ -0,0 +1,12 @@ +from rest_framework.views import APIView +from utils.response import CustomResponse +from db.user import UserCouponLink + + +class CouponApi(APIView): + def post(self, request): + if coupon_code := request.data.get('data'): + if UserCouponLink.objects.filter(coupon=coupon_code).exists(): + return CustomResponse(general_message="Coupon is valid").get_success_response() + return CustomResponse(general_message="Coupon is invalid").get_failure_response() + return CustomResponse(general_message="Coupon code is required").get_failure_response() \ No newline at end of file diff --git a/api/dashboard/coupon/urls.py b/api/dashboard/coupon/urls.py new file mode 100644 index 00000000..a5ae7ba0 --- /dev/null +++ b/api/dashboard/coupon/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import coupon_view + +urlpatterns = [ + path('verify-coupon/', coupon_view.CouponApi.as_view(), name='verify-coupon'), +] \ No newline at end of file diff --git a/api/dashboard/urls.py b/api/dashboard/urls.py index 797c97a2..7343ab2e 100644 --- a/api/dashboard/urls.py +++ b/api/dashboard/urls.py @@ -21,6 +21,7 @@ path('affiliation/',include('api.dashboard.affiliation.urls')), path('channels/',include('api.dashboard.channels.urls')), path('discord-moderator/',include('api.dashboard.discord_moderator.urls')), - path('events/',include('api.dashboard.events.urls')) + path('events/',include('api.dashboard.events.urls')), + path('coupon/', include('api.dashboard.coupon.urls')), ] diff --git a/db/user.py b/db/user.py index d6152e15..890e6f5f 100644 --- a/db/user.py +++ b/db/user.py @@ -203,3 +203,16 @@ class DynamicUser(models.Model): class Meta: managed = False db_table = 'dynamic_user' + +class UserCouponLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', on_delete=models.CASCADE, related_name='usercouponlink_user') + coupon = models.CharField(max_length=15) + type = models.CharField(max_length=36) + created_by = models.ForeignKey('User', on_delete=models.SET(settings.SYSTEM_ADMIN_ID), db_column='created_by', + related_name='usercouponlink_created_by_set') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_coupon_link' \ No newline at end of file From 00058c6b1a60cfc5e4e6eb5318d8dbe6335de2ee Mon Sep 17 00:00:00 2001 From: Shaheen Hyder K Date: Thu, 15 Feb 2024 04:18:47 +0530 Subject: [PATCH 2/2] change coupon verify response --- api/dashboard/coupon/coupon_view.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/dashboard/coupon/coupon_view.py b/api/dashboard/coupon/coupon_view.py index b597d2d5..764fecb4 100644 --- a/api/dashboard/coupon/coupon_view.py +++ b/api/dashboard/coupon/coupon_view.py @@ -1,12 +1,13 @@ from rest_framework.views import APIView from utils.response import CustomResponse from db.user import UserCouponLink +from rest_framework.response import Response class CouponApi(APIView): def post(self, request): if coupon_code := request.data.get('data'): if UserCouponLink.objects.filter(coupon=coupon_code).exists(): - return CustomResponse(general_message="Coupon is valid").get_success_response() - return CustomResponse(general_message="Coupon is invalid").get_failure_response() - return CustomResponse(general_message="Coupon code is required").get_failure_response() \ No newline at end of file + return Response(data={"discount_type": "Percentage", "discount_value": 100}) + return Response(data={"discount_type": "Percentage", "discount_value": 0}) + return Response(data={"discount_type": "Percentage", "discount_value": 0})