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

Changed Output Data so that we don't violate Inward Dependency Rule #71

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ public DashboardPresenter(ViewManagerModel viewManagerModel, DashboardViewModel
public void prepareSuccessView(DashboardOutputData dashboardOutputData) {
// Get the current dashboardViewModel's state
DashboardState dashboardState = dashboardViewModel.getState();
// Alter the state such that it updates to the new portfolioInformation and user stats
dashboardState.setOwnedStocks(dashboardOutputData.getPortfolioInformation());
// Alter the state such that it updates to the new ticker, amount, and full name info
// and user stats
dashboardState.setOwnedAmounts(dashboardOutputData.getAmountInformation());
dashboardState.setOwnedTickers(dashboardOutputData.getTickerInformation());
dashboardState.setOwnedFullNames(dashboardOutputData.getFullNamesInformation());
dashboardState.setUserStats(dashboardOutputData.getUserStats());
// fire the property changed for dashboard view model
dashboardViewModel.firePropertyChanged();
Expand Down
38 changes: 30 additions & 8 deletions src/main/java/interface_adapters/Dashboard/DashboardState.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,40 @@
public class DashboardState {
private HashMap<String, Double> userStats;
// change owned stocks data type
private List<PortfolioInformation> ownedStocks;
private List<String> ownedTickers;
private List<String> ownedFullNames;
private List<Double> ownedAmounts;

public DashboardState(HashMap<String, Double> userStats, List<PortfolioInformation> ownedStocks) {
public DashboardState(HashMap<String, Double> userStats, List<String> ownedTickers,
List<String> ownedFullNames, List<Double> ownedAmounts) {
this.userStats = userStats;
this.ownedStocks = ownedStocks;
this.ownedTickers = ownedTickers;
this.ownedAmounts = ownedAmounts;
this.ownedFullNames = ownedFullNames;
}

public List<PortfolioInformation> getOwnedStocks() {
return this.ownedStocks;
public List<Double> getOwnedAmounts() {
return this.ownedAmounts;
}

public void setOwnedAmounts(List<Double> ownedAmounts) {
this.ownedAmounts = ownedAmounts;
}

public List<String> getOwnedTickers() {
return ownedTickers;
}

public void setOwnedTickers(List<String> ownedTickers) {
this.ownedTickers = ownedTickers;
}

public List<String> getOwnedFullNames() {
return ownedFullNames;
}

public void setOwnedFullNames(List<String> ownedFullNames) {
this.ownedFullNames = ownedFullNames;
}

public HashMap<String, Double> getUserStats() {
Expand All @@ -26,9 +51,6 @@ public void setUserStats(HashMap<String, Double> userStats) {
this.userStats = userStats;
}

public void setOwnedStocks(List<PortfolioInformation> ownedStocks) {
this.ownedStocks = ownedStocks;
}

// Because of the previous copy constructor, the default constructor must be explicit. Hence overloading.
public DashboardState() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package interface_adapters.Dashboard;
package use_cases.Dashboard;

import use_cases.Dashboard.DashboardOutputData;

Expand Down
29 changes: 27 additions & 2 deletions src/main/java/use_cases/Dashboard/DashboardOutputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import entities.PortfolioInformation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

Expand All @@ -18,7 +19,31 @@ public HashMap<String, Double> getUserStats() {
return this.userStats;
}

public List<PortfolioInformation> getPortfolioInformations() {
return this.portfolioInformation;
public List<String> getTickerInformation() {
List<String> tickers = new ArrayList<String>();

for (PortfolioInformation pdata: portfolioInformation) {
tickers.add(pdata.getTicker());
}
return tickers;
}


public List<String> getFullNamesInformation() {
List<String> fullNames = new ArrayList<String>();

for (PortfolioInformation pdata: portfolioInformation) {
fullNames.add(pdata.getFullName());
}
return fullNames;
}

public List<Double> getAmountInformation() {
List<Double> amount = new ArrayList<Double>();

for (PortfolioInformation pdata: portfolioInformation) {
amount.add(pdata.getAmount());
}
return amount;
}
}