Skip to content

Commit

Permalink
Merge pull request #15 from pitzzahh/patches
Browse files Browse the repository at this point in the history
Patches [v1.0.2]
  • Loading branch information
pitzzahh committed Aug 12, 2022
2 parents 842f2f6 + 4bb79da commit fa033b6
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 135 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ API used for making atm applications (none-web-app)
![Forks](https://img.shields.io/github/forks/pitzzahh/automated-teller-machine-console)
![Stars](https://img.shields.io/github/stars/pitzzahh/automated-teller-machine-console)
![License](https://img.shields.io/github/license/pitzzahh/automated-teller-machine-console)
![Stable Release](https://img.shields.io/badge/version-1.0.1-blue)
![Stable Release](https://img.shields.io/badge/version-1.0.2-blue)
________________________________________
## Quickstart
### How to use the API
Expand Down Expand Up @@ -141,7 +141,7 @@ If you use Maven, add the following configuration to your project's `pom.xml`
<dependency>
<groupId>io.github.pitzzahh</groupId>
<artifactId>automated-teller-machine-API</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
<!-- other dependencies are there -->
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

<groupId>io.github.pitzzahh</groupId>
<artifactId>automated-teller-machine-API</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>

<properties>
<maven.test.skip>true</maven.test.skip>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/pitzzahh/atm/dao/AtmDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public interface AtmDAO {
* <p>T - a {@code String} containing the account number to be search from the database.</p>
* <p>R - a {@code Optional<Client>} containing the result if the client is found or not.</p>
* @return a {@code Optional<Client>} object.
* @throws IllegalArgumentException if the account number does not belong to any client.
* @see Function
* @see Optional
* @see Client
*/
Function<String, Optional<Client>> getClientByAccountNumber();
Function<String, Client> getClientByAccountNumber() throws IllegalArgumentException;

/**
* Function that accepts a {@code String} containing the account number.
Expand Down
38 changes: 18 additions & 20 deletions src/main/java/io/github/pitzzahh/atm/dao/AtmDAOImplementation.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.pitzzahh.atm.dao;

import java.sql.SQLException;
import java.util.*;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.function.Function;
Expand Down Expand Up @@ -69,14 +69,20 @@ public Supplier<Map<String, Client>> getAllClients() {
* <p>T - a {@code String} containing the account number to be search from the database.</p>
* <p>R - a {@code Optional<Client>} containing the result if the client is found or not.</p>
* @return a {@code Optional<Client>} object.
* @throws IllegalArgumentException if the account number does not belong to any client.
* @see Function
* @see Optional
* @see Client
*/
@Override
public Function<String, Optional<Client>> getClientByAccountNumber() {
public Function<String, Client> getClientByAccountNumber() throws IllegalArgumentException {
final var QUERY = "SELECT * FROM clients WHERE account_number = ?";
return an -> Optional.ofNullable(db.queryForObject(QUERY, new ClientMapper(), SecurityUtil.encrypt(an)));
return an -> {
try {
return db.queryForObject(QUERY, new ClientMapper(), SecurityUtil.encrypt(an));
} catch (RuntimeException ignored) {
throw new IllegalArgumentException(String.format("CLIENT WITH ACCOUNT NUMBER: %s DOES NOT EXIST", an));
}
};
}

/**
Expand Down Expand Up @@ -299,15 +305,16 @@ public Function<String, Integer> getLoanCount() {
* Function that approves a loan request.
* The function takes a {@code Loan} object containing the loan information to be approved.
* @return a {@code Status} of the query wether {@link Status#SUCCESS} or {@link Status#ERROR}.
* @throws IllegalArgumentException if the account number does not belong to any client, thus the message cannot be found.
* @see BiFunction
* @see Loan
* @see Status
*/
@Override
public BiFunction<Loan, Client, Status> approveLoan() {
public BiFunction<Loan, Client, Status> approveLoan() throws IllegalArgumentException {
final var QUERY = "UPDATE loans SET pending = ? WHERE loan_number = ? AND account_number = ?";
return (loan, c) -> {
var client = getClientByAccountNumber().apply(c.accountNumber()).get();
var client = getClientByAccountNumber().apply(c.accountNumber());
var status = updateClientSavingsByAccountNumber().apply(client.accountNumber(), client.savings() + loan.amount());
return status == SUCCESS ? db.update(
QUERY,
Expand Down Expand Up @@ -372,19 +379,17 @@ public Supplier<Status> removeAllLoans() {
* 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.
* @throws IllegalArgumentException if the account number does not belong to any client.
* @throws IllegalStateException if there are no messages for the client.
* @see Function
* @see Map
* @see List
* @see Message
*/
@Override
public Function<String, Map<String, List<Message>>> getMessage() {
public Function<String, Map<String, List<Message>>> getMessage() throws IllegalArgumentException, IllegalStateException {
return accountNumber -> {
var clients = getAllClients().get()
.entrySet()
.stream()
.map(Map.Entry::getValue)
.toList();
var client = getClientByAccountNumber().apply(accountNumber);
var check = getAllLoans()
.get()
.entrySet()
Expand All @@ -400,14 +405,7 @@ public Function<String, Map<String, List<Message>>> getMessage() {
.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()
);
return new Message(loan, client, loan.pending() && loan.isDeclined());
})
.collect(Collectors.groupingBy(message -> message.loan().accountNumber()));
};
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/io/github/pitzzahh/atm/service/AtmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import java.util.function.Supplier;
import java.util.function.BiFunction;
import io.github.pitzzahh.atm.dao.AtmDAO;
import io.github.pitzzahh.atm.database.DatabaseConnection;
import io.github.pitzzahh.atm.entity.Loan;
import io.github.pitzzahh.atm.entity.Client;
import io.github.pitzzahh.atm.entity.Message;
import io.github.pitzzahh.atm.dao.AtmDAOImplementation;
import com.github.pitzzahh.utilities.classes.enums.Status;
import io.github.pitzzahh.atm.database.DatabaseConnection;

/**
* The service for overall functionality..
Expand Down Expand Up @@ -71,11 +71,11 @@ public Supplier<Map<String, Client>> getAllClients() {
* <p>T - a {@code String} containing the account number to be search from the database.</p>
* <p>R - a {@code Optional<Client>} containing the result if the client is found or not.</p>
* @return a {@code Optional<Client>} object.
* @throws IllegalArgumentException if the account number does not belong to any client.
* @see Function
* @see Optional
* @see Client
*/
public Function<String, Optional<Client>> getClientByAccountNumber() {
public Function<String, Client> getClientByAccountNumber() throws IllegalArgumentException {
return atmDAO.getClientByAccountNumber();
}

Expand Down Expand Up @@ -259,12 +259,14 @@ public Supplier<Status> removeAllLoans() {
* 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.
* @throws IllegalArgumentException if the account number does not belong to any client.
* @throws IllegalStateException if there are no messages for the client.
* @see Function
* @see Map
* @see List
* @see Message
*/
public Function<String, Map<String, List<Message>>> getMessage() {
public Function<String, Map<String, List<Message>>> getMessage() throws IllegalArgumentException, IllegalStateException {
return atmDAO.getMessage();
}
}
68 changes: 0 additions & 68 deletions src/test/java/io/github/pitzzahh/entity/ClientTest.java

This file was deleted.

Loading

0 comments on commit fa033b6

Please sign in to comment.