diff --git a/.idea/FullStack.MicroWebApplication-Server.iml b/.idea/FullStack.MicroWebApplication-Server.iml
index eb02fb50d..61d2df724 100644
--- a/.idea/FullStack.MicroWebApplication-Server.iml
+++ b/.idea/FullStack.MicroWebApplication-Server.iml
@@ -15,7 +15,6 @@
-
diff --git a/src/main/java/runner/controllers/AccountController.java b/src/main/java/runner/controllers/AccountController.java
index e82577019..20cc7c6cf 100644
--- a/src/main/java/runner/controllers/AccountController.java
+++ b/src/main/java/runner/controllers/AccountController.java
@@ -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;
@@ -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
@@ -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> readAllAccount() {
String currentPrincipalName = SecurityContextHolder.getContext().getAuthentication().getName();
return new ResponseEntity<>(accountServices.getAllAccounts(currentPrincipalName), HttpStatus.OK);
}
+ @JsonView(Views.AccountSpecific.class)
@GetMapping(value = "/{accountEncryptedUrl}")
public ResponseEntity readAccountById(@PathVariable String accountEncryptedUrl){
return new ResponseEntity<>(accountServices.findAccountByEncryptedUrl(accountEncryptedUrl), HttpStatus.OK);
diff --git a/src/main/java/runner/controllers/CustomerController.java b/src/main/java/runner/controllers/CustomerController.java
index 116b24780..6080fc41c 100644
--- a/src/main/java/runner/controllers/CustomerController.java
+++ b/src/main/java/runner/controllers/CustomerController.java
@@ -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;
@@ -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;
@@ -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)
@@ -62,6 +62,7 @@ public ResponseEntity 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();
@@ -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();
@@ -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();
@@ -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();
@@ -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);
- }
}
\ No newline at end of file
diff --git a/src/main/java/runner/entities/Account.java b/src/main/java/runner/entities/Account.java
index 6f921ce2a..ae67915da 100644
--- a/src/main/java/runner/entities/Account.java
+++ b/src/main/java/runner/entities/Account.java
@@ -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;
@@ -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",
diff --git a/src/main/java/runner/entities/Address.java b/src/main/java/runner/entities/Address.java
index a92522a86..295605517 100644
--- a/src/main/java/runner/entities/Address.java
+++ b/src/main/java/runner/entities/Address.java
@@ -1,5 +1,8 @@
package runner.entities;
+import com.fasterxml.jackson.annotation.JsonView;
+import runner.views.Views;
+
import javax.persistence.*;
@Entity
@@ -7,15 +10,20 @@ 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() {
diff --git a/src/main/java/runner/entities/Customer.java b/src/main/java/runner/entities/Customer.java
index edafbc743..7f48ddb3a 100644
--- a/src/main/java/runner/entities/Customer.java
+++ b/src/main/java/runner/entities/Customer.java
@@ -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;
@@ -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")
diff --git a/src/main/java/runner/entities/Login.java b/src/main/java/runner/entities/Login.java
index 7d946331b..a357121a2 100644
--- a/src/main/java/runner/entities/Login.java
+++ b/src/main/java/runner/entities/Login.java
@@ -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;
@@ -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;
diff --git a/src/main/java/runner/services/AccountServices.java b/src/main/java/runner/services/AccountServices.java
index fc870471b..6390e7ccf 100644
--- a/src/main/java/runner/services/AccountServices.java
+++ b/src/main/java/runner/services/AccountServices.java
@@ -24,6 +24,7 @@ public Set 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);
}
diff --git a/src/main/java/runner/services/CustomerServices.java b/src/main/java/runner/services/CustomerServices.java
index 08746c4b9..a2106e1b8 100644
--- a/src/main/java/runner/services/CustomerServices.java
+++ b/src/main/java/runner/services/CustomerServices.java
@@ -48,7 +48,7 @@ public Customer createCustomer(Customer customer) {
public Boolean checkLogin(Login login) {
List 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;
}
diff --git a/src/main/java/runner/views/Views.java b/src/main/java/runner/views/Views.java
new file mode 100644
index 000000000..37c1ff241
--- /dev/null
+++ b/src/main/java/runner/views/Views.java
@@ -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 {
+ }
+
+}
diff --git a/target/classes/runner/controllers/AccountController.class b/target/classes/runner/controllers/AccountController.class
index dec6b332c..8a99e4818 100644
Binary files a/target/classes/runner/controllers/AccountController.class and b/target/classes/runner/controllers/AccountController.class differ
diff --git a/target/classes/runner/controllers/CustomerController.class b/target/classes/runner/controllers/CustomerController.class
index 2bac0399d..b778e38fb 100644
Binary files a/target/classes/runner/controllers/CustomerController.class and b/target/classes/runner/controllers/CustomerController.class differ
diff --git a/target/classes/runner/entities/Account.class b/target/classes/runner/entities/Account.class
index 3b1d8ea93..d8cdb0f15 100644
Binary files a/target/classes/runner/entities/Account.class and b/target/classes/runner/entities/Account.class differ
diff --git a/target/classes/runner/entities/Address.class b/target/classes/runner/entities/Address.class
index 87d6aa6e9..e9f4a0202 100644
Binary files a/target/classes/runner/entities/Address.class and b/target/classes/runner/entities/Address.class differ
diff --git a/target/classes/runner/entities/Customer.class b/target/classes/runner/entities/Customer.class
index e9df4b91c..a2a655f4a 100644
Binary files a/target/classes/runner/entities/Customer.class and b/target/classes/runner/entities/Customer.class differ
diff --git a/target/classes/runner/entities/Login.class b/target/classes/runner/entities/Login.class
index 8383afc3e..5afbda332 100644
Binary files a/target/classes/runner/entities/Login.class and b/target/classes/runner/entities/Login.class differ
diff --git a/target/classes/runner/repositories/AccountRepo.class b/target/classes/runner/repositories/AccountRepo.class
index 365d7c449..076181a9c 100644
Binary files a/target/classes/runner/repositories/AccountRepo.class and b/target/classes/runner/repositories/AccountRepo.class differ
diff --git a/target/classes/runner/services/AccountServices.class b/target/classes/runner/services/AccountServices.class
index bb5d84495..8548a25a6 100644
Binary files a/target/classes/runner/services/AccountServices.class and b/target/classes/runner/services/AccountServices.class differ
diff --git a/target/classes/runner/views/Views$AccountActions.class b/target/classes/runner/views/Views$AccountActions.class
new file mode 100644
index 000000000..9eea03fa7
Binary files /dev/null and b/target/classes/runner/views/Views$AccountActions.class differ
diff --git a/target/classes/runner/views/Views$AccountDetails.class b/target/classes/runner/views/Views$AccountDetails.class
new file mode 100644
index 000000000..c6649830b
Binary files /dev/null and b/target/classes/runner/views/Views$AccountDetails.class differ
diff --git a/target/classes/runner/views/Views$AccountNumber.class b/target/classes/runner/views/Views$AccountNumber.class
new file mode 100644
index 000000000..e1a6befdc
Binary files /dev/null and b/target/classes/runner/views/Views$AccountNumber.class differ
diff --git a/target/classes/runner/views/Views$AccountSpecific.class b/target/classes/runner/views/Views$AccountSpecific.class
new file mode 100644
index 000000000..49768f12f
Binary files /dev/null and b/target/classes/runner/views/Views$AccountSpecific.class differ
diff --git a/target/classes/runner/views/Views$AccountType.class b/target/classes/runner/views/Views$AccountType.class
new file mode 100644
index 000000000..bec16886c
Binary files /dev/null and b/target/classes/runner/views/Views$AccountType.class differ
diff --git a/target/classes/runner/views/Views$Address.class b/target/classes/runner/views/Views$Address.class
new file mode 100644
index 000000000..3e3d188de
Binary files /dev/null and b/target/classes/runner/views/Views$Address.class differ
diff --git a/target/classes/runner/views/Views$AllAccounts.class b/target/classes/runner/views/Views$AllAccounts.class
new file mode 100644
index 000000000..b84c53035
Binary files /dev/null and b/target/classes/runner/views/Views$AllAccounts.class differ
diff --git a/target/classes/runner/views/Views$Email.class b/target/classes/runner/views/Views$Email.class
new file mode 100644
index 000000000..7a871efc1
Binary files /dev/null and b/target/classes/runner/views/Views$Email.class differ
diff --git a/target/classes/runner/views/Views$PhoneNumber.class b/target/classes/runner/views/Views$PhoneNumber.class
new file mode 100644
index 000000000..660f91a58
Binary files /dev/null and b/target/classes/runner/views/Views$PhoneNumber.class differ
diff --git a/target/classes/runner/views/Views$Profile.class b/target/classes/runner/views/Views$Profile.class
new file mode 100644
index 000000000..cd29d30cb
Binary files /dev/null and b/target/classes/runner/views/Views$Profile.class differ
diff --git a/target/classes/runner/views/Views.class b/target/classes/runner/views/Views.class
new file mode 100644
index 000000000..746a9ede2
Binary files /dev/null and b/target/classes/runner/views/Views.class differ