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)
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)
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)