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

Implemented data model and configured database #85

Open
wants to merge 1 commit 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
41 changes: 41 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,41 @@
package com.wellsfargo.counselor.entity;

import jakarta.persistence.*;

@Entity
public class Client {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long clientId;

private String name;
private String email;
private String phoneNumber;

@ManyToOne
@JoinColumn(name = "advisor_id", nullable = false)
private FinancialAdvisor advisor;

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

public Client() {}

public Client(String name, String email, String phoneNumber, FinancialAdvisor advisor) {
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
this.advisor = advisor;
}

public Long getClientId() { return clientId; }
public String getName() { return name; }
public String getEmail() { return email; }
public String getPhoneNumber() { return phoneNumber; }
public FinancialAdvisor getAdvisor() { return advisor; }
public Portfolio getPortfolio() { return portfolio; }

public void setName(String name) { this.name = name; }
public void setEmail(String email) { this.email = email; }
public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.wellsfargo.counselor.entity;

import jakarta.persistence.*;
import java.util.List;

@Entity
public class FinancialAdvisor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long advisorId;

private String name;
private String email;
private String phoneNumber;

@OneToMany(mappedBy = "advisor", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Client> clients;

public FinancialAdvisor() {}

public FinancialAdvisor(String name, String email, String phoneNumber) {
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
}

public Long getAdvisorId() { return advisorId; }
public String getName() { return name; }
public String getEmail() { return email; }
public String getPhoneNumber() { return phoneNumber; }
public List<Client> getClients() { return clients; }

public void setName(String name) { this.name = name; }
public void setEmail(String email) { this.email = email; }
public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; }
}
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 jakarta.persistence.*;
import java.util.List;

@Entity
public class Portfolio {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long portfolioId;

@OneToOne
@JoinColumn(name = "client_id", nullable = false)
private Client client;

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

public Portfolio() {}

public Portfolio(Client client) {
this.client = client;
}

public Long getPortfolioId() { return portfolioId; }
public Client getClient() { return client; }
public List<Security> getSecurities() { return securities; }
}

42 changes: 42 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,42 @@
package com.wellsfargo.counselor.entity;


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

@Entity
public class Security {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long securityId;

private String name;
private String category;
private LocalDate purchaseDate;
private double purchasePrice;
private int quantity;

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

public Security() {}

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

public Long getSecurityId() { return securityId; }
public String getName() { return name; }
public String getCategory() { return category; }
public LocalDate getPurchaseDate() { return purchaseDate; }
public double getPurchasePrice() { return purchasePrice; }
public int getQuantity() { return quantity; }
public Portfolio getPortfolio() { return portfolio; }
}