def get(self): params = _ARGUMENTS.parse_args() account_id = params.get('account_id') credit_debit = params.get('credit_debit') user = AccountModel.find(account_id) credits = [] debits = [] if user is None: return errors._USER_NOT_FOUND, server_code.NOT_FOUND if credit_debit is None: credits = CreditModel.find_all_credits(account_id) debits = DebitModel.find_all_credits(account_id) elif credit_debit == 0: credits = CreditModel.find_all_credits(account_id) elif credit_debit == 1: debits = DebitModel.find_all_credits(account_id) result = user.json() result["debits"] = [debit.json() for debit in debits] result["credits"] = [credit.json() for credit in credits] result["amount_credits"] = amount_credits = self.__sum(credits) result["amount_debits"] = amount_debits = self.__sum(debits) result[ "amount"] = user.initial_balance + amount_credits - amount_debits return result, server_code.OK
def __validate_value(self, arguments_data): if arguments_data is None: return errors._NOT_FOUND, server_code.INTERNAL_SERVER_ERROR if AccountModel.find(arguments_data.get('account_id')) is None: return errors._USER_NOT_FOUND, server_code.BAD_REQUEST if arguments_data.get("value") <= 0: return errors._VALUE_ERROR, server_code.BAD_REQUEST return None, None