def post(self): item = request.get_json() if request.get_json() else request.form # reports = ReportModel.list_all() try: if item: model = ReportModel() model.status = item['status'] model.vehicle_id = item['vehicle_id'] model.client_id = item['client_id'] model.description = item['description'] model.timestamp = date.today() model.save() return 'created', 201 else: return 'not created, invalid payload', 400 except Exception as e: return f"{e}", 500
def put(self, id): item = request.get_json() if request.get_json() else request.form try: if item: model = ReportModel() model = ReportModel.get_by_id(id) if 'status' in item: model.status = item['status'] if 'vehicle_id' in item: model.vehicle_id = item['vehicle_id'] if 'client_id' in item: model.client_id = item['client_id'] if 'description' in item: model.description = item['description'] model.save() return 'edited', 204 else: return 'unedited, invalid payload', 400 except Exception as e: return f"{e}", 500