def response(reserve): return jsonify({ 'date_out': reserve.date_out, 'date_back': reserve.date_back, 'client_id': reserve.client_id, 'book_id': reserve.book_id })
def authors(identity): """Example endpoint return a list of authors by identity This is using docstring for specifications --- tags: - authors parameters: - name: identity in: path type: string enum: ['all', 'rgb', 'cmyk'] required: true default: all description: Which identity to filter? operationId: get_authors consumes: - application/json produces: - application/json security: authors_auth: - 'write:authors' - 'read:authors' schemes: ['http', 'https'] deprecated: false externalDocs: description: Project repository url: http://github.com/rochacbruno/flasgger definitions: identity: type: object properties: identity_name: type: array items: $ref: '#/definitions/Color' Color: type: string responses: 200: description: A list of authors (may be filtered by identity) schema: $ref: '#/definitions/identity' examples: rgb: ['red', 'green', 'blue'] """ author = Identity.query.filter_by(firstname='Max').first() all_authors = { 'cmyk': [author.firstname, author.lastname], 'rgb': ['red', 'green', 'blue'] } if identity == 'all': result = all_authors else: result = {identity: all_authors.get(identity)} return jsonify(result)
def all_reserves(): return jsonify([ { 'date_out': reserve.date_out, 'date_back': reserve.date_back, 'client_id': reserve.client_id, 'book_id': reserve.book_id } for reserve in Reserve.query.all() ])
def register_books(): new_book = Book( title=request.json['title'], author=request.json['author'] ) db.session.add(new_book) db.session.commit() return jsonify({ 'id': new_book.id, 'title': new_book.title, 'author': new_book.author })
def response(book): return jsonify({ 'id': book.id, 'title': book.title, 'author': book.author })
def response(client): return jsonify({'id': client.id, 'name': client.name})
def delete_clients(client_id): client = Client.query.get(client_id) db.session.delete(client) db.session.commit() return jsonify([{'message': "Data deleted"}])
def all_clients(): return jsonify([ {'id': client.id, 'name': client.name} for client in Client.query.all() ])
def delete_book(book_id): book = Book.query.get(book_id) db.session.delete(book) db.session.commit() return jsonify([{'message': "Data deleted"}])
def book(book_id): book = Book.query.get(book_id) return jsonify([ {'id': book.id, 'title': book.title, 'author': book.author,} ])
def all_books(): return jsonify([ {'id': book.id, 'title': book.title, 'author': book.author} for book in Book.query.all() ])
def delete_reserves(reserve_id): reserve = Reserve.query.get(reserve_id) db.session.delete(reserve) db.session.commit() return jsonify([{'message': "Data deleted"}])
def clients_reserves(client_id): client = Client.query.get(client_id) return jsonify([ {'date_out': reserve.date_out,'date_back': reserve.date_back,'client_id': reserve.client_id,'book_id': reserve.book_id} for reserve in client.reserves ])