Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches [update README.md] #13

Merged
merged 3 commits into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# automated-teller-machine-API
An API for an atm application
API used for making atm applications (none-web-app)

![GitHub Issues](https://img.shields.io/github/issues/pitzzahh/automated-teller-machine-console)
![Forks](https://img.shields.io/github/forks/pitzzahh/automated-teller-machine-console)
Expand All @@ -8,6 +8,7 @@ An API for an atm application
![Stable Release](https://img.shields.io/badge/version-1.0.1-blue)
________________________________________
## Quickstart
### How to use the API
* connecting to a database

```java
Expand All @@ -34,7 +35,101 @@ public class App {
}
}
```
* saving clients to the database
```java
import io.github.pitzzahh.atm.database.DatabaseConnection;
import com.github.pitzzahh.utilities.classes.enums.Gender;
import com.github.pitzzahh.utilities.classes.Person;
import io.github.pitzzahh.atm.service.AtmService;
import io.github.pitzzahh.atm.entity.Client;
import com.github.pitzzahh.utilities.Print;
import io.github.pitzzahh.atm.dao.AtmDAO;
import java.time.LocalDate;
import java.util.Optional;
import java.time.Month;

public class App {

private static AtmDAO atmDAO;
private static AtmService atmService;
private static DatabaseConnection databaseConnection;

public static void main(String[] args) {
atmService = new AtmService(atmDAO, databaseConnection);
atmService.setDataSource().accept(atmService
.connection
.setDriverClassName("org.postgresql.Driver")
.setUrl("jdbc:postgresql://localhost/atm")
.setUsername("postgres")
.setPassword("!Password123")
.getDataSource()
);
// saving a client object to the clients table...
atmService.saveClient().apply(
new Client(
"123123123",
"123123",
new Person(
"Mark",
"Silent",
Gender.PREFER_NOT_TO_SAY,
"Earth",
LocalDate.of(2018, Month.AUGUST, 10)
),
5555,
false
)
);
// getting the client, returns an Optional<Client> because Client Object might be null.
Optional<Client> client = atmService.getClientByAccountNumber().apply("123123123");
// prints the client (using Print class from util-classes-API) or else throws an exception
client.ifPresentOrElse(Print::println, () -> new IllegalStateException("CLIENT WITH ACCOUNT NUMBER 123123123 DOES NOT EXIST"));
// removes the client by account number
atmService.removeClientByAccountNumber().apply("123123123");
}
}
```
To save a client object, a method called `saveClient()` in `AtmService` is used. It is a Function that accepts a Client Object.
```java
atmService.saveClient().apply(
new Client(
"123123123", // the account number
"123123", // the account pin
new Person(
"Mark", // the first name
"Silent", // the last name
Gender.PREFER_NOT_TO_SAY, // the gender
"Earth", // the address
LocalDate.of(2018, Month.AUGUST, 10) // the birth date
),
5555, // the initial account balance
false // false means the account is not locked, otherwise true if locked
)
);
```
To get the client from the database, there are two methods that can be used, first is `getClientByAccountNumber()` a method that accepts a
`String` containing an account number, second is `getAllClients()` a method that get all the client
as a `Supplier<Map<String, Client>>`.
Below shows the two ways on how to get a client/clients.
```java
// getting client by account number
Optional<Client> client = atmService.getClientByAccountNumber().apply("123123123");
```
```java
// getting all the clients.
Supplier<Map<String, Client> > clients = atmService.getAllClients();
```
To remove a client, there are also two methods that can be used, first is removing client by account number,
second is removing all the clients.
Below shows the two ways on how to remove a client/clients.
```java
// removes the client by account number
atmService.removeClientByAccountNumber().apply("123123123");
```
```java
// removes all the clients
atmService.removeAllClients();
```
### Add Maven Dependency

If you use Maven, add the following configuration to your project's `pom.xml`
Expand All @@ -52,3 +147,6 @@ If you use Maven, add the following configuration to your project's `pom.xml`

</dependencies>
```
### About
Dependencies
- [util-classes](https://github.com/pitzzahh/util-classes)