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
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
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
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
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
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
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
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
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