Skip to content

Commit

Permalink
GetInfo use case implemented (#45)
Browse files Browse the repository at this point in the history
* GetInfo use case implemented

* GetInfo use case implementation has been fixed, no longer messing up all the import statements of everything.

* Documentation for GetInfoInteractor improved as requested
  • Loading branch information
quiz3 committed Nov 20, 2023
1 parent 9eee38d commit 37c2436
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 3 deletions.
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

0 comments on commit 37c2436

Please sign in to comment.