From 1fcd4dc5f4bf6e2c0e911edcb43a86917884a88e Mon Sep 17 00:00:00 2001 From: quiz3 <113859565+quiz3@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:53:25 -0500 Subject: [PATCH] GetNews Interface Adapters implemented --- .../GetNews/GetNewsController.java | 17 ++++++++++ .../GetNews/GetNewsPresenter.java | 30 +++++++++++++++++ .../GetNews/GetNewsState.java | 25 ++++++++++++++ .../GetNews/GetNewsViewModel.java | 33 +++++++++++++++++++ src/main/java/view/GetNewsView.java | 26 +++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 src/main/java/interface_adapters/GetNews/GetNewsController.java create mode 100644 src/main/java/interface_adapters/GetNews/GetNewsPresenter.java create mode 100644 src/main/java/interface_adapters/GetNews/GetNewsState.java create mode 100644 src/main/java/interface_adapters/GetNews/GetNewsViewModel.java create mode 100644 src/main/java/view/GetNewsView.java diff --git a/src/main/java/interface_adapters/GetNews/GetNewsController.java b/src/main/java/interface_adapters/GetNews/GetNewsController.java new file mode 100644 index 0000000..de048ef --- /dev/null +++ b/src/main/java/interface_adapters/GetNews/GetNewsController.java @@ -0,0 +1,17 @@ +package interface_adapters.GetNews; + +import use_cases.GetNews.GetNewsInputBoundary; +import use_cases.GetNews.GetNewsInputData; + +public class GetNewsController { + final private GetNewsInputBoundary getNewsInteractor; + + public GetNewsController(GetNewsInputBoundary getNewsInteractor) { + this.getNewsInteractor = getNewsInteractor; + } + + public void execute(String ticker) { + GetNewsInputData getNewsInputData = new GetNewsInputData(ticker); + getNewsInteractor.execute(getNewsInputData); + } +} diff --git a/src/main/java/interface_adapters/GetNews/GetNewsPresenter.java b/src/main/java/interface_adapters/GetNews/GetNewsPresenter.java new file mode 100644 index 0000000..2c8ef25 --- /dev/null +++ b/src/main/java/interface_adapters/GetNews/GetNewsPresenter.java @@ -0,0 +1,30 @@ +package interface_adapters.GetNews; + +import interface_adapters.ViewManagerModel; +import use_cases.GetNews.GetNewsOutputBoundary; +import use_cases.GetNews.GetNewsOutputData; +import view.GetNewsView; + +public class GetNewsPresenter implements GetNewsOutputBoundary { + private final GetNewsView getNewsViewModel; + private ViewManagerModel viewManagerModel; + + public GetNewsPresenter(ViewManagerModel viewManagerModel, GetNewsView getNewsViewModel) { + this.viewManagerModel = viewManagerModel; + this.getNewsViewModel = getNewsViewModel; + } + + @Override + public void prepareSuccessView(GetNewsOutputData response) { + // TODO: On Success switch to Dashboard View + // Figure out how to make this switch + } + + @Override + public void prepareFailView(String error) { + // TODO +// GetNewsState getNewsState = getNewsViewModel.getState(); +// GetNewsState.setProcessError(error); +// getNewsViewModel.firePropertyChanged(); + } +} diff --git a/src/main/java/interface_adapters/GetNews/GetNewsState.java b/src/main/java/interface_adapters/GetNews/GetNewsState.java new file mode 100644 index 0000000..71e57f4 --- /dev/null +++ b/src/main/java/interface_adapters/GetNews/GetNewsState.java @@ -0,0 +1,25 @@ +package interface_adapters.GetNews; + +import java.util.List; +import java.util.Map; + +public class GetNewsState { + private String newsError = null; + private List> newsList = null; + + public GetNewsState(List> news_list, String newsError) { + this.newsList = news_list; + this.newsError = newsError; + } + + public String getNewsError() {return newsError;} + + public void setNewsError() {this.newsError = newsError;} + + public List> getNewsList() {return newsList;} + + public void setNewsList(List> news_list) {this.newsList = news_list;} + + // Due to the copy constructor, the default constructor must be explicit. So we overload it. + public GetNewsState() {} +} diff --git a/src/main/java/interface_adapters/GetNews/GetNewsViewModel.java b/src/main/java/interface_adapters/GetNews/GetNewsViewModel.java new file mode 100644 index 0000000..75a8584 --- /dev/null +++ b/src/main/java/interface_adapters/GetNews/GetNewsViewModel.java @@ -0,0 +1,33 @@ +package interface_adapters.GetNews; + +import interface_adapters.ViewModel; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +public class GetNewsViewModel extends ViewModel { + public final String TITLE_LABEL = "Get Company News"; + public final String NEWS_BUTTON_LABEL = "Get News"; + + private GetNewsState state = new GetNewsState(); + + public GetNewsViewModel() {super("Get Company News");} + + public void setState(GetNewsState state) { + this.state = state; + } + + private final PropertyChangeSupport support = new PropertyChangeSupport(this); + + public void firePropertyChanged() { + support.firePropertyChange("state", null, this.state); + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + support.addPropertyChangeListener(listener); + } + + public GetNewsState getState() { + return state; + } +} diff --git a/src/main/java/view/GetNewsView.java b/src/main/java/view/GetNewsView.java new file mode 100644 index 0000000..167a48c --- /dev/null +++ b/src/main/java/view/GetNewsView.java @@ -0,0 +1,26 @@ +package view; + +import interface_adapters.Buy.BuyViewModel; +import interface_adapters.GetNews.GetNewsState; +import interface_adapters.GetNews.GetNewsViewModel; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +public class GetNewsView extends JPanel implements ActionListener, PropertyChangeListener { + public final String viewName = "Get Company News"; + private final GetNewsViewModel getNewsViewModel; + + /** + * Text fields, labels, and buttons + */ + + // TODO fill the rest in + +}