From 3a2177431ccdb998fe8314a64327a96291ce03ce Mon Sep 17 00:00:00 2001 From: Joel Wembo Date: Mon, 23 Oct 2023 01:47:58 +0800 Subject: [PATCH] removed notes api app --- apps/node_api/__init__.py | 0 apps/node_api/admin.py | 13 --- apps/node_api/apps.py | 6 - apps/node_api/migrations/0001_initial.py | 36 ------ .../migrations/0002_subscribetonewsletter.py | 27 ----- .../0003_category_retail_product.py | 82 ------------- apps/node_api/migrations/0004_users.py | 34 ------ apps/node_api/migrations/__init__.py | 0 apps/node_api/models.py | 77 ------------ apps/node_api/serializers.py | 14 --- apps/node_api/tasks.py | 38 ------ apps/node_api/tests.py | 5 - apps/node_api/urls.py | 12 -- apps/node_api/views.py | 110 ------------------ 14 files changed, 454 deletions(-) delete mode 100644 apps/node_api/__init__.py delete mode 100644 apps/node_api/admin.py delete mode 100644 apps/node_api/apps.py delete mode 100644 apps/node_api/migrations/0001_initial.py delete mode 100644 apps/node_api/migrations/0002_subscribetonewsletter.py delete mode 100644 apps/node_api/migrations/0003_category_retail_product.py delete mode 100644 apps/node_api/migrations/0004_users.py delete mode 100644 apps/node_api/migrations/__init__.py delete mode 100644 apps/node_api/models.py delete mode 100644 apps/node_api/serializers.py delete mode 100644 apps/node_api/tasks.py delete mode 100644 apps/node_api/tests.py delete mode 100644 apps/node_api/urls.py delete mode 100644 apps/node_api/views.py diff --git a/apps/node_api/__init__.py b/apps/node_api/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/node_api/admin.py b/apps/node_api/admin.py deleted file mode 100644 index d820955..0000000 --- a/apps/node_api/admin.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.contrib import admin - -# Register your models here. -from .models import NoteModel , SubscribeToNewsletter , Retail, Category, Product -from .models import Users -admin.site.register(NoteModel) -admin.site.register(SubscribeToNewsletter) -admin.site.register(Retail) -admin.site.register(Category) -admin.site.register(Product) - -admin.site.register(Users) -# admin.site.register(BankAccounts) \ No newline at end of file diff --git a/apps/node_api/apps.py b/apps/node_api/apps.py deleted file mode 100644 index 94515f8..0000000 --- a/apps/node_api/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class NodeApiConfig(AppConfig): - default_auto_field = "django.db.models.BigAutoField" - name = "apps.node_api" diff --git a/apps/node_api/migrations/0001_initial.py b/apps/node_api/migrations/0001_initial.py deleted file mode 100644 index 6f2a72b..0000000 --- a/apps/node_api/migrations/0001_initial.py +++ /dev/null @@ -1,36 +0,0 @@ -# Generated by Django 4.2.2 on 2023-07-28 23:28 - -from django.db import migrations, models -import uuid - - -class Migration(migrations.Migration): - initial = True - - dependencies = [] - - operations = [ - migrations.CreateModel( - name="NoteModel", - fields=[ - ( - "id", - models.UUIDField( - default=uuid.uuid4, - editable=False, - primary_key=True, - serialize=False, - ), - ), - ("title", models.CharField(max_length=255, unique=True)), - ("content", models.TextField()), - ("category", models.CharField(blank=True, max_length=100, null=True)), - ("createdAt", models.DateTimeField(auto_now_add=True)), - ("updatedAt", models.DateTimeField(auto_now_add=True)), - ], - options={ - "db_table": "notes", - "ordering": ["-createdAt"], - }, - ), - ] diff --git a/apps/node_api/migrations/0002_subscribetonewsletter.py b/apps/node_api/migrations/0002_subscribetonewsletter.py deleted file mode 100644 index 36d5c94..0000000 --- a/apps/node_api/migrations/0002_subscribetonewsletter.py +++ /dev/null @@ -1,27 +0,0 @@ -# Generated by Django 4.2.4 on 2023-08-18 14:12 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("node_api", "0001_initial"), - ] - - operations = [ - migrations.CreateModel( - name="SubscribeToNewsletter", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("email", models.EmailField(max_length=254, unique=True)), - ], - ), - ] diff --git a/apps/node_api/migrations/0003_category_retail_product.py b/apps/node_api/migrations/0003_category_retail_product.py deleted file mode 100644 index 2ee0316..0000000 --- a/apps/node_api/migrations/0003_category_retail_product.py +++ /dev/null @@ -1,82 +0,0 @@ -# Generated by Django 4.2.4 on 2023-08-23 22:09 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - dependencies = [ - ("node_api", "0002_subscribetonewsletter"), - ] - - operations = [ - migrations.CreateModel( - name="Category", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=128, unique=True)), - ], - ), - migrations.CreateModel( - name="Retail", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=128)), - ], - ), - migrations.CreateModel( - name="Product", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("sku", models.CharField(max_length=50, unique=True)), - ("name", models.CharField(max_length=50)), - ("description", models.TextField(blank=True, default="")), - ("mrp", models.DecimalField(decimal_places=2, max_digits=10)), - ("weight", models.DecimalField(decimal_places=2, max_digits=10)), - ("date_created", models.DateTimeField(auto_now_add=True)), - ("date_modified", models.DateTimeField(auto_now=True)), - ( - "category", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - related_name="products", - to="node_api.category", - ), - ), - ( - "retails", - models.ManyToManyField( - related_name="products", - to="node_api.retail", - verbose_name="Retail stores that carry the product", - ), - ), - ], - ), - ] diff --git a/apps/node_api/migrations/0004_users.py b/apps/node_api/migrations/0004_users.py deleted file mode 100644 index 721ed5b..0000000 --- a/apps/node_api/migrations/0004_users.py +++ /dev/null @@ -1,34 +0,0 @@ -# Generated by Django 4.2.4 on 2023-08-29 22:56 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - ("node_api", "0003_category_retail_product"), - ] - - operations = [ - migrations.CreateModel( - name="Users", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("name", models.CharField(max_length=255)), - ("bank_name", models.CharField(max_length=255)), - ("branch_name", models.CharField(max_length=255)), - ("ifsc_code", models.CharField(max_length=255)), - ("account_number", models.CharField(max_length=255)), - ], - options={ - "db_table": "users", - }, - ), - ] diff --git a/apps/node_api/migrations/__init__.py b/apps/node_api/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/apps/node_api/models.py b/apps/node_api/models.py deleted file mode 100644 index fe4736c..0000000 --- a/apps/node_api/models.py +++ /dev/null @@ -1,77 +0,0 @@ -import uuid -from django.db import models - - -class NoteModel(models.Model): - id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - title = models.CharField(max_length=255, unique=True) - content = models.TextField() - category = models.CharField(max_length=100, null=True, blank=True) - createdAt = models.DateTimeField(auto_now_add=True) - updatedAt = models.DateTimeField(auto_now_add=True) - - class Meta: - db_table = "notes" - ordering = ['-createdAt'] - - def __str__(self) -> str: - return self.title - - -class SubscribeToNewsletter(models.Model): - email = models.EmailField(unique=True) - def __str__(self): - return self.email - - -# Models for pytest - -class Retail(models.Model): - name = models.CharField(max_length=128) - -class Category(models.Model): - name = models.CharField(max_length=128, unique=True) - -class Product(models.Model): - sku = models.CharField(max_length=50, unique=True) # unique model number - name = models.CharField(max_length=50) - description = models.TextField(default="", blank=True) - mrp = models.DecimalField(max_digits=10, decimal_places=2) - weight = models.DecimalField(max_digits=10, decimal_places=2) - retails = models.ManyToManyField( - Retail, - related_name="products", - verbose_name="Retail stores that carry the product", - ) - category = models.ForeignKey( - Category, - related_name="products", - on_delete=models.CASCADE, - blank=True, - null=True, - ) - date_created = models.DateTimeField(auto_now_add=True) - date_modified = models.DateTimeField(auto_now=True) - -# Example for Custom migration - -class Users(models.Model): - name = models.CharField(max_length=255) - bank_name = models.CharField(max_length=255) - branch_name = models.CharField(max_length=255) - ifsc_code = models.CharField(max_length=255) - account_number = models.CharField(max_length=255) - - class Meta: - db_table = 'users' - - -# class BankAccounts(models.Model): -# class Meta: -# db_table = 'bank_accounts' - -# bank_name = models.CharField(max_length=255) -# branch_name = models.CharField(max_length=255) -# ifsc_code = models.CharField(max_length=255) -# account_number = models.CharField(max_length=255) -# user = models.ForeignKey(Users, on_delete=models.CASCADE) \ No newline at end of file diff --git a/apps/node_api/serializers.py b/apps/node_api/serializers.py deleted file mode 100644 index 9c63df3..0000000 --- a/apps/node_api/serializers.py +++ /dev/null @@ -1,14 +0,0 @@ -from rest_framework import serializers -from .models import NoteModel, SubscribeToNewsletter - - -class NoteSerializer(serializers.ModelSerializer): - class Meta: - model = NoteModel - fields = '__all__' - -class SubscribeSerializer(serializers.ModelSerializer): - - class Meta: - models = SubscribeToNewsletter - fields = ('email',) diff --git a/apps/node_api/tasks.py b/apps/node_api/tasks.py deleted file mode 100644 index 827e7e6..0000000 --- a/apps/node_api/tasks.py +++ /dev/null @@ -1,38 +0,0 @@ -from celery import shared_task -from django.core.mail import EmailMessage -from celery.utils.log import get_task_logger -from fintechengine.celery import app -from .models import SubscribeToNewsletter - - -logger = get_task_logger(__name__) - -# @app.task -# def send_reminder(): -# # this will be used to send mail to all subscribed users -# all_users = SubscribeToNewsletter.objects.all() -# for user in all_users: -# logger.info("Reminder message sent") -# email = EmailMessage( -# subject= 'Reset your password', -# body= 'Hi, thank you for subscribing to our', -# to=[user.email] -# ) -# email.send(fail_silently=True) -# return {'status': 'sent successfully'} - - -@shared_task(bind=True) -def test_func(self): - #operations - for i in range(10): - print("Test App Loading " , i) - return "Done" - - -@shared_task(bind=True) -def run_func(self): - #operations - for i in range(10): - print("Test App Processing" , i) - return "Done" \ No newline at end of file diff --git a/apps/node_api/tests.py b/apps/node_api/tests.py deleted file mode 100644 index 28cc8bc..0000000 --- a/apps/node_api/tests.py +++ /dev/null @@ -1,5 +0,0 @@ -import django -django.setup() - -def test_foo(): - assert True \ No newline at end of file diff --git a/apps/node_api/urls.py b/apps/node_api/urls.py deleted file mode 100644 index 6ed34ff..0000000 --- a/apps/node_api/urls.py +++ /dev/null @@ -1,12 +0,0 @@ -from django.urls import path -from .views import Notes, NoteDetail , SubscribeView -from . import views -urlpatterns = [ - path('apiview', Notes.as_view()), - path('', Notes.as_view()), - path('', NoteDetail.as_view()), - path('test', views.test, name="test"), - path('run-test', views.test_second_function, name="test_second_function"), - path("subscribe", SubscribeView.as_view(), name="subscribe-newsletter") -] - diff --git a/apps/node_api/views.py b/apps/node_api/views.py deleted file mode 100644 index 3b16dc6..0000000 --- a/apps/node_api/views.py +++ /dev/null @@ -1,110 +0,0 @@ -from django.http import HttpResponse -from rest_framework.response import Response -from rest_framework import status, generics -from .models import NoteModel , SubscribeToNewsletter -from .serializers import NoteSerializer , SubscribeSerializer -import math -from datetime import datetime -from rest_framework import viewsets -from django.shortcuts import get_object_or_404 -from .tasks import test_func, run_func - - -class Notes(generics.GenericAPIView): - serializer_class = NoteSerializer - queryset = NoteModel.objects.all() - - def get(self, request): - page_num = int(request.GET.get("page", 1)) - limit_num = int(request.GET.get("limit", 10)) - start_num = (page_num - 1) * limit_num - end_num = limit_num * page_num - search_param = request.GET.get("search") - notes = NoteModel.objects.all() - total_notes = notes.count() - if search_param: - notes = notes.filter(title__icontains=search_param) - serializer = self.serializer_class(notes[start_num:end_num], many=True) - return Response({ - "status": "success", - "total": total_notes, - "page": page_num, - "last_page": math.ceil(total_notes / limit_num), - "notes": serializer.data - }) - - def post(self, request): - serializer = self.serializer_class(data=request.data) - if serializer.is_valid(): - serializer.save() - return Response({"status": "success", "data": {"note": serializer.data}}, status=status.HTTP_201_CREATED) - else: - return Response({"status": "fail", "message": serializer.errors}, status=status.HTTP_400_BAD_REQUEST) - - -class NoteDetail(generics.GenericAPIView): - queryset = NoteModel.objects.all() - serializer_class = NoteSerializer - - def get_note(self, pk): - try: - return NoteModel.objects.get(pk=pk) - except: - return None - - def get(self, request, pk): - note = self.get_note(pk=pk) - if note == None: - return Response({"status": "fail", "message": f"Note with Id: {pk} not found"}, status=status.HTTP_404_NOT_FOUND) - - serializer = self.serializer_class(note) - return Response({"status": "success", "data": {"note": serializer.data}}) - - def patch(self, request, pk): - note = self.get_note(pk) - if note == None: - return Response({"status": "fail", "message": f"Note with Id: {pk} not found"}, status=status.HTTP_404_NOT_FOUND) - - serializer = self.serializer_class( - note, data=request.data, partial=True) - if serializer.is_valid(): - serializer.validated_data['updatedAt'] = datetime.now() - serializer.save() - return Response({"status": "success", "data": {"note": serializer.data}}) - return Response({"status": "fail", "message": serializer.errors}, status=status.HTTP_400_BAD_REQUEST) - - def delete(self, request, pk): - note = self.get_note(pk) - if note == None: - return Response({"status": "fail", "message": f"Note with Id: {pk} not found"}, status=status.HTTP_404_NOT_FOUND) - - note.delete() - return Response(status=status.HTTP_204_NO_CONTENT) - -class NoteViewSet(viewsets.ViewSet): - """ - A simple ViewSet for listing or retrieving notes. - """ - def list(self, request): - queryset = NoteModel.objects.all() - serializer = NoteSerializer(queryset, many=True) - return Response(serializer.data) - - def retrieve(self, request, pk=None): - queryset = NoteModel.objects.all() - notes = get_object_or_404(queryset, pk=pk) - serializer = NoteSerializer(notes) - return Response(serializer.data) - -def test(request): - test_func.delay() - return HttpResponse("Done") - -def test_second_function(request): - run_func.delay() - return HttpResponse("Done") - - -class SubscribeView(generics.ListCreateAPIView): - queryset = SubscribeToNewsletter.objects.all() - serializer_class = SubscribeSerializer \ No newline at end of file