Code Monkey home page Code Monkey logo

automated-teller-machine-api's Introduction

automated-teller-machine-API

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

GitHub Issues Forks Stars License


Quickstart

How to use the API

  • With Database (can use any DBMS)
import io.github.pitzzahh.atm.database.DatabaseConnection;
import io.github.pitzzahh.atm.dao.InDatabase;
import io.github.pitzzahh.atm.service.AtmService;
import io.github.pitzzahh.atm.dao.AtmDAO;

public class App {
    private static final AtmDAO ATM_DAO = new InDatabase();
    private static final DatabaseConnection DATABASE_CONNECTION = new DatabaseConnection();

    public static void main(String[] args) {
        AtmService atmService = new AtmService(ATM_DAO);
        atmService.setDataSource().accept(
                DATABASE_CONNECTION
                        .setDriverClassName("org.postgresql.Driver")
                        .setUrl("jdbc:postgresql://localhost/{database_name}")
                        .setUsername("{username}")
                        .setPassword("{password}")
                        .getDataSource()
        );
    }
}

  • Without Database (in-memory)
import io.github.pitzzahh.atm.service.AtmService;
import io.github.pitzzahh.atm.dao.InMemory;

public class App {

    public static void main(String[] args) {
        AtmService atmService = new AtmService(new InMemory()); 
    }
}

Saving clients

To save a client object, a method called saveClient() in AtmService is used. It is a Function that accepts a Client Object.

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 a Client object, throws IllegalArgumentException if account number does not belong to any client.
Client client = atmService.getClientByAccountNumber().apply("123123123");
// prints the client (using Print class from util-classes-API)
println(client);
// removes the client by account number
atmService.removeClientByAccountNumber().apply("123123123");

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.

// getting client by account number
Client client = atmService.getClientByAccountNumber().apply("123123123");
// 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.

// removes the client by account number
atmService.removeClientByAccountNumber().apply("123123123");
// removes all the clients
atmService.removeAllClients();

Add Maven Dependency

maven-central

If you use Maven, add the following configuration to your project's pom.xml

Be sure to replace the VERSION key below with the one of the versions shown above

<dependencies>

    <!-- other dependencies are there -->
    <dependency>
        <groupId>io.github.pitzzahh</groupId>
        <artifactId>automated-teller-machine-API</artifactId>
        <version>VERSION</version>
    </dependency>
    <!-- other dependencies are there -->

</dependencies>

Others

Dependencies

automated-teller-machine-api's People

Contributors

dependabot[bot] avatar pitzzahh avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

automated-teller-machine-api's Issues

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

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()));
        };
    }

Should throw informational exception when client is not found when getClientByAccountNumber() is invoked

When the client is not found, it throws

Exception in thread "main" org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
	at org.springframework.dao.support.DataAccessUtils.nullableSingleResult(DataAccessUtils.java:97)
	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:887)
	at io.github.pitzzahh.atm.dao.AtmDAOImplementation.lambda$getClientByAccountNumber$3(AtmDAOImplementation.java:81)
	at App.main(App.java:47)

which is valid but not much info about it.

Outdated comment

The comments forgetClientByAccountNumber() found in AtmDAO, AtmDAOImplementation, and AtmService does not contain the latest info about the method changes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.