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

Master #2

Merged
merged 5 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
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
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
/.idea/*.xml
*.iws
*.iml
*.ipr
/.idea/
.gitignore

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
10 changes: 5 additions & 5 deletions src/main/java/io/github/pitzzahh/Atm.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
public class Atm {
private static final ClientService CLIENT_SERVICE = new ClientService();
@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) {
final Scanner scanner = new Scanner(System.in);
CLIENT_SERVICE.setDataSource().accept(ClientService.getDataSource());
Expand All @@ -36,14 +37,13 @@ public static void main(String[] args) {
System.out.println(RED_BOLD_BRIGHT + runtimeException.getMessage() + RESET);
}
}

}

/**
* The automated teller machine that handles most of the process.
*/
static class Machine {
private static final String $a = "?cl0m0#sq3s/q"; // @dm1n1$tr4t0r
private static final String $adm = "?cl0m0#sq3s/q";
private static String $an;
/**
* Searches the {@code Hashtable<String, Client>}, checks if the account number exists.
Expand Down Expand Up @@ -116,7 +116,7 @@ private static void createClient(Scanner scanner) throws IllegalArgumentExceptio

/**
* method for asking for user details.
* @param scanner the scanner needed for keynoard input.
* @param scanner the scanner needed for keyboard input.
* @return a {@code Client} object.
* @throws IllegalArgumentException if any of the input is not valid.
*/
Expand Down Expand Up @@ -207,7 +207,7 @@ public static Status removeClient(Scanner scanner) {
System.out.println(RED_BOLD_BRIGHT + "ENTER ACCOUNT NUMBER TO REMOVE: ");
System.out.print(PURPLE_BOLD + ">>>: " + RESET);
$an = scanner.nextLine().trim();
return CLIENT_SERVICE.removeClientByAccountNumber().apply(SecurityUtil.encrypt($an));
return CLIENT_SERVICE.removeClientByAccountNumber().apply($an);
}

/**
Expand Down Expand Up @@ -322,7 +322,7 @@ private static Role home(Scanner scanner) throws IllegalArgumentException, Illeg
System.out.println(YELLOW_BRIGHT + "ENTER YOUR ACCOUNT NUMBER" + RESET);
System.out.print(RED_BOLD_BRIGHT + ">>>: " + RESET);
var input = scanner.nextLine().trim();
if (input.equals(SecurityUtil.decrypt(Machine.$a))) return Role.ADMIN;
if (input.equals(SecurityUtil.decrypt(Machine.$adm))) return Role.ADMIN;
if (Validator.isDecimalNumber().test(input)) throw new IllegalArgumentException("\nACCOUNT NUMBER IS A WHOLE NUMBER\n");
if (Validator.isWholeNumber().negate().test(input)) throw new IllegalArgumentException("\nACCOUNT NUMBER IS A NUMBER\n");
var result = Machine.searchAccount(input);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/github/pitzzahh/dao/Queries.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static com.github.pitzzahh.utilities.classes.enums.Status.*;

// TODO: create a test for this.
// TODO: implement updateClientAttemptsByAccountNumberQuery() and updateClientSavingsByAccountNumberQuery()
public class Queries {

public static Supplier<List<Optional<Client>>> getAllClientsQuery(JdbcTemplate jdbc) {
Expand All @@ -20,13 +19,13 @@ public static Supplier<List<Optional<Client>>> getAllClientsQuery(JdbcTemplate j

public static Optional<Client> getClientByAccountNumberQuery(String $an, JdbcTemplate jdbc) {
try {
return jdbc.queryForObject("SELECT * FROM clients WHERE account_number = ?", new Object[]{SecurityUtil.encrypt($an)}, new ClientMapper());
return jdbc.queryForObject("SELECT * FROM clients WHERE account_number = ?", new ClientMapper(), SecurityUtil.encrypt($an));
} catch (EmptyResultDataAccessException ignored) {}
return Optional.empty();
}

public static Status removeClientByAccountNumberQuery(String $an, JdbcTemplate jdbc) {
return jdbc.update("DELETE FROM clients WHERE account_number = ?", $an) > 0 ? SUCCESS : ERROR;
return jdbc.update("DELETE FROM clients WHERE account_number = ?", SecurityUtil.encrypt($an)) > 0 ? SUCCESS : ERROR;
}

public static Status updateClientAttemptsByAccountNumberQuery(String an, String at, JdbcTemplate jdbc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public interface DatabaseConnection {

/**
* Setup the datasource.
* Set up the datasource.
* @see ClientService
* @return the datasource.
*/
Expand Down