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

GetNews table added #123

Merged
merged 5 commits into from
Nov 27, 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 @@ -16,13 +16,20 @@ public GetNewsPresenter(ViewManagerModel viewManagerModel, GetNewsViewModel getN
@Override
public void prepareSuccessView(GetNewsOutputData response) {
// TODO: On success, show articles in a list (aka. table)
GetNewsState state = getNewsViewModel.getState();

state.setRenderNewInfo(true);
state.setNewsItems(response.getNewsItems());
state.setTicker(response.getTicker());

getNewsViewModel.firePropertyChanged();
}

@Override
public void prepareFailView(String error) {
// TODO
GetNewsState state = getNewsViewModel.getState();
state.setTickerError(error);
getNewsViewModel.firePropertyChanged();
}

}
46 changes: 38 additions & 8 deletions src/main/java/interface_adapters/GetNews/GetNewsState.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
package interface_adapters.GetNews;

import java.util.List;
import java.util.Map;

public class GetNewsState {
private String tickerError = null;
private String ticker = null;
private String ticker = "";
List<Map<String, String>> newsItems;
private Boolean renderNewInfo;

public GetNewsState(String ticker, String tickerError) {
this.ticker = ticker;
public String getTickerError() {
return tickerError;
}

public void setTickerError(String tickerError) {
this.tickerError = tickerError;
}

public String getTickerError() {return tickerError;}
public String getTicker() {
return ticker;
}

public void setTickerError(String tickerError) {this.tickerError = tickerError;}
public void setTicker(String ticker) {
this.ticker = ticker;
}

public String getTicker() {return ticker;}
public List<Map<String, String>> getNewsItems() {
return this.newsItems;
}

public void setTicker(String ticker) {this.ticker = ticker;}
public void setNewsItems(List<Map<String, String>> newsItems) {
this.newsItems = newsItems;
}

public Map<String, String> getNewsItem() {
return this.newsItems.get(0);
}

public Boolean getRenderNewInfo() {
return renderNewInfo;
}

public void setRenderNewInfo(Boolean renderNewInfo) {
this.renderNewInfo = renderNewInfo;
}

// Due to the ViewModel's default constructor call, we must explicitly define the default constructor.
// So, we overload the copy constructor.
public GetNewsState() {}
public GetNewsState() {

}

}
18 changes: 9 additions & 9 deletions src/main/java/use_cases/GetNews/GetNewsInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public GetNewsInteractor(GetNewsOutputBoundary getNewsPresenter, APIAccessInterf
@Override
public void execute(GetNewsInputData getNewsInputData) {
/**
* The getNewsInputData parameter should follow the specifications laid out in that class.
* <p>
* This method implements the bulk of the GetNews use case.
* News is fetched over a time period of a month prior to the method call.
*
* @param getNewsInputData an InputData object following the relevant CA Engine rules
*/
* The getNewsInputData parameter should follow the specifications laid out in that class.
* <p>
* This method implements the bulk of the GetNews use case.
* News is fetched over a time period of a month prior to the method call.
*
* @param getNewsInputData an InputData object following the relevant CA Engine rules
*/
String ticker = getNewsInputData.getTicker();

// Define end of news period to be right now
Expand All @@ -34,10 +34,10 @@ public void execute(GetNewsInputData getNewsInputData) {

try {
// Make API call
List<CompanyNews> company_news_list = driverAPI.getCompanyNews(ticker, from, to);
List<CompanyNews> companyNewsList = driverAPI.getCompanyNews(ticker, from, to);

// Save API output using OutputData format for the GetNews use case
GetNewsOutputData result = new GetNewsOutputData(ticker, company_news_list);
GetNewsOutputData result = new GetNewsOutputData(ticker, companyNewsList);

getNewsPresenter.prepareSuccessView(result);

Expand Down
27 changes: 13 additions & 14 deletions src/main/java/use_cases/GetNews/GetNewsOutputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,28 @@

public class GetNewsOutputData {
String ticker;
List<Map<String, String>> news_items;
List<Map<String, String>> newsItems;

public GetNewsOutputData(String ticker, List<CompanyNews> company_news_items) {
public GetNewsOutputData(String ticker, List<CompanyNews> companyNewsItems) {
this.ticker = ticker;
this.news_items = new ArrayList<Map<String, String>>();
this.newsItems = new ArrayList<Map<String, String>>();

for (CompanyNews company_news : company_news_items) {
Map<String, String> news_item = new HashMap<>();
for (CompanyNews companyNews : companyNewsItems) {
Map<String, String> newsItem = new HashMap<>();

news_item.put("category", company_news.getCategory());
news_item.put("datetime", company_news.getDatetime().toString());
news_item.put("headline", company_news.getHeadline());
news_item.put("url", company_news.getUrl());
news_item.put("summary", company_news.getSummary());
newsItem.put("category", companyNews.getCategory());
newsItem.put("datetime", companyNews.getDatetime().toString());
newsItem.put("headline", companyNews.getHeadline());
newsItem.put("url", companyNews.getUrl());
newsItem.put("summary", companyNews.getSummary());

this.news_items.add(news_item);
this.newsItems.add(newsItem);
}

}

public String getTicker() {return ticker;}

public List<Map<String, String>> getNewsItems() {return news_items;}
public List<Map<String, String>> getNewsItems() {return newsItems;}

// TODO decide whether this is necessary
// public Map<String, String> getNewsItem(int idx) {return news_items.get(idx);}
}
3 changes: 2 additions & 1 deletion src/main/java/view/BuyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class BuyView extends JPanel implements ActionListener, PropertyChangeLis

public final String viewName = "buy";
private final BuyViewModel buyViewModel;
private final BuyController buyController;

private final JLabel amountErrorField = new JLabel();
final JTextField tickerInputField = new JTextField(15);
Expand All @@ -33,7 +34,7 @@ public class BuyView extends JPanel implements ActionListener, PropertyChangeLis
JPanel middlePanel;
JPanel bottomPanel;
private final JLabel balanceField = new JLabel();
BuyController buyController;

private void updateBalanceLabelColor() {
BuyState state = buyViewModel.getState();
if (state == null || state.getCurBalance() == null || state.getStockInfo() == null) {
Expand Down