コード例 #1
0
ファイル: reserve.py プロジェクト: vinidotruan/python-api
 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
     })
コード例 #2
0
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)
コード例 #3
0
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()
    ])
コード例 #4
0
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
    })
コード例 #5
0
ファイル: book.py プロジェクト: vinidotruan/python-api
 def response(book):
     return jsonify({
         'id': book.id,
         'title': book.title,
         'author': book.author
     })
コード例 #6
0
 def response(client):
     return jsonify({'id': client.id, 'name': client.name})
コード例 #7
0
def delete_clients(client_id):
    client = Client.query.get(client_id)
    db.session.delete(client)
    db.session.commit()

    return jsonify([{'message': "Data deleted"}])
コード例 #8
0
def all_clients():
    return jsonify([
        {'id': client.id, 'name': client.name}
        for client in Client.query.all()
    ])
コード例 #9
0
def delete_book(book_id):
    book = Book.query.get(book_id)
    db.session.delete(book)
    db.session.commit()

    return jsonify([{'message': "Data deleted"}])
コード例 #10
0
def book(book_id):
    book = Book.query.get(book_id)
    return jsonify([
        {'id': book.id, 'title': book.title, 'author': book.author,}
    ])
コード例 #11
0
def all_books():
    return jsonify([
        {'id': book.id, 'title': book.title, 'author': book.author}
        for book in Book.query.all()
    ])
コード例 #12
0
def delete_reserves(reserve_id):
    reserve = Reserve.query.get(reserve_id)
    db.session.delete(reserve)
    db.session.commit()

    return jsonify([{'message': "Data deleted"}])
コード例 #13
0
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
    ])