def post(self, id_1, id_2): banner_top = InterfaceModel.find_by_id(id_1) banner_down = InterfaceModel.find_by_id(id_2) if not banner_top: return {'message': "Banner with ['id': {}] not found".format(id_1)}, 404 if not banner_down: return {'message': "Banner with ['id': {}] not found".format(id_2)}, 404 order_aux = banner_top.order banner_top.order = banner_down.order banner_top.save_to_db() banner_down.order = order_aux banner_down.save_to_db() return {'message': "Banners ID changed"}, 200
def delete(self, id_interface, id_book): interface = InterfaceModel.find_by_id(id_interface) if not interface: return {'message': "Interface with ['id': {}] not found".format(id_interface)}, 404 book = BookModel.find_by_id(id_book) if not book: return {'message': "Book with ['id': {}] not found".format(id_book)}, 404 interface.books.remove(book) interface.save_to_db() return {'message': "Book with ['id': {}] has successfully been deleted".format(id_book)}, 200
def delete(self, idd): exists = InterfaceModel.find_by_id(idd) if not exists: return {'message': "Interface with ['id': {}] not found".format(idd)}, 404 exists.delete_from_db() interfaces = sorted([i for i in db.session.query(InterfaceModel).all()], key=lambda x: x.order) # file deepcode ignore C0200: <comment the reason here> for i in range(len(interfaces)): interfaces[i].order = i + 1 interfaces[i].save_to_db() return {'message': "Interface with ['id': {}] has successfully been deleted".format(idd)}, 200
def put(self, idd): data = self.__parse_request__() exists = InterfaceModel.find_by_id(idd) if not exists: return {'message': "Interface with ['id': {}] not found".format(idd)}, 404 exists.front_type = data.get('front_type') exists.t2BookMode = data.get('t2BookMode') exists.t1BackgndURL = data.get('t1BackgndURL') exists.t1BackgndCOL = data.get('t1BackgndCOL') exists.t1LinkTo = data.get('t1LinkTo') exists.t1Tit = data.get('t1Tit') exists.t1Separator = data.get('t1Separator') exists.t1Sub = data.get('t1Sub') exists.t1Small = data.get('t1Small') exists.t2RowTitle = data.get('t2RowTitle') exists.t2RowNumber = data.get('t2RowNumber') exists.t1TxtColor = data.get('t1TxtColor') if data.get('t2Books'): exists.books = [BookModel.find_by_id(int(i)) for i in data.get('t2Books').split(",")] exists.save_to_db() return exists.json(), 200
def get(self, idd): interface = InterfaceModel.find_by_id(idd) if interface: return interface.json(), 200 return {'message': "Interface with ['id': {}] not found".format(idd)}, 404
def get(self, id_interface): interface = InterfaceModel.find_by_id(id_interface) if not interface: return {'message': "Interface with ['id': {}] not found".format(id_interface)}, 404 return {'books': [i.json() for i in interface.books]}, 200