diff --git a/api/dashboard/coupon/coupon_view.py b/api/dashboard/coupon/coupon_view.py index 434566f7..f75ac9ac 100644 --- a/api/dashboard/coupon/coupon_view.py +++ b/api/dashboard/coupon/coupon_view.py @@ -1,12 +1,18 @@ 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() + diff --git a/api/dashboard/coupon/urls.py b/api/dashboard/coupon/urls.py index 59c345a5..907503b4 100644 --- a/api/dashboard/coupon/urls.py +++ b/api/dashboard/coupon/urls.py @@ -5,3 +5,7 @@ urlpatterns = [ path('verify-coupon/', coupon_view.CouponApi.as_view(), name='verify-coupon'), ] + + + + diff --git a/api/dashboard/urls.py b/api/dashboard/urls.py index 5d5702f5..91d3b94d 100644 --- a/api/dashboard/urls.py +++ b/api/dashboard/urls.py @@ -18,10 +18,12 @@ path('organisation/', include('api.dashboard.organisation.urls')), path('dynamic-management/', include('api.dashboard.dynamic_management.urls')), path('error-log/', include('api.dashboard.error_log.urls')), + 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('coupon/', include('api.dashboard.coupon.urls')), ] diff --git a/db/user.py b/db/user.py index 52bc70d3..24ab129b 100644 --- a/db/user.py +++ b/db/user.py @@ -208,6 +208,9 @@ class Meta: 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') @@ -219,4 +222,8 @@ class UserCouponLink(models.Model): class Meta: managed = False + db_table = 'user_coupon_link' + + +