Raise error whether field's absent
This commit is contained in:
parent
393aa9ef28
commit
4cf0ce831b
|
|
@ -31,7 +31,8 @@ class AbstractBookingService(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def check_whether_booking_available(self, restaurant_id, date):
|
def check_whether_booking_available(self, restaurant_id, date):
|
||||||
""" checks whether booking is available """
|
""" checks whether booking is available """
|
||||||
pass
|
if date is None:
|
||||||
|
raise serializers.ValidationError(detail='date query param is required')
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def cancel_booking(self, payload):
|
def cancel_booking(self, payload):
|
||||||
|
|
@ -66,6 +67,7 @@ class GuestonlineService(AbstractBookingService):
|
||||||
return {'X-Token': self.token, 'Content-type': 'application/json', 'Accept': 'application/json'}
|
return {'X-Token': self.token, 'Content-type': 'application/json', 'Accept': 'application/json'}
|
||||||
|
|
||||||
def check_whether_booking_available(self, restaurant_id, date: str):
|
def check_whether_booking_available(self, restaurant_id, date: str):
|
||||||
|
super().check_whether_booking_available(restaurant_id, date)
|
||||||
url = f'{self.url}v1/runtime_services'
|
url = f'{self.url}v1/runtime_services'
|
||||||
params = {'restaurant_id': restaurant_id, 'date': date, 'expands[]': 'table_availabilities'}
|
params = {'restaurant_id': restaurant_id, 'date': date, 'expands[]': 'table_availabilities'}
|
||||||
r = requests.get(url, headers=self.get_common_headers(), params=params)
|
r = requests.get(url, headers=self.get_common_headers(), params=params)
|
||||||
|
|
@ -126,6 +128,7 @@ class LastableService(AbstractBookingService):
|
||||||
'Accept': 'application/json'}
|
'Accept': 'application/json'}
|
||||||
|
|
||||||
def check_whether_booking_available(self, restaurant_id, date):
|
def check_whether_booking_available(self, restaurant_id, date):
|
||||||
|
super().check_whether_booking_available(restaurant_id, date)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def commit_booking(self, payload):
|
def commit_booking(self, payload):
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,24 @@ class BookingSerializer(serializers.ModelSerializer):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CheckBookingSerializer(serializers.ModelSerializer):
|
||||||
|
available = serializers.BooleanField()
|
||||||
|
type = serializers.ChoiceField(choices=models.Booking.AVAILABLE_SERVICES, allow_null=True)
|
||||||
|
details = serializers.DictField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.Booking
|
||||||
|
fields = (
|
||||||
|
'available',
|
||||||
|
'type',
|
||||||
|
'details',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PendingBookingSerializer(serializers.ModelSerializer):
|
class PendingBookingSerializer(serializers.ModelSerializer):
|
||||||
restaurant_id = serializers.IntegerField(min_value=0, )
|
restaurant_id = serializers.IntegerField(read_only=True)
|
||||||
id = serializers.ReadOnlyField()
|
id = serializers.ReadOnlyField()
|
||||||
|
user = serializers.ReadOnlyField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Booking
|
model = models.Booking
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,14 @@ from establishment.models import Establishment
|
||||||
from booking.models.models import Booking, GuestonlineService, LastableService
|
from booking.models.models import Booking, GuestonlineService, LastableService
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from booking.serializers.web import (PendingBookingSerializer,
|
from booking.serializers.web import (PendingBookingSerializer,
|
||||||
UpdateBookingSerializer, GetBookingSerializer)
|
UpdateBookingSerializer, GetBookingSerializer, CheckBookingSerializer)
|
||||||
from utils.serializers import EmptySerializer
|
|
||||||
|
|
||||||
|
|
||||||
class CheckWhetherBookingAvailable(generics.GenericAPIView):
|
class CheckWhetherBookingAvailable(generics.GenericAPIView):
|
||||||
""" Checks which service to use if establishmend is managed by any """
|
""" Checks which service to use if establishmend is managed by any """
|
||||||
|
|
||||||
permission_classes = (permissions.AllowAny,)
|
permission_classes = (permissions.AllowAny,)
|
||||||
serializer_class = EmptySerializer
|
serializer_class = CheckBookingSerializer
|
||||||
pagination_class = None
|
pagination_class = None
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user