├── tekki ├── __init__.py ├── __pycache__ │ ├── urls.cpython-37.pyc │ ├── wsgi.cpython-37.pyc │ ├── __init__.cpython-37.pyc │ └── settings.cpython-37.pyc ├── urls.py ├── asgi.py ├── wsgi.py └── settings.py ├── subscription ├── __init__.py ├── management │ ├── __init__.py │ ├── commands │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-37.pyc │ │ │ └── get_payment.cpython-37.pyc │ │ └── get_payment.py │ └── __pycache__ │ │ └── __init__.cpython-37.pyc ├── migrations │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-37.pyc │ │ └── 0001_initial.cpython-37.pyc │ └── 0001_initial.py ├── tests.py ├── apps.py ├── __pycache__ │ ├── admin.cpython-37.pyc │ ├── views.cpython-37.pyc │ ├── __init__.cpython-37.pyc │ ├── models.cpython-37.pyc │ └── serializer.cpython-37.pyc ├── admin.py ├── serializer.py ├── models.py └── views.py ├── db.sqlite3 ├── README.md ├── readme.md └── manage.py /tekki/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /subscription/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /subscription/management/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /subscription/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /subscription/management/commands/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/db.sqlite3 -------------------------------------------------------------------------------- /subscription/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /tekki/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/tekki/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /tekki/__pycache__/wsgi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/tekki/__pycache__/wsgi.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class SubscriptionConfig(AppConfig): 5 | name = 'subscription' 6 | -------------------------------------------------------------------------------- /tekki/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/tekki/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /tekki/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/tekki/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/__pycache__/admin.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/__pycache__/admin.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/__pycache__/views.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/__pycache__/views.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/__pycache__/serializer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/__pycache__/serializer.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import * 3 | 4 | admin.site.register(Plan) 5 | admin.site.register(UserSubscription) -------------------------------------------------------------------------------- /subscription/management/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/management/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/migrations/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/migrations/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/migrations/__pycache__/0001_initial.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/migrations/__pycache__/0001_initial.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/management/commands/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/management/commands/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/management/commands/__pycache__/get_payment.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hardeepsingh980/tekki/main/subscription/management/commands/__pycache__/get_payment.cpython-37.pyc -------------------------------------------------------------------------------- /subscription/serializer.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import UserSubscription 3 | 4 | class UserSubscriptionSerialiser(serializers.ModelSerializer): 5 | 6 | class Meta: 7 | model = UserSubscription 8 | fields = '__all__' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tekki 2 | 3 | 4 | Visit http://127.0.0.1:8000/subscription/ for getting all user subscription and adding new subscription. 5 | 6 | Visit http://127.0.0.1:8000/remove-subscription// to remove subscription. 7 | 8 | to get payment run command python manage.py get_payment 9 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # tekki 2 | 3 | 4 | Visit http://127.0.0.1:8000/subscription/ for getting all user subscription and adding new subscription. 5 | 6 | Visit http://127.0.0.1:8000/remove-subscription// to remove subscription. 7 | 8 | to get payment run command python manage.py get_payment 9 | -------------------------------------------------------------------------------- /tekki/urls.py: -------------------------------------------------------------------------------- 1 | 2 | from django.contrib import admin 3 | from django.urls import path, include 4 | 5 | from subscription.views import UserSubscriptionView, RemoveSubscriptionView 6 | 7 | urlpatterns = [ 8 | path('admin/', admin.site.urls), 9 | path('subscription/', UserSubscriptionView.as_view()), 10 | path('remove-subscription//', RemoveSubscriptionView.as_view()), 11 | ] 12 | -------------------------------------------------------------------------------- /tekki/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for tekki project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tekki.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /tekki/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for tekki project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tekki.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /subscription/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth import get_user_model 3 | 4 | User = get_user_model() 5 | 6 | 7 | 8 | class Plan(models.Model): 9 | title = models.CharField(max_length=100) 10 | price = models.IntegerField() 11 | 12 | def __str__(self): 13 | return self.title 14 | 15 | class UserSubscription(models.Model): 16 | user = models.ForeignKey(User, on_delete=models.CASCADE) 17 | plan = models.ForeignKey(Plan, on_delete=models.CASCADE) 18 | created_at = models.DateTimeField(auto_now_add=True) 19 | updated_at = models.DateTimeField(auto_now=True) 20 | 21 | def __str__(self): 22 | return f'{self.user} purchase {self.plan}' -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tekki.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /subscription/management/commands/get_payment.py: -------------------------------------------------------------------------------- 1 | from django.core.management.base import BaseCommand, CommandError 2 | from subscription.models import UserSubscription 3 | import datetime 4 | from django.utils import timezone 5 | 6 | 7 | 8 | 9 | class Command(BaseCommand): 10 | help = 'Get Payment' 11 | 12 | 13 | def handle(self, *args, **options): 14 | start_date = timezone.now() 15 | end_date = start_date + datetime.timedelta(days=0) 16 | 17 | userSubscriptions = UserSubscription.objects.filter(updated_at__range=(start_date, end_date)) 18 | 19 | for i in userSubscriptions: 20 | # Write Payment Logic 21 | self.stdout.write(self.style.SUCCESS(f'Payment Done For {i.user}')) 22 | 23 | self.stdout.write(self.style.SUCCESS('Successfully closed poll ')) -------------------------------------------------------------------------------- /subscription/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1 on 2021-02-23 06:30 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='Plan', 19 | fields=[ 20 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('title', models.CharField(max_length=100)), 22 | ('price', models.IntegerField()), 23 | ], 24 | ), 25 | migrations.CreateModel( 26 | name='UserSubscription', 27 | fields=[ 28 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 29 | ('created_at', models.DateTimeField(auto_now_add=True)), 30 | ('updated_at', models.DateTimeField(auto_now=True)), 31 | ('plan', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='subscription.plan')), 32 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 33 | ], 34 | ), 35 | ] 36 | -------------------------------------------------------------------------------- /subscription/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | from rest_framework import generics 4 | from rest_framework.response import Response 5 | from rest_framework import status 6 | 7 | 8 | from .models import UserSubscription 9 | from .serializer import UserSubscriptionSerialiser 10 | 11 | 12 | class UserSubscriptionView(generics.ListAPIView): 13 | queryset = UserSubscription.objects.all() 14 | serializer_class = UserSubscriptionSerialiser 15 | 16 | 17 | def post(self, request): 18 | serializer = UserSubscriptionSerialiser(data=request.data) 19 | if serializer.is_valid(): 20 | try: 21 | UserSubscription.objects.get(user=serializer.validated_data['user']) 22 | return Response({'error': 'user already subscribed'}, status=status.HTTP_400_BAD_REQUEST) 23 | except: 24 | serializer.save() 25 | return Response(serializer.data, status=status.HTTP_201_CREATED) 26 | return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) 27 | 28 | 29 | class RemoveSubscriptionView(generics.DestroyAPIView): 30 | queryset = UserSubscription.objects.all() 31 | serializer_class = UserSubscriptionSerialiser 32 | lookup_field = 'id' 33 | lookup_url_kwarg = 'id' 34 | 35 | 36 | def get(self, *args, **kwargs): 37 | try: 38 | queryset = UserSubscription.objects.get(id=self.kwargs['id']) 39 | serializer_class = UserSubscriptionSerialiser(queryset) 40 | return Response(serializer_class.data) 41 | except: 42 | return Response({'error':f'No data found with id: {self.kwargs["id"]}'}) 43 | 44 | -------------------------------------------------------------------------------- /tekki/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for tekki project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve(strict=True).parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'xzk6!#suav9i)2amz_y0rq*+p3_^hd&pv6t!rban$hq)7y%y2d' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 41 | 'rest_framework', 42 | 43 | 'subscription', 44 | 45 | ] 46 | 47 | MIDDLEWARE = [ 48 | 'django.middleware.security.SecurityMiddleware', 49 | 'django.contrib.sessions.middleware.SessionMiddleware', 50 | 'django.middleware.common.CommonMiddleware', 51 | 'django.middleware.csrf.CsrfViewMiddleware', 52 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 53 | 'django.contrib.messages.middleware.MessageMiddleware', 54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 55 | ] 56 | 57 | ROOT_URLCONF = 'tekki.urls' 58 | 59 | TEMPLATES = [ 60 | { 61 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 62 | 'DIRS': [], 63 | 'APP_DIRS': True, 64 | 'OPTIONS': { 65 | 'context_processors': [ 66 | 'django.template.context_processors.debug', 67 | 'django.template.context_processors.request', 68 | 'django.contrib.auth.context_processors.auth', 69 | 'django.contrib.messages.context_processors.messages', 70 | ], 71 | }, 72 | }, 73 | ] 74 | 75 | WSGI_APPLICATION = 'tekki.wsgi.application' 76 | 77 | 78 | 79 | 80 | # Database 81 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 82 | 83 | DATABASES = { 84 | 'default': { 85 | 'ENGINE': 'django.db.backends.sqlite3', 86 | 'NAME': BASE_DIR / 'db.sqlite3', 87 | } 88 | } 89 | 90 | 91 | # Password validation 92 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 93 | 94 | AUTH_PASSWORD_VALIDATORS = [ 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 100 | }, 101 | { 102 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 103 | }, 104 | { 105 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 106 | }, 107 | ] 108 | 109 | 110 | # Internationalization 111 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 112 | 113 | LANGUAGE_CODE = 'en-us' 114 | 115 | TIME_ZONE = 'UTC' 116 | 117 | USE_I18N = True 118 | 119 | USE_L10N = True 120 | 121 | USE_TZ = True 122 | 123 | 124 | # Static files (CSS, JavaScript, Images) 125 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 126 | 127 | STATIC_URL = '/static/' 128 | --------------------------------------------------------------------------------