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 Interface Adapters implemented #62

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/interface_adapters/GetNews/GetNewsController.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
30 changes: 30 additions & 0 deletions src/main/java/interface_adapters/GetNews/GetNewsPresenter.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
25 changes: 25 additions & 0 deletions src/main/java/interface_adapters/GetNews/GetNewsState.java
Original file line number Diff line number Diff line change
@@ -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<Map<String, String>> newsList = null;

public GetNewsState(List<Map<String, String>> news_list, String newsError) {
this.newsList = news_list;
this.newsError = newsError;
}

public String getNewsError() {return newsError;}

public void setNewsError() {this.newsError = newsError;}

public List<Map<String, String>> getNewsList() {return newsList;}

public void setNewsList(List<Map<String, String>> news_list) {this.newsList = news_list;}

// Due to the copy constructor, the default constructor must be explicit. So we overload it.
public GetNewsState() {}
}
33 changes: 33 additions & 0 deletions src/main/java/interface_adapters/GetNews/GetNewsViewModel.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
26 changes: 26 additions & 0 deletions src/main/java/view/GetNewsView.java
Original file line number Diff line number Diff line change
@@ -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

}
Loading