diff --git a/core/api/coupon.py b/core/api/coupon.py new file mode 100644 index 0000000000000000000000000000000000000000..6e68e91a47b83ce658d5dcd5dcaf6e571695847f --- /dev/null +++ b/core/api/coupon.py @@ -0,0 +1,11 @@ +from rest_framework import viewsets +from rest_framework.permissions import IsAuthenticated + +from core.serializers.coupon import CouponSerializer +from core.models.coupon import Coupon + + +class CouponViewSet(viewsets.ReadOnlyModelViewSet): + permission_classes = (IsAuthenticated,) + serializer_class = CouponSerializer + queryset = Coupon.objects.all() diff --git a/core/models/coupon.py b/core/models/coupon.py new file mode 100644 index 0000000000000000000000000000000000000000..9982c5ef2c2bbc6f6f8e0774a6a4e284eba9ec81 --- /dev/null +++ b/core/models/coupon.py @@ -0,0 +1,25 @@ +from django.db import models + +from .coupon_category import CouponCategory +from .utils import UUIDModel + + +class Coupon (UUIDModel): + store = models.CharField(max_length=100) + merchant_homepage = models.URLField(max_length=200) + offer_text = models.CharField(max_length=100) + offer_value = models.CharField(max_length=100) + title = models.CharField(max_length=200, default='') + description = models.TextField(default='') + code = models.CharField(max_length=50) + smart_link = models.URLField(max_length=200) + image_url = models.URLField(max_length=200) + type = models.CharField(max_length=50) + status = models.CharField(max_length=50) + start_date = models.DateField('coupon valid date') + expire_date = models.DateField('coupon expired date') + categories = models.ManyToManyField(to=CouponCategory) + + def __str__(self) -> str: + return self.coupon_text[:12] + '...' + diff --git a/core/models/coupon_category.py b/core/models/coupon_category.py new file mode 100644 index 0000000000000000000000000000000000000000..ce6c37b06ee722c67ce99344226ea612f8176124 --- /dev/null +++ b/core/models/coupon_category.py @@ -0,0 +1,11 @@ +from django.db import models + +from .utils import UUIDModel + + +class CouponCategory(UUIDModel): + category = models.CharField(max_length=50) + sub_category = models.CharField(max_length=50) + + def __str__(self) -> str: + return f'<CouponCategory: {self.category}-{self.sub_category}>' diff --git a/core/serializers/coupon.py b/core/serializers/coupon.py new file mode 100644 index 0000000000000000000000000000000000000000..be88d3797eff077e55730a9b2c30a4ac7691155c --- /dev/null +++ b/core/serializers/coupon.py @@ -0,0 +1,10 @@ +from rest_framework import serializers + +from core.models.coupon import Coupon + + +class CouponSerializer(serializers.ModelSerializer): + class Meta: + model = Coupon + fields = ('__all__', ) + depth = 1 diff --git a/core/urls.py b/core/urls.py index 02cc9486ed5f4e83551073e5891ca159b8047d8c..7a014bcf1191a337597f90cb50f70443cfe0fdc4 100644 --- a/core/urls.py +++ b/core/urls.py @@ -5,6 +5,7 @@ from rest_framework import routers from core.api.auth import RegisterAPI, LoginAPI, AppleLogin, GoogleLogin, FacebookLogin, validate_token, verify_user_and_activate from core.api.password import ChangePasswordView from core.api.profile import ProfileViewSet +from core.api.coupon import CouponViewSet router = routers.DefaultRouter() @@ -24,5 +25,7 @@ urlpatterns += [ path('api/change-password', ChangePasswordView.as_view(), name='change-password'), path('api/password_reset/', include('django_rest_passwordreset.urls', namespace='password_reset')), # profile - path('api/profile', ProfileViewSet.as_view(), name='profile') + path('api/profile', ProfileViewSet.as_view(), name='profile'), + # coupon + path('api/coupon', CouponViewSet.as_view(), name='coupon'), ]