From 2cf418a3528ea5582dedf599ae3070ba756c4500 Mon Sep 17 00:00:00 2001 From: DotworldX Date: Sun, 30 Mar 2025 21:44:22 +0100 Subject: [PATCH 1/2] chore: initial setup of trajectfi backend application ## Description ## Related Issue Fixes #[Issue Number] ## Type of Change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Performance improvement - [ ] Code refactoring - [ ] Documentation update - [ ] Test coverage improvement - [ ] CI/CD related changes ## How Has This Been Tested? - [ ] Unit tests - [ ] Integration tests - [ ] Manual testing ## Python Dependencies ``` # New dependencies: # example_package==1.0.0 ``` ## Starknet-Specific Considerations ## Checklist - [ ] My code follows the project's style guidelines - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules ## Security Considerations - [ ] This PR introduces no security concerns - [ ] This PR modifies authentication/authorization - [ ] This PR handles sensitive data - [ ] This PR modifies financial transaction logic ## Performance Impact - [ ] This PR has no significant performance impact - [ ] This PR improves performance - [ ] This PR may impact performance negatively (explain why it's necessary) ## Additional Context --- trajectfi/asgi.py | 3 ++- trajectfi/settings.py | 6 ++++++ trajectfi/urls.py | 27 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/trajectfi/asgi.py b/trajectfi/asgi.py index 61da327..d4fb655 100644 --- a/trajectfi/asgi.py +++ b/trajectfi/asgi.py @@ -6,11 +6,12 @@ For more information on this file, see https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ """ - +import sys import os from django.core.asgi import get_asgi_application +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "trajectfi.settings") application = get_asgi_application() diff --git a/trajectfi/settings.py b/trajectfi/settings.py index e6e5c58..b767f30 100644 --- a/trajectfi/settings.py +++ b/trajectfi/settings.py @@ -13,6 +13,7 @@ import os from pathlib import Path + import dj_database_url # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -161,3 +162,8 @@ # Custom settings AUTH_USER_MODEL = "core.User" + +INSTALLED_APPS = [ + 'core.tests', # Register the models path + 'rest_framework', +] \ No newline at end of file diff --git a/trajectfi/urls.py b/trajectfi/urls.py index 95cae23..ddddc45 100644 --- a/trajectfi/urls.py +++ b/trajectfi/urls.py @@ -17,6 +17,33 @@ from django.contrib import admin from django.urls import include, path +from django.db.models import Count +from rest_framework import serializers, generics +from rest_framework.response import Response +from rest_framework.views import APIView +from django.urls import path +from core.tests.models import AcceptedToken, Listing # type: ignore + +# Serializer +class AcceptedTokenSerializer(serializers.ModelSerializer): + listing_count = serializers.SerializerMethodField() + + class Meta: + model = AcceptedToken + fields = ['contract_address', 'name', 'listing_count'] + + def get_listing_count(self, obj): + return obj.listing_count + +# View +class AcceptedTokenListView(generics.ListAPIView): + queryset = AcceptedToken.objects.annotate(listing_count=Count('listing')) + serializer_class = AcceptedTokenSerializer + +# URL Configuration +urlpatterns = [ + path('api/accepted-tokens/', AcceptedTokenListView.as_view(), name='accepted-token-list'), +] urlpatterns = [ path("admin/", admin.site.urls), From 5acfb03d4f893f77640d1be735fb392145c8bc49 Mon Sep 17 00:00:00 2001 From: DotworldX Date: Mon, 31 Mar 2025 00:33:03 +0100 Subject: [PATCH 2/2] Create API Endpoint to Retrieve All Accepted Tokens with Listing Count Fixes #9 --- trajectfi/asgi.py | 3 ++- trajectfi/settings.py | 6 +++--- trajectfi/urls.py | 15 +++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/trajectfi/asgi.py b/trajectfi/asgi.py index d4fb655..9cf77f7 100644 --- a/trajectfi/asgi.py +++ b/trajectfi/asgi.py @@ -6,12 +6,13 @@ For more information on this file, see https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ """ + import sys import os from django.core.asgi import get_asgi_application -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) os.environ.setdefault("DJANGO_SETTINGS_MODULE", "trajectfi.settings") application = get_asgi_application() diff --git a/trajectfi/settings.py b/trajectfi/settings.py index b767f30..4446818 100644 --- a/trajectfi/settings.py +++ b/trajectfi/settings.py @@ -164,6 +164,6 @@ AUTH_USER_MODEL = "core.User" INSTALLED_APPS = [ - 'core.tests', # Register the models path - 'rest_framework', -] \ No newline at end of file + "core.tests", # Register the models path + "rest_framework", +] diff --git a/trajectfi/urls.py b/trajectfi/urls.py index ddddc45..bbddb17 100644 --- a/trajectfi/urls.py +++ b/trajectfi/urls.py @@ -22,7 +22,8 @@ from rest_framework.response import Response from rest_framework.views import APIView from django.urls import path -from core.tests.models import AcceptedToken, Listing # type: ignore +from core.tests.models import AcceptedToken, Listing # type: ignore + # Serializer class AcceptedTokenSerializer(serializers.ModelSerializer): @@ -30,19 +31,25 @@ class AcceptedTokenSerializer(serializers.ModelSerializer): class Meta: model = AcceptedToken - fields = ['contract_address', 'name', 'listing_count'] + fields = ["contract_address", "name", "listing_count"] def get_listing_count(self, obj): return obj.listing_count + # View class AcceptedTokenListView(generics.ListAPIView): - queryset = AcceptedToken.objects.annotate(listing_count=Count('listing')) + queryset = AcceptedToken.objects.annotate(listing_count=Count("listing")) serializer_class = AcceptedTokenSerializer + # URL Configuration urlpatterns = [ - path('api/accepted-tokens/', AcceptedTokenListView.as_view(), name='accepted-token-list'), + path( + "api/accepted-tokens/", + AcceptedTokenListView.as_view(), + name="accepted-token-list", + ), ] urlpatterns = [