pitzzahh / automated-teller-machine-API

API used for making atm applications (none-web-app)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If account number is not an existing client. No error thrown in getting the message

pitzzahh opened this issue · comments

bug is in the getMessage() method of AtmDAOImplementation class

    /**
     * Function that gets the message of the loan requst of a client to the database.
     * The Function takes a {@code String}.
     * The {@code String} contains the account number of the client.
     * @return a {@code Message} object containg the message of the loan.
     * @see Function
     * @see Map
     * @see List
     * @see Message
     */
    @Override
    public Function<String, Map<String, List<Message>>> getMessage() {
        return accountNumber -> {
            var clients = getAllClients().get()
                    .entrySet()
                    .stream()
                    .map(Map.Entry::getValue)
                    .toList();
            var check = getAllLoans()
                    .get()
                    .entrySet()
                    .stream()
                    .map(Map.Entry::getValue)
                    .flatMap(Collection::stream)
                    .allMatch(a -> a.accountNumber().equals(accountNumber) && ( a.pending() && !a.isDeclined() ));
            if (check) throw new IllegalStateException("THERE ARE NO MESSAGES AT THE MOMENT");
            return getAllLoans().get()
                    .entrySet()
                    .stream()
                    .map(Map.Entry::getValue)
                    .flatMap(Collection::stream)
                    .filter(l -> !l.pending() || l.isDeclined())
                    .map(loan -> {
                        return new Message(
                                loan,
                                clients.stream()
                                        .filter(a -> a.accountNumber().equals(loan.accountNumber()))
                                        .findFirst()
                                        .get(),
                                loan.pending() && loan.isDeclined()
                        );
                    })
                    .collect(Collectors.groupingBy(message -> message.loan().accountNumber()));
        };
    }

fixed on commit: 98daccd