コード例 #1
0
class UpdateRestaurant(UpdateAPIView):
    permission_classes = (PlaceAdmin, RestaurantAdmin)

    def __init__(self, *args, **kwargs):
        self._restaurants_service = RestaurantsService()

    def put(self, request, restaurant_id):
        logger.info(
            f'Updating restaurant {restaurant_id} with data {request.data}')
        serializer = RestaurantCreateSerializer(data=request.data)

        if not serializer.is_valid():
            logger.error(f'Validation failed, {serializer.errors}')
            return BAD_REQUEST(serializer.errors)

        updated = self._restaurants_service.update(restaurant_id,
                                                   **serializer.validated_data)

        if not updated:
            msg = 'Could not update the restaurant.'
            logger.error(f'{msg}')
            return INTERNAL_SERVER_ERROR(msg)

        logger.info('Restaurant updated successfully.')
        return OK(None)
コード例 #2
0
class GetWithinRadius(ListAPIView):
    '''
        Get restaurants within a radius of user's latitude and longitude. The radius is configured in settings.
    '''
    permission_classes = (permissions.AllowAny, )

    def __init__(self, **kwargs):
        self._restaurants = RestaurantsService()

    @method_decorator(cache_page(settings.ONE_DAY))
    def get(self, request):
        lat = request.query_params.get('lat', None)
        lng = request.query_params.get('lng', None)

        if lat == None or lng == None:
            return BAD_REQUEST({
                'Invalid request':
                'Latitude and longitude are required as query parameters.'
            })

        restaurants = self._restaurants.get_within_radius(lat, lng)

        serializer = RestaurantsListResponseSerializer(restaurants, many=True)

        return Response(serializer.data)
コード例 #3
0
class GetRestaurants(ListAPIView):
    permission_classes = (PlaceAdmin, )

    def __init__(self):
        self._restaurants_service = RestaurantsService()

    def get(self, request):
        restaurants = self._restaurants_service.get_by_appuser(
            request.appuser_id)
        resp = restaurants.serialize_data(
            RestaurantsListResponseSerializerAdmin)
        return Response(resp)
コード例 #4
0
class GetRestaurants(ListAPIView):
    permission_classes = (permissions.AllowAny, )

    def __init__(self):
        self._restaurants = RestaurantsService()

    @method_decorator(cache_page(settings.ONE_DAY))
    def get(self, request):
        q = request.query_params.get('q', None)
        page = request.query_params.get('page', 1)
        size = request.query_params.get('size', 10)
        restaurants = self._restaurants.search(q, page, size)

        resp = restaurants.serialize_data(RestaurantsListResponseSerializer)

        return Response(resp)
コード例 #5
0
class AcceptOrder(permissions.BasePermission):
    def __init__(self, *args, **kwargs):
        self._order_service = OrderService()
        self._restaurants_service = RestaurantsService()

    def has_permission(self, request, view):
        order_id = view.kwargs.get('order_id')

        restaurant_id = self._order_service.get_restaurant_id_by_orderid(
            order_id)
        if not restaurant_id:
            return False

        is_restaurant_admin = self._restaurants_service.check_admin(
            request.appuser_id, restaurant_id)

        return is_restaurant_admin
コード例 #6
0
class RestaurantAdmin(permissions.BasePermission):
    def __init__(self):
        self.__appuser_service = AppUserService()
        self.__restaurants_service = RestaurantsService()

    def has_permission(self, request, view):
        restaurant_id = view.kwargs.get('restaurant_id')

        if restaurant_id == None:
            restaurant_id = request.data.get('restaurant_id')
            if restaurant_id == None:
                return False

        is_admin = self.__restaurants_service.check_admin(
            request.appuser_id, restaurant_id)

        return is_admin
コード例 #7
0
class PrepopRestaurants(ListAPIView):
    '''
        Get prepop data from the prepop service
    '''
    permission_classes = (permissions.AllowAny, )

    def __init__(self):
        self._restaurants = RestaurantsService()

    @method_decorator(cache_page(settings.ONE_DAY))
    def get(self, request):
        query = request.query_params.get('q', None)

        if query == None:
            return Response([])

        prepop = self._restaurants.query_prepop(query)

        return Response(prepop)
コード例 #8
0
class AddRestaurant(CreateAPIView):
    permission_classes = (PlaceAdmin, )

    def __init__(self):
        self._restaurants_service = RestaurantsService()
        self._appuser_service = AppUserService()

    def post(self, request, *args, **kwargs):
        serializer = RestaurantCreateSerializer(data=request.data)
        if not serializer.is_valid():
            return BAD_REQUEST(serializer.errors)

        banner = request.data.get('banner', None)

        if banner == None:
            return BAD_REQUEST('Please upload a banner.')

        newid = self._restaurants_service.create(request.appuser_id, banner,
                                                 **serializer.validated_data)

        if not newid:
            return INTERNAL_SERVER_ERROR('Could not save the restaurant.')

        return OK(newid)
コード例 #9
0
 def __init__(self):
     self._restaurants = RestaurantsService()
コード例 #10
0
 def __init__(self, **kwargs):
     self._restaurants = RestaurantsService()
コード例 #11
0
 def __init__(self):
     self._restaurants_service = RestaurantsService()
     self._appuser_service = AppUserService()
コード例 #12
0
 def __init__(self, *args, **kwargs):
     self._order_service = OrderService()
     self._restaurants_service = RestaurantsService()