def put(self,_id): value = self.parser.parse_args() order = OrderModel.find_by_id(_id) if order is not None: order.menu = value['menu'] order.res = value['res'] order.userid = value['userid'] order.save_to_db() return order.json() return {'msg','no user'},400
def put(self, order_id: int): result_dict, err_code = handle_request_validation_and_serialisation( order_creation_schema) if err_code: return result_dict, err_code if not result_dict['elements']: return { "message": "The order cannot be empty. The order must have at least one element." }, 400 order = OrderModel.find_by_id(order_id) if not order: return { "message": f"Order with id: {order_id} does not exist." }, 404 new_elements = result_dict['elements'] old_elements = [ order_element_creation_schema.dump(e) for e in order.elements ] old_to_delete = [ e['item_id'] for e in old_elements if e not in new_elements ] new_to_add = [e for e in new_elements if e not in old_elements] # useful for debugging purposes # print('O', old_elements) # print('N', new_elements) # print(old_to_delete) # print(new_to_add) # for x in order.elements: # print(x.item_id in old_to_delete) old_to_delete = list( filter(lambda x: x.item_id in old_to_delete, order.elements)) OrderElementModel.delete_all_from_db(old_to_delete) new_to_add = [ OrderElementModel(**order_element_creation_schema.load(e)) for e in new_to_add ] if err_msg := _validate_order_elements(new_to_add): return err_msg, 400
def put(self, order_id: int): result_dict, err_code = handle_request_validation_and_serialisation( order_update_schema) if err_code: return result_dict, err_code order = OrderModel.find_by_id(order_id) if not order: return { "message": f"Order with id: {order_id} does not exist." }, 400 order.user_id = result_dict.get('user_id', order.user_id) order.status = result_dict.get('status', order.status) order.comments = result_dict.get('comments', order.comments) order.update_in_db() return { "message": f"The order with id: {order.id} updated successfully.", "entry": order_schema.dump(order) }, 200
def delete(self,_id): order = OrderModel.find_by_id(_id) if order: order.delete_from_db() return order.json() return {"msg":'No user'},400
def get(self,_id): order = OrderModel.find_by_id(_id) if order: return order.json() return {"msg":'No user'},400