adding api for phone app
This commit is contained in:
parent
63818c6fe3
commit
c728c4e116
Binary file not shown.
Binary file not shown.
@ -58,6 +58,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'rest_framework.authtoken',
|
'rest_framework.authtoken',
|
||||||
|
'drf_yasg',
|
||||||
'core',
|
'core',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,29 @@ from django.conf import settings
|
|||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.conf.urls.i18n import i18n_patterns
|
from django.conf.urls.i18n import i18n_patterns
|
||||||
|
|
||||||
|
from rest_framework import permissions
|
||||||
|
from drf_yasg.views import get_schema_view
|
||||||
|
from drf_yasg import openapi
|
||||||
|
|
||||||
|
schema_view = get_schema_view(
|
||||||
|
openapi.Info(
|
||||||
|
title="Masar Express API",
|
||||||
|
default_version='v1',
|
||||||
|
description="API documentation for Masar Express Mobile App & Drivers",
|
||||||
|
terms_of_service="https://www.google.com/policies/terms/",
|
||||||
|
contact=openapi.Contact(email="support@masarexpress.com"),
|
||||||
|
license=openapi.License(name="BSD License"),
|
||||||
|
),
|
||||||
|
public=True,
|
||||||
|
permission_classes=(permissions.AllowAny,),
|
||||||
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('i18n/', include('django.conf.urls.i18n')),
|
path('i18n/', include('django.conf.urls.i18n')),
|
||||||
|
# Swagger / Redoc
|
||||||
|
path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
|
||||||
|
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||||
|
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += i18n_patterns(
|
urlpatterns += i18n_patterns(
|
||||||
@ -17,4 +38,4 @@ urlpatterns += i18n_patterns(
|
|||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
urlpatterns += static("/assets/", document_root=settings.BASE_DIR / "assets")
|
urlpatterns += static("/assets/", document_root=settings.BASE_DIR / "assets")
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,7 +5,7 @@ from rest_framework.authtoken.models import Token
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from .models import Parcel, Profile
|
from .models import Parcel, Profile
|
||||||
from .serializers import ParcelSerializer, ProfileSerializer
|
from .serializers import ParcelSerializer, ProfileSerializer, PublicParcelSerializer
|
||||||
|
|
||||||
class CustomAuthToken(ObtainAuthToken):
|
class CustomAuthToken(ObtainAuthToken):
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
@ -78,3 +78,13 @@ class UserProfileView(generics.RetrieveUpdateAPIView):
|
|||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
return self.request.user.profile
|
return self.request.user.profile
|
||||||
|
|
||||||
|
class PublicParcelTrackView(generics.RetrieveAPIView):
|
||||||
|
"""
|
||||||
|
Public endpoint to track a parcel by its tracking number.
|
||||||
|
No authentication required.
|
||||||
|
"""
|
||||||
|
serializer_class = PublicParcelSerializer
|
||||||
|
permission_classes = [permissions.AllowAny]
|
||||||
|
queryset = Parcel.objects.all()
|
||||||
|
lookup_field = 'tracking_number'
|
||||||
@ -35,3 +35,24 @@ class ParcelSerializer(serializers.ModelSerializer):
|
|||||||
model = Parcel
|
model = Parcel
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
read_only_fields = ['shipper', 'tracking_number', 'created_at', 'updated_at', 'thawani_session_id']
|
read_only_fields = ['shipper', 'tracking_number', 'created_at', 'updated_at', 'thawani_session_id']
|
||||||
|
|
||||||
|
class PublicParcelSerializer(serializers.ModelSerializer):
|
||||||
|
pickup_governate_name = serializers.CharField(source='pickup_governate.name', read_only=True)
|
||||||
|
pickup_city_name = serializers.CharField(source='pickup_city.name', read_only=True)
|
||||||
|
delivery_governate_name = serializers.CharField(source='delivery_governate.name', read_only=True)
|
||||||
|
delivery_city_name = serializers.CharField(source='delivery_city.name', read_only=True)
|
||||||
|
status_display = serializers.CharField(source='get_status_display', read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Parcel
|
||||||
|
fields = [
|
||||||
|
'tracking_number',
|
||||||
|
'status',
|
||||||
|
'status_display',
|
||||||
|
'pickup_governate_name',
|
||||||
|
'pickup_city_name',
|
||||||
|
'delivery_governate_name',
|
||||||
|
'delivery_city_name',
|
||||||
|
'updated_at',
|
||||||
|
'description'
|
||||||
|
]
|
||||||
@ -70,5 +70,6 @@ urlpatterns = [
|
|||||||
path('api/auth/token/', api_views.CustomAuthToken.as_view(), name='api_token_auth'),
|
path('api/auth/token/', api_views.CustomAuthToken.as_view(), name='api_token_auth'),
|
||||||
path('api/parcels/', api_views.ParcelListCreateView.as_view(), name='api_parcel_list'),
|
path('api/parcels/', api_views.ParcelListCreateView.as_view(), name='api_parcel_list'),
|
||||||
path('api/parcels/<int:pk>/', api_views.ParcelDetailView.as_view(), name='api_parcel_detail'),
|
path('api/parcels/<int:pk>/', api_views.ParcelDetailView.as_view(), name='api_parcel_detail'),
|
||||||
|
path('api/track/<str:tracking_number>/', api_views.PublicParcelTrackView.as_view(), name='api_track_parcel'),
|
||||||
path('api/profile/', api_views.UserProfileView.as_view(), name='api_user_profile'),
|
path('api/profile/', api_views.UserProfileView.as_view(), name='api_user_profile'),
|
||||||
]
|
]
|
||||||
@ -5,4 +5,5 @@ Pillow
|
|||||||
weasyprint
|
weasyprint
|
||||||
qrcode
|
qrcode
|
||||||
django-jazzmin==3.0.1
|
django-jazzmin==3.0.1
|
||||||
djangorestframework==3.15.1
|
djangorestframework==3.15.1
|
||||||
|
drf-yasg
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user