def get(self, id):
        """Gives the data of single fund transfer  with selected fund transfer id """

        try:
            fund = FundTransfer.query.filter(FundTransfer.id == id).first()
            output = fund_transfer_schema.dump(fund)
            if fund:
                logger.info('fund transfer returned successfully')
                response = ResponseGenerator(
                    data=output,
                    message="fund transfer returned successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
    def get(self, id):
        """Gives the data of single transaction type  with selected transaction type id """

        try:
            transaction = TransactionType.query.filter(
                TransactionType.id == id).first()
            output = transaction_type_schema.dump(transaction)
            if transaction:
                logger.info('transaction type returned successfully')
                response = ResponseGenerator(
                    data=output,
                    message="transaction type returned successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
 def delete(self, id):
     """delete the branch detail of selected branch  id"""
     try:
         branch = BranchDetails.query.get(id)
         if branch:
             db.session.delete(branch)
             db.session.commit()
             logger.info("Branch details deleted successfully")
             return "Branch details deleted successfully"
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def get(self, id):
     """Gives the data of single branch detail with selected branch id """
     try:
         branch = BranchDetails.query.filter(BranchDetails.id == id).first()
         output = branch_detail_schema.dump(branch)
         logger.info('Branch data returned successfully')
         if branch:
             response = ResponseGenerator(
                 data=output,
                 message="Branch data returned successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
Пример #5
0
 def get(self, id):
     """Gives the detail of first 10 transactions of selected bank account  id """
     try:
         account_transaction = BankAccount.query.filter(
             BankAccount.id == id).first()
         if account_transaction:
             mini_statement = AccountTransactionDetails.query.filter(
                 AccountTransactionDetails.bank_account_id == id).order_by(
                     desc(AccountTransactionDetails.id)).limit(10)
             if not mini_statement:
                 raise IdNotFound('id not found:{}'.format(id))
         output = account_transaction_details_schema.dump(mini_statement)
         logger.info('account transaction details returned successfully')
         response = ResponseGenerator(
             data=output,
             message="account transaction details returned successfully",
             success=True,
             status=status.HTTP_200_OK)
         return response.success_response()
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def delete(self, id):
     """Delete the user"""
     try:
         user = User.query.get(id)
         if user:
             if user.is_deleted == 1:
                 logger.info("User is already deleted")
                 return "User is already deleted"
             elif user.is_deleted == 0:
                 user.is_deleted = 1
                 db.session.commit()
                 logger.info("User data deleted successfully")
                 response = ResponseGenerator(
                     data=user,
                     message="User data deleted successfully",
                     success=True,
                     status=status.HTTP_200_OK)
                 return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def get(self, id):
     """Gives the data of single user with selected user_id """
     try:
         user = User.query.filter(User.id == id,
                                  User.is_deleted == 0).first()
         output = user_schema.dump(user)
         logger.info('User data returned successfully')
         if user:
             response = ResponseGenerator(
                 data=output,
                 message="User data returned successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
Пример #8
0
 def get(self, id):
     """Gives the data of bank account of selected bank account id """
     try:
         account = BankAccount.query.filter(
             BankAccount.id == id, BankAccount.deleted == 0).first()
         output = bank_account_schema.dump(account)
         if account:
             logger.info('bank account data returned successfully')
             response = ResponseGenerator(
                 data=output,
                 message="bank account data returned successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
 def put(self, id):
     """Update the user data """
     try:
         data = request.get_json()
         result = user_schema.validate(data, partial=True)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         user = User.query.filter(User.id == id,
                                  User.is_deleted == 0).first()
         hashed = bcrypt.hashpw(
             data.get('password', user.password).encode('utf-8'),
             bcrypt.gensalt())
         if user:
             user.first_name = data.get('first_name', user.first_name)
             user.last_name = data.get('last_name', user.last_name)
             user.address = data.get('address', user.address)
             user.mobile_number = data.get('mobile_number',
                                           user.mobile_number)
             user.email_id = data.get('email_id', user.email_id)
             user.password = hashed
             user.user_type_id = data.get('user_type_id', user.user_type_id)
             db.session.commit()
             output = user_schema.dump(user)
             logger.info("User data updated successfully")
             response = ResponseGenerator(
                 data=output,
                 message="User data updated successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
Пример #10
0
 def put(self, id):
     """Update the bank account data """
     try:
         data = request.get_json()
         result = bank_account_schema.validate(data, partial=True)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         account = BankAccount.query.filter(
             BankAccount.id == id, BankAccount.is_active == True,
             BankAccount.deleted == False).first()
         if account:
             account.user_id = data.get('user_id', account.user_id)
             account.account_type_id = data.get('account_type_id',
                                                account.account_type_id)
             account.branch_id = data.get('branch_id', account.branch_id)
             account.balance = data.get('balance', account.balance)
             db.session.commit()
             output = bank_account_schema.dump(account)
             logger.info("bank account data updated successfully")
             response = ResponseGenerator(
                 data=output,
                 message="bank account data updated successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
    def put(self, id):
        """Update the Transaction type """

        try:
            data = request.get_json()
            result = transaction_type_schema.validate(data, partial=True)
            if result:
                logger.exception(result)
                response = ResponseGenerator(
                    data={},
                    message=result,
                    success=False,
                    status=status.HTTP_400_BAD_REQUEST)
                return response.error_response()
            transaction = TransactionType.query.filter(
                TransactionType.id == id).first()
            if transaction:
                transaction.transaction_type = data.get(
                    'transaction_type', transaction.transaction_type)
                db.session.commit()
                output = transaction_type_schema.dump(transaction)
                logger.info("transaction_type updated successfully")
                response = ResponseGenerator(
                    data=output,
                    message="transaction_type updated successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()
 def put(self, id):
     """Update the Branch Data """
     try:
         data = request.get_json()
         result = branch_detail_schema.validate(data, partial=True)
         if result:
             logger.exception(result)
             response = ResponseGenerator(
                 data={},
                 message=result,
                 success=False,
                 status=status.HTTP_400_BAD_REQUEST)
             return response.error_response()
         branch = BranchDetails.query.filter(BranchDetails.id == id).first()
         if branch:
             branch.branch_name = data.get('branch_name',
                                           branch.branch_name)
             branch.branch_address = data.get('branch_address',
                                              branch.branch_address)
             db.session.commit()
             output = branch_detail_schema.dump(branch)
             logger.info("Branch data updated successfully")
             response = ResponseGenerator(
                 data=output,
                 message="Branch data updated successfully",
                 success=True,
                 status=status.HTTP_200_OK)
             return response.success_response()
         else:
             raise IdNotFound('id not found:{}'.format(id))
     except IdNotFound as error:
         logger.exception(error.message)
         response = ResponseGenerator(data={},
                                      message=error.message,
                                      success=False,
                                      status=status.HTTP_404_NOT_FOUND)
         return response.error_response()
     except Exception as error:
         logger.exception(error)
         response = ResponseGenerator(data={},
                                      message=error,
                                      success=False,
                                      status=status.HTTP_400_BAD_REQUEST)
         return response.error_response()
    def put(self, id):
        """Update the fund transfer """

        try:
            data = request.get_json()
            result = fund_transfer_schema.validate(data, partial=True)
            if result:
                logger.exception(result)
                response = ResponseGenerator(
                    data={},
                    message=result,
                    success=False,
                    status=status.HTTP_400_BAD_REQUEST)
                return response.error_response()
            fund = FundTransfer.query.filter(FundTransfer.id == id).first()
            if fund:
                fund.source = data.get('from_account', fund.from_account)
                fund.destination = data.get('to_account', fund.to_account)
                db.session.commit()
                output = fund_transfer_schema.dump(fund)
                logger.info("fund transfer updated successfully")
                response = ResponseGenerator(
                    data=output,
                    message="fund transfer updated successfully",
                    success=True,
                    status=status.HTTP_200_OK)
                return response.success_response()
            else:
                raise IdNotFound('id not found:{}'.format(id))
        except IdNotFound as error:
            logger.exception(error.message)
            response = ResponseGenerator(data={},
                                         message=error.message,
                                         success=False,
                                         status=status.HTTP_404_NOT_FOUND)
            return response.error_response()
        except Exception as error:
            logger.exception(error)
            response = ResponseGenerator(data={},
                                         message=error,
                                         success=False,
                                         status=status.HTTP_400_BAD_REQUEST)
            return response.error_response()