def post(cls): name = request.get_json()["name"] if ListModel.find_by_name(name): return {"message": NAME_ALREADY_EXISTS.format(name=name)}, 400 list = ListModel(name=name) try: list.save_to_db() except: return {"message": ERROR_INSERTING}, 500 return list_schema.dump(list), 201
def get(cls): name = request.get_json()["name"] list = ListModel.find_by_name(name) if list: return list_schema.dump(list), 200 return {"message": LIST_NOT_FOUND}, 404
def put(self, list_id): ilist = ListModel.find_by_id(list_id) ilist_data = list_schema.load(request.get_json()) if ilist: ilist.title = ilist_data.title else: ilist_data.save_to_db() ilist.save_to_db() return list_schema.dump(ilist)
def post(self): try: user = user_schema.load(request.get_json()) except ValidationError as err: return err.messages, 400 if UserModel.find_by_username(user.username): return {"message": "A user with that username already exists"}, 400 user.save_to_db() thelist = ListModel("Gelen Kutusu") thelist.save_to_db() permission = ListPermissionModel(user.id, thelist.id) permission.save_to_db() #return {"message": "User created successfully."}, 201 return perm_schema.dump(permission)
def delete(cls): name = request.get_json()["name"] list = ListModel.find_by_name(name) if list: list.delete_from_db() return {"message": LIST_DELETED}, 200 return {"message": LIST_NOT_FOUND}, 404
def list_list(self, request): logging.info('list_list()') query = ListModel.get_lists() lists = [entity.to_message() for entity in query.fetch()] listList = ListListResponse() listList.lists = lists return listList
def get(self): items = [item.json() for item in ListModel.find_all()] return {"lists":items}
def delete(self, list_id): ilist = ListModel.find_by_id(list_id) if ilist: ilist.delete_from_db() return{"message":"list deleted"}, 200 return{"message":"list not found"}
def get(self, list_id): ilist = ListModel.find_by_id(list_id) if ilist: return ilist.json() return {"message":"not found"}, 404
def get(cls): return {"lists": list_list_schema.dump(ListModel.find_all())}, 200
def list_delete_all(self, request): logging.info('list_delete()') ListModel.delete_by_id(request) return ListListResponse()
def list_insert(self, request): logging.info('list_insert()') entity = ListModel.put_from_message(request) return entity.to_message()
def list_details(self, request): logging.info('list_details()') list = ListModel.get_details(request) return list.to_message()