-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Build-Squad/GEN-65-List-APIs-Core-Modals
Add core URLs and views for Country and Currency
- Loading branch information
Showing
22 changed files
with
1,847 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.urls import path | ||
from .views import CountryListView, CountryDetailView, CurrencyListView, CurrencyDetailView | ||
|
||
urlpatterns = [ | ||
path('country/', CountryListView.as_view()), | ||
path('country/<str:pk>/', CountryDetailView.as_view()), | ||
|
||
path('currency/', CurrencyListView.as_view()), | ||
path('currency/<str:pk>/', CurrencyDetailView.as_view()), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,87 @@ | ||
from django.shortcuts import render | ||
from marketplace.services import Pagination, handleServerException, handleNotFound | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from rest_framework.views import APIView | ||
from .models import Country, Currency | ||
from django.db.models import Q | ||
from .serializers import CountrySerializer, CurrencySerializer | ||
|
||
# Create your views here. | ||
|
||
class CountryListView(APIView): | ||
def get(self, request, format=None): | ||
try: | ||
search = request.GET.get('search', None) | ||
order_by = request.GET.get('order_by', None) | ||
if search: | ||
countries = Country.objects.filter( | ||
Q(name__icontains=search) | Q(country_code__icontains=search)) | ||
else: | ||
countries = Country.objects.all() | ||
if order_by: | ||
countries = countries.order_by(order_by) | ||
pagination = Pagination(countries, request) | ||
serializer = CountrySerializer(pagination.getData(), many=True) | ||
return Response({ | ||
'isSuccess': True, | ||
'data': serializer.data, | ||
'message': 'All Countries retrieved successfully', | ||
'pagination': pagination.getPageInfo() | ||
}, status=status.HTTP_200_OK) | ||
except Exception as e: | ||
return handleServerException(e) | ||
|
||
|
||
class CountryDetailView(APIView): | ||
def get(self, request, pk, format=None): | ||
try: | ||
country = Country.objects.get(pk=pk) | ||
serializer = CountrySerializer(country) | ||
return Response({ | ||
'isSuccess': True, | ||
'data': serializer.data, | ||
'message': 'Country retrieved successfully' | ||
}, status=status.HTTP_200_OK) | ||
except Country.DoesNotExist: | ||
return handleNotFound() | ||
except Exception as e: | ||
return handleServerException(e) | ||
|
||
|
||
class CurrencyListView(APIView): | ||
def get(self, request, format=None): | ||
try: | ||
search = request.GET.get('search', None) | ||
order_by = request.GET.get('order_by', None) | ||
if search: | ||
currencies = Currency.objects.filter( | ||
Q(name__icontains=search) | Q(symbol__icontains=search)) | ||
else: | ||
currencies = Currency.objects.all() | ||
if order_by: | ||
currencies = currencies.order_by(order_by) | ||
pagination = Pagination(currencies, request) | ||
serializer = CurrencySerializer(pagination.getData(), many=True) | ||
return Response({ | ||
'isSuccess': True, | ||
'data': serializer.data, | ||
'message': 'All Currencies retrieved successfully', | ||
'pagination': pagination.getPageInfo() | ||
}, status=status.HTTP_200_OK) | ||
except Exception as e: | ||
return handleServerException(e) | ||
|
||
|
||
class CurrencyDetailView(APIView): | ||
def get(self, request, pk, format=None): | ||
try: | ||
currency = Currency.objects.get(pk=pk) | ||
serializer = CurrencySerializer(currency) | ||
return Response({ | ||
'isSuccess': True, | ||
'data': serializer.data, | ||
'message': 'Currency retrieved successfully' | ||
}, status=status.HTTP_200_OK) | ||
except Currency.DoesNotExist: | ||
return handleNotFound() | ||
except Exception as e: | ||
return handleServerException(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...arketplace/packages/migrations/0004_alter_service_package_alter_service_service_master.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.2.7 on 2023-11-30 09:46 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('packages', '0003_service_deleted_at'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='service', | ||
name='package', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='service_package_id', to='packages.package'), | ||
), | ||
migrations.AlterField( | ||
model_name='service', | ||
name='service_master', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='service_master_id', to='packages.servicemaster'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.