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

Added the Entities and their functions to perform the required operations #77

Open
wants to merge 5 commits into
base: flow
Choose a base branch
from
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Task 2 Starter Repo
Contains Everything you need to get started on task 2 of Forage's Wells Fargo software engineering program
# Investment Management System
- Developed relevant requirements for building a system to manage financial investment with Advisor, Client, Portfolio and Securities as the entities.
- Developed data the system needed to keep track of.

<p align="center">
<img src="https://github.com/user-attachments/assets/39897e10-25e2-48e1-b98c-927bda28bdc4" />
</p>
70 changes: 65 additions & 5 deletions src/main/java/com/wellsfargo/counselor/entity/Advisor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.wellsfargo.counselor.entity;


import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import java.time.LocalDate;
import java.util.*;
import jakarta.persistence.*;

@Entity
public class Advisor {
Expand All @@ -28,6 +26,10 @@ public class Advisor {
@Column(nullable = false)
private String email;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "advisorId")
private List<Client> clients = new ArrayList<>();

protected Advisor() {

}
Expand Down Expand Up @@ -83,4 +85,62 @@ public String getEmail() {
public void setEmail(String email) {
this.email = email;
}

public List<Client> getClients() {
return clients;
}

public void addClient(Client client) {
clients.add(client);
}

public Client createClient(String userName, String firstName, String lastName, String address, String phone, String email) {
Client client = new Client(userName, firstName, lastName, address, phone, email);
this.addClient(client);
return client;
}

public boolean updateClient(int clientId, String firstName, String lastName, String address, String phone, String email) {
for (Client client : clients) {
if (client.getClientId() == clientId) {
client.setFirstName(firstName);
client.setFirstName(lastName);
client.setFirstName(address);
client.setFirstName(phone);
client.setEmail(email);
return true;
}
}
return false;
}

public void removeClient(Client client) {
clients.remove(client);
}

public void createSecurityForClient(Client client, String securityName, String category, LocalDate purchaseDate, double purchasePrice, int quantity) {
Portfolio portfolio = client.getPortfolio();
portfolio.addSecurity(securityName, category, purchaseDate, purchasePrice, quantity);
}

public boolean updateSecurityForClient(Client client, int securityId, String securityName, String category, LocalDate purchaseDate, double purchasePrice, int quantity) {
Portfolio portfolio = client.getPortfolio();
for (Security security : portfolio.getSecurities()) {
if (security.getSecurityId() == securityId) {
security.setSecurityName(securityName);
security.setCategory(category);
security.setPurchaseDate(purchaseDate);
security.setPurchasePrice(purchasePrice);
security.setQuantity(quantity);
return true;
}
}
return false;
}

public boolean removeSecurityFromClient(Client client, int securityId) {
Portfolio portfolio = client.getPortfolio();
return portfolio.removeSecurityById(securityId);
}

}
102 changes: 102 additions & 0 deletions src/main/java/com/wellsfargo/counselor/entity/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.wellsfargo.counselor.entity;


import jakarta.persistence.*;

@Entity
public class Client {

@Id
@GeneratedValue()
private long clientId;

@Column(nullable = false)
private String userName;

@Column(nullable = false)
private String firstName;

@Column(nullable = false)
private String lastName;

@Column(nullable = false)
private String address;

@Column(nullable = false)
private String phone;

@Column(nullable = false)
private String email;

protected Client() {

}

public Client(String userName, String firstName, String lastName, String address, String phone, String email) {
this.userName = userName;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phone = phone;
this.email = email;
}

@OneToOne(cascade = CascadeType.ALL, mappedBy = "client")
private Portfolio portfolio;

public Long getClientId() {
return clientId;
}

public String getUserName() {
return userName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Portfolio getPortfolio() {
return this.portfolio;
}

public void setPortfolio() {
this.portfolio = new Portfolio();
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/wellsfargo/counselor/entity/Portfolio.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.wellsfargo.counselor.entity;

import java.time.LocalDate;
import java.util.*;

import jakarta.persistence.*;

@Entity
public class Portfolio {
@Id
@GeneratedValue()
private int id;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "portfolio", orphanRemoval = true)
private List<Security> securities = new ArrayList<>();

public List<Security> getSecurities() {
return this.securities;
};

public void addSecurity(String securityName, String category, LocalDate purchaseDate, double purchasePrice, int quantity) {
Security security = new Security(securityName, category, purchaseDate, purchasePrice, quantity);
securities.add(security);
}

public boolean removeSecurityById(int securityId) {
return securities.removeIf(security -> security.getSecurityId() == securityId);
}
}
86 changes: 86 additions & 0 deletions src/main/java/com/wellsfargo/counselor/entity/Security.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.wellsfargo.counselor.entity;

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

@Entity
public class Security {
@Id
@GeneratedValue()
private long securityId;

@Column(nullable = false)
private String securityName;

@Column(nullable = false)
private String category;

@Column(nullable = false)
private LocalDate purchaseDate;

@Column(nullable = false)
private double purchasePrice;

@Column(nullable = false)
private int quantity;

@ManyToOne
@JoinColumn(name = "portfolio_id", nullable = false)
private Portfolio portfolio;

protected Security() {

}

public Security(String securityName, String category, LocalDate purchaseDate, double purchasePrice, int quantity) {
this.securityName = securityName;
this.category = category;
this.purchaseDate = purchaseDate;
this.purchasePrice = purchasePrice;
this.quantity = quantity;
}

public Long getSecurityId() {
return this.securityId;
}

public String getSecurityName() {
return this.securityName;
}

public void setSecurityName(String securityName) {
this.securityName = securityName;
}

public String getCategory() {
return this.category;
}

public void setCategory(String category) {
this.category = category;
}

public LocalDate getPusrchaseDate() {
return this.purchaseDate;
}

public void setPurchaseDate(LocalDate purchaseDate) {
this.purchaseDate = purchaseDate;
}

public double getPurchasePrice() {
return this.purchasePrice;
}

public void setPurchasePrice(double purchasePrice) {
this.purchasePrice = purchasePrice;
}

public int getQuantity() {
return this.quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}
}