Skip to content

Commit

Permalink
service methods for accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsundin committed Jan 28, 2024
1 parent f1ce0d6 commit a405874
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/main/java/Service/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,45 @@
import Model.Account;
import DAO.AccountDAO;

import java.util.List;

public class AccountService {
AccountDAO accountDAO;

public AccountService(){
public AccountService() {
accountDAO = new AccountDAO();
}

public AccountService(AccountDAO accountDAO){
public AccountService(AccountDAO accountDAO) {
this.accountDAO = accountDAO;
}

public Account addAccount(Account account){
return accountDAO.insertAccount(account);
public Account addAccount(Account account) {
String username = account.getUsername();
String password = account.getPassword();
return accountDAO.insertAccount(username, password);
}

public boolean isValidCredentials(String username, String password) {
if (accountIsRegistered(username)) return false;
else if (username.isEmpty()) return false;
if (password.length() < 4) return false;
return true;
}

public boolean accountIsRegistered(String username) {
if (accountDAO.findAccountByUsername(username) != null) return true;
return false;
}

public Account login(String username, String password) {
Account registeredAccount = accountDAO.findAccountByUsername(username);
if (registeredAccount == null) return null;
if (!registeredAccount.getPassword().equals(password)) return null;
return registeredAccount;
}

public List<Account> getAllAccounts() {
return accountDAO.getAllAccounts();
}
}

0 comments on commit a405874

Please sign in to comment.