Skip to content
Open
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
1 change: 0 additions & 1 deletion .idea/FullStack.MicroWebApplication-Server.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/main/java/runner/controllers/AccountController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package runner.controllers;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -7,10 +8,11 @@
import runner.entities.Account;
import runner.entities.Transaction;
import runner.services.AccountServices;
import runner.services.CustomerServices;
import runner.views.Views;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;


@RequestMapping("/myaccount")
@RestController
Expand All @@ -28,12 +30,14 @@ public String testJWT() {
}

//get accounts for the authenticated user only, THIS is the homepage once user has logged in
@JsonView(Views.AllAccounts.class)
@GetMapping
public ResponseEntity<Set<Account>> readAllAccount() {
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
return new ResponseEntity<>(accountServices.getAllAccounts(currentPrincipalName), HttpStatus.OK);
}

@JsonView(Views.AccountSpecific.class)
@GetMapping(value = "/{accountEncryptedUrl}")
public ResponseEntity<Account> readAccountById(@PathVariable String accountEncryptedUrl){
return new ResponseEntity<>(accountServices.findAccountByEncryptedUrl(accountEncryptedUrl), HttpStatus.OK);
Expand Down
22 changes: 8 additions & 14 deletions src/main/java/runner/controllers/CustomerController.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package runner.controllers;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
Expand All @@ -9,8 +10,7 @@
import runner.entities.Address;
import runner.entities.Customer;
import runner.services.CustomerServices;


import runner.views.Views;
import java.net.URI;
import java.util.logging.Logger;

Expand All @@ -23,9 +23,9 @@ public class CustomerController {

private final static Logger logger = Logger.getLogger(CustomerController.class.getName());


@JsonView(Views.Profile.class)
@GetMapping
public ResponseEntity<?> readById() {
public ResponseEntity<?> getCustomer() {
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
Customer customer =customerServices.readCustomerByLogin(currentPrincipalName);
if( customer == null)
Expand Down Expand Up @@ -62,6 +62,7 @@ public ResponseEntity<Customer> update(@RequestBody Customer customer) throws Ex
return new ResponseEntity<>(customerServices.updateCustomer(id,customer), HttpStatus.OK);
}

@JsonView(Views.PhoneNumber.class)
@PutMapping(value = "/update/phone")
public ResponseEntity<?> updatePhone(@RequestBody String phoneNumber) throws Exception {
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
Expand All @@ -77,6 +78,7 @@ else if(response == 1 )

}

@JsonView(Views.Email.class)
@PutMapping(value = "/update/email")
public ResponseEntity<?> updateEmail(@RequestBody String email) throws Exception {
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
Expand All @@ -92,6 +94,7 @@ else if(response == 1 )

}

@JsonView(Views.Address.class)
@PutMapping(value = "/update/address")
public ResponseEntity<?> updateEmail(@RequestBody Address address) throws Exception {
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
Expand All @@ -103,6 +106,7 @@ public ResponseEntity<?> updateEmail(@RequestBody Address address) throws Except
else
return new ResponseEntity<>(customerServices.readCustomer(id), HttpStatus.OK);
}

@DeleteMapping(value = "/delete")
public ResponseEntity<?> deleteById() {
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
Expand All @@ -117,14 +121,4 @@ else if(flag==2)
return new ResponseEntity<>("No accounts/user found", HttpStatus.NOT_FOUND);
}

@GetMapping(value = "/accounts")
public ResponseEntity<?> getAllAccounts(){
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
Customer customerReturned =customerServices.readCustomerByLogin(currentPrincipalName);
Long id = customerReturned.getId();
if(customerServices.getAllAccounts(id) == null)
return new ResponseEntity<>("Customer not found", HttpStatus.NOT_FOUND);
else
return new ResponseEntity<>(customerServices.getAllAccounts(id), HttpStatus.OK);
}
}
20 changes: 19 additions & 1 deletion src/main/java/runner/entities/Account.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package runner.entities;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonView;
import runner.enums.AccountType;
import runner.views.Views;

import javax.persistence.*;
import java.time.LocalDate;

Expand All @@ -15,15 +18,30 @@ public class Account {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@JsonView(Views.AccountNumber.class)
private String accountNumber;
private String routingNumber;

@JsonView(Views.AccountDetails.class)
private String routingNumber = "091000022";

@JsonView(Views.AccountType.class)
@Enumerated(EnumType.STRING)
private AccountType accountType; //enum

@JsonView(Views.AccountActions.class)
private Double balance;

@JsonView(Views.AccountDetails.class)
private LocalDate dateOfOpening;

@JsonView(Views.AccountDetails.class)
private Double interestRate;

@JsonView(Views.AllAccounts.class) //delete this later in production
private String encryptedUrl;

@JsonView(Views.AccountSpecific.class)
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "account_transaction",
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/runner/entities/Address.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package runner.entities;

import com.fasterxml.jackson.annotation.JsonView;
import runner.views.Views;

import javax.persistence.*;

@Entity
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@JsonView(Views.Address.class)
@Column(nullable = false)
private String firstLine;
@Column(nullable = true)
@JsonView(Views.Address.class)
private String secondLIne;
@Column(nullable = false)
@JsonView(Views.Address.class)
private String city;
@Column(nullable = false)
@JsonView(Views.Address.class)
private String state;
@Column(nullable = false)
@JsonView(Views.Address.class)
private String zipcode;

public Long getId() {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/runner/entities/Customer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package runner.entities;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonView;
import runner.views.Views;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.Set;
Expand All @@ -12,20 +15,31 @@ public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@JsonView(Views.Profile.class)
@Column(nullable = false)
private String firstName;

@JsonView(Views.Profile.class)
private String middleName;
@JsonView(Views.Profile.class)
@Column(nullable = false)
private String lastName;
@JsonView(Views.Profile.class)
@Column(nullable = false)
private LocalDate dateOfBirth;

@Column(nullable = false)
private String socialSecurity;

@Column(nullable = false)
@JsonView(Views.Email.class)
private String email;

@JsonView(Views.PhoneNumber.class)
@Column(nullable = false)
private String phoneNumber;

@JsonView(Views.Address.class)
@OneToOne(cascade = ALL, fetch = FetchType.EAGER)
private Address address;
@JsonBackReference(value = "login")
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/runner/entities/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import runner.views.Views;

import javax.persistence.*;
import java.util.Collection;
Expand All @@ -15,8 +17,11 @@ public class Login implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

@JsonView(Views.Profile.class)
@Column(nullable = false)
private String username;

@Column(nullable = false)
private String password;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/runner/services/AccountServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Set<Account> getAllAccounts(String username){

public Account createAccount(Account account) {
loggerService.log(Level.INFO, "The customer's new account is being saved");
account.setAccountNumber(String.valueOf((Math.floor(Math.random()*1000000000))));
return accountRepo.save(account);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/runner/services/CustomerServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Customer createCustomer(Customer customer) {
public Boolean checkLogin(Login login) {

List<String> logins= customerRepo.findAllLoginsNative();
long count = logins.stream().filter(name -> name.equals(login.getUsername())).count();
long count = logins.stream().filter(name -> name.equalsIgnoreCase(login.getUsername())).count();
return count!=0 ? true:false;
}

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/runner/views/Views.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package runner.views;

public class Views {

public static interface AccountNumber{

}

public static interface AccountType{

}

public static class AllAccounts implements AccountNumber, AccountType{
/*
payload: multiple accounts: account number, account balance, account type
*/
}

public static interface AccountActions{
/*
payload: account balance
*/
}

public static class AccountDetails implements AccountNumber, AccountType, AccountActions{
/*
payload: account balance, interest rate, date of creation, account number, routing number, account type
*/
}

public static class AccountSpecific implements AccountActions{
/*
payload: account balance, transactions
*/
}

public static interface Email{
}

public static interface PhoneNumber{
}

public static interface Address{
}

public static class Profile implements Email, PhoneNumber, Address {
}

}
Binary file modified target/classes/runner/controllers/AccountController.class
Binary file not shown.
Binary file modified target/classes/runner/controllers/CustomerController.class
Binary file not shown.
Binary file modified target/classes/runner/entities/Account.class
Binary file not shown.
Binary file modified target/classes/runner/entities/Address.class
Binary file not shown.
Binary file modified target/classes/runner/entities/Customer.class
Binary file not shown.
Binary file modified target/classes/runner/entities/Login.class
Binary file not shown.
Binary file modified target/classes/runner/repositories/AccountRepo.class
Binary file not shown.
Binary file modified target/classes/runner/services/AccountServices.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added target/classes/runner/views/Views$AccountType.class
Binary file not shown.
Binary file added target/classes/runner/views/Views$Address.class
Binary file not shown.
Binary file added target/classes/runner/views/Views$AllAccounts.class
Binary file not shown.
Binary file added target/classes/runner/views/Views$Email.class
Binary file not shown.
Binary file added target/classes/runner/views/Views$PhoneNumber.class
Binary file not shown.
Binary file added target/classes/runner/views/Views$Profile.class
Binary file not shown.
Binary file added target/classes/runner/views/Views.class
Binary file not shown.