예제 #1
0
파일: user.py 프로젝트: alamillac/brokerify
    def delete(self, portfolio_id, transaction_id):
        context.update_uuid()
        stock_transaction = PortfolioStock.get(transaction_id)
        if not stock_transaction or stock_transaction.portfolio_id != portfolio_id:
            return [], 404

        response = PortfolioStockSchema().dump(stock_transaction)
        db_session.delete(stock_transaction)
        return response.data, 200
예제 #2
0
    def get(self, index_id=None):
        context.update_uuid()
        if index_id:
            current_app.logger.debug("Showing index %s", index_id)
            index = Index.get(index_id)
            response = IndexSchema().dump(index)
            return response.data, 200

        current_app.logger.debug("Showing all indices")
        indices = Index.all()
        response = IndexSchema(many=True).dump(indices)
        return response.data, 200
예제 #3
0
파일: user.py 프로젝트: alamillac/brokerify
    def get(self, portfolio_id, dividend_id=None):
        context.update_uuid()
        if not dividend_id:
            stock_dividend = PortfolioDividend.get_list(portfolio_id)
            response = PortfolioDividendSchema(many=True).dump(stock_dividend)
            return response.data, 200

        stock_dividend = PortfolioDividend.get(dividend_id)
        if not stock_dividend or stock_dividend.portfolio_id != portfolio_id:
            return [], 404
        response = PortfolioDividendSchema().dump(stock_dividend)
        return response.data, 200
예제 #4
0
파일: user.py 프로젝트: alamillac/brokerify
    def get(self, portfolio_id, transaction_id=None):
        context.update_uuid()
        if not transaction_id:
            stock_transactions = PortfolioStock.get_list(portfolio_id)
            response = portfolio_stock_schema.dump(stock_transactions)
            return response.data, 200

        stock_transaction = PortfolioStock.get(transaction_id)
        if not stock_transaction or stock_transaction.portfolio_id != portfolio_id:
            return [], 404
        response = PortfolioStockSchema().dump(stock_transaction)
        return response.data, 200
예제 #5
0
파일: user.py 프로젝트: alamillac/brokerify
    def get(self, username=None):
        context.update_uuid()
        if username:
            current_app.logger.debug("Showing user %s", username)
            user = User.get(username)
            response = user_schema.dump(user)
            return response.data, 200

        current_app.logger.debug("Showing all users")
        users = User.all()
        response = users_schema.dump(users)
        return response.data, 200
예제 #6
0
    def get(self, stock_id=None):
        context.update_uuid()
        attributes = ('id', 'name', 'stats', 'market')
        if stock_id:
            current_app.logger.debug("Showing stock %s", stock_id)
            stock = Stock.get(stock_id)
            response = StockSchema(only=attributes).dump(stock)
            return response.data, 200

        current_app.logger.debug("Showing all stocks")
        stocks = Stock.all()
        response = StockSchema(many=True, only=attributes).dump(stocks)
        return response.data, 200
예제 #7
0
파일: user.py 프로젝트: alamillac/brokerify
    def post(self, portfolio_id, transaction_id=None):
        context.update_uuid()
        data = request.get_json()
        if not data:
            return {"error": "Invalid data"}, 400

        data["portfolio_id"] = portfolio_id
        result = UserStockForm().load(data)
        if result.errors:
            return {"error": "Invalid data", "fields": result.errors}, 400

        stock_transaction = PortfolioStock.add(result.data)
        response = PortfolioStockSchema().dump(stock_transaction)
        return response.data, 201
예제 #8
0
    def get(self, stock_id=None):
        context.update_uuid()
        form = StockHistoricalForm().load(request.args)
        if form.errors:
            return {"error": "Invalid data", "fields": form.errors}, 400
        date = form.data.get('date')

        attributes = ('id', 'name', 'historical')
        if stock_id:
            current_app.logger.debug("Showing historical stock %s", stock_id)
            stock = Stock.get(stock_id)
            response = StockSchema(context={'date': date}, only=attributes).dump(stock)
            return response.data, 200

        current_app.logger.debug("Showing all historical stocks")
        stocks = Stock.all()
        response = StockSchema(many=True, context={'date':date}, only=attributes).dump(stocks)
        return response.data, 200
예제 #9
0
파일: user.py 프로젝트: alamillac/brokerify
    def put(self, portfolio_id, transaction_id):
        context.update_uuid()
        data = request.get_json()
        if not data:
            return {"error": "Invalid data"}, 400

        data.update({"portfolio_id": portfolio_id, "id": transaction_id})
        result = UserStockForm().load(data)
        if result.errors:
            return {"error": "Invalid data", "fields": result.errors}, 400

        stock_transaction = PortfolioStock.get(transaction_id)
        if not stock_transaction or stock_transaction.portfolio_id != portfolio_id:
            return [], 404

        stock_transaction = PortfolioStock.update(transaction_id, result.data)
        response = PortfolioStockSchema().dump(stock_transaction)
        return response.data, 200