def delete_car(current_user, car_id): car = Car.get_car_by_id(car_id) if not car: return response('failed', 'car not found', 404) data = cars_schema.dump(car).data if data.get('owner_id') != current_user.id: return response('failed', 'It\'s not your car', 400) car.delete() return response('success', 'car deleted', 204)
def update_car(current_user, car_id): if request.content_type == 'application/json' : req_data = request.get_json() car = Car.get_car_by_id(car_id) if not car: return response('failed', 'car not found', 404) data = cars_schema.dump(car).data if data.get('owner_id') != current_user.id: return response('failed', 'It\'s not your car', 400) data, error = cars_schema.load(req_data, partial=True) if error: return response('failed', error, 400) car.update(data) data = cars_schema.dump(car).data return response_for_get_cars(data)
def get_car_by_id(current_user, car_id): car = Car.get_car_by_id(car_id) if not car: return response('failed', 'car not found', 404) data = car_schema.dump(car).data return response_for_user_car(data)