Exemplo n.º 1
0
def delete_income(id):
    try:
        #TODO DELETE
        schema = IncomeSchema(many=True)
        incomes = schema.dump(
            filter(lambda t: t.type == TransactionType.INCOME, transactions))

    except ValueError:
        pass

    return "", 204
Exemplo n.º 2
0
def get_incomes():

    schema = IncomeSchema(many=True)

    # Serialize income object to native Python data types according to its Schema's fields.
    # We use a filter with a lambda function to get all objects of type INCOME from 'transactions' list var to serialize
    # Var 'incomes' is of type => tuple of the form (``data``, ``errors``)
    incomes = schema.dump(
        filter(lambda t: t.type == TransactionType.INCOME, transactions))

    # Return the serialised data as JSON to the browser
    return jsonify(incomes.data)
Exemplo n.º 3
0
def get_incomes():
    op = 0
    conn = pg.connect(dbname='postgres', user='******', password='******', host='192.168.99.102')
    cur = conn.cursor()

    cur.execute("SELECT * FROM byte_store")
    trs = cur.fetchall()
    trs = [pickle.loads(bytes(i[0])) for i in trs]
    schema = IncomeSchema(many=True)
    incomes = schema.dump(
        filter(lambda t: t.type == TransactionType.INCOME, trs)
    )
    
    resp = json.dumps(incomes.data, sort_keys = True, indent = 4, separators = (',', ': '))
    return current_app.response_class(resp, mimetype="application/json")
Exemplo n.º 4
0
    Income('Salary', 5000),
    Income('Dividends', 200),
    Expense('pizza', 50),
    Expense('Rock Concert', 100)
]


@app.route('/incomes'
def get_incomes():
    """
    1. manyってなに?
    2. filterの挙動を忘れた
    """
    schema = IncomeSchema(many=True)
    incomes = schema.dump(
        filter(lambda t: t.type == TransactionType.INCOME, transactions )
    )

    return jsonify(incomes.data)


@app.route('/incomes', methods=['POST'])
def add_income():
    """
    1. POSTは待ちの姿勢のmethodsか?それとも新しいデータを追加する為のmethodsか?
    2. request.get_json()で新しい入力データを読み込むのか?
    3. 204ってなに?なんで空文字を返すの?
    """
    income = IncomeSchema().load(request.get_json())
    transactions.append(income.data)
    return "", 204
Exemplo n.º 5
0
def get_incomes():
  schema = IncomeSchema(many=True)
  incomes = schema.dump(
    filter(lambda t: t.type == TransactionType.INCOME, transactions)
  )
  return jsonify(incomes.data)