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

GetInfo use case implemented #45

Merged
merged 3 commits into from
Nov 20, 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
12 changes: 9 additions & 3 deletions src/main/java/entities/CompanyInformation.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ public CompanyInformation(String country, String name, String ticker, String web
this.ipo = ipo;
}

public String getName() {
return name;
}
public String getCountry() {return country;}

public String getName() {return name;}

public String getTicker() {return ticker;}

public String getWeburl() {return weburl;}

public String getIpo() {return ipo;}

public String toString() {
return "CompanyInformation{\n" +
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/use_cases/GetInfo/GetInfoInputBoundary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package use_cases.GetInfo;

public interface GetInfoInputBoundary {
void execute(GetInfoInputData getInfoInputData);
}
13 changes: 13 additions & 0 deletions src/main/java/use_cases/GetInfo/GetInfoInputData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package use_cases.GetInfo;

public class GetInfoInputData {
public String ticker;

public GetInfoInputData(String ticker) {
this.ticker = ticker;
}

public String getTicker() {
return ticker;
}
}
42 changes: 42 additions & 0 deletions src/main/java/use_cases/GetInfo/GetInfoInteractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package use_cases.GetInfo;

import entities.CompanyInformation;
import use_cases.APIAccessInterface;

public class GetInfoInteractor implements GetInfoInputBoundary {
GetInfoOutputBoundary getInfoPresenter;
APIAccessInterface driverAPI;

public GetInfoInteractor(GetInfoOutputBoundary getInfoPresenter, APIAccessInterface driverAPI) {
this.getInfoPresenter = getInfoPresenter;
this.driverAPI = driverAPI;
}

@Override
public void execute(GetInfoInputData getInfoInputData) {
/**
* <p>
* Info is fetched using the drivers.Finnhub.getCompanyProfile() method, which interacts with the API through
* an OKHTTP client.
* The information in the CompanyInformation object generated by the driver when data is taken from the API is
* transferred into a HashMap through the GetInfoOutputData constructor.
*
* @param getInfoInputData an InputData object containing the ticker of the company whose profile we fetch
*/
String ticker = getInfoInputData.getTicker();

try {
// Make API call
CompanyInformation company_info = driverAPI.getCompanyProfile(ticker);

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

getInfoPresenter.prepareSuccessView(result);

} catch (RuntimeException e) {
// e.printStackTrace();
getInfoPresenter.prepareFailView("API call failed.");
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/use_cases/GetInfo/GetInfoOutputBoundary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package use_cases.GetInfo;

public interface GetInfoOutputBoundary {
void prepareSuccessView(GetInfoOutputData result);

void prepareFailView(String error);
}
27 changes: 27 additions & 0 deletions src/main/java/use_cases/GetInfo/GetInfoOutputData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package use_cases.GetInfo;

import entities.CompanyInformation;

import java.util.Map;
import java.util.HashMap;

public class GetInfoOutputData {
String ticker;
Map<String, String> info_map;

public GetInfoOutputData(String ticker, CompanyInformation company_info) {
this.ticker = ticker;

// Initialize info_map attribute, then manually put each attribute to the Map from the CompanyInformation object
this.info_map = new HashMap<String, String>();
info_map.put("country", company_info.getCountry());
info_map.put("name", company_info.getName());
info_map.put("ticker", company_info.getTicker());
info_map.put("weburl", company_info.getWeburl());
info_map.put("ipo", company_info.getIpo());
}

public String getTicker() {return ticker;}

public Map<String, String> getInfo() {return info_map;}
}
1 change: 1 addition & 0 deletions src/main/java/use_cases/GetNews/GetNewsOutputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class GetNewsOutputData {
public GetNewsOutputData(String ticker, List<CompanyNews> company_news_items) {
this.ticker = ticker;
this.news_items = new ArrayList<Map<String, String>>();

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

Expand Down
Loading