Ejemplo n.º 1
0
    def get_by_id(rental_id: int):

        rental = RentalModel.get_by_id(rental_id)
        if not rental:
            return custom_response({'error': 'not found'}, 404)
        data = rental_schema.dump(rental)
        if data.get('user_id') != RentalService.get_user():
            return custom_response({'error': 'permission denied'}, 400)
        return custom_response(data, 200)
Ejemplo n.º 2
0
    def return_movie(req_data):

        rental = RentalModel.get_by_id(req_data["rental_id"])
        if not rental:
            return custom_response({'error': 'rental not found'}, 404)
        data = rental_schema.dump(rental)
        if data.get('user_id') != RentalService.get_user():
            return custom_response({'error': 'permission denied'}, 400)
        rental = rental.return_movie()

        data = rental_schema.dump(rental)
        return custom_response(data, 200)
Ejemplo n.º 3
0
    def update(rental_id: int, req_data):

        rental = RentalModel.get_by_id(rental_id)
        if not rental:
            return custom_response({'error': 'not found'}, 404)
        data = rental_schema.dump(rental)
        if data.get('user_id') != RentalService.get_user():
            return custom_response({'error': 'permission denied'}, 400)

        try:
            data = rental_schema.load(req_data, partial=True)
        except ValidationError as e:
            return custom_response(e.messages, 400)
        rental.update(data)

        data = rental_schema.dump(rental)
        return custom_response(data, 200)