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

Javadoc for entirety of Buy #226

Merged
merged 3 commits into from
Dec 4, 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
18 changes: 18 additions & 0 deletions src/main/java/interface_adapter/Buy/BuyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
import use_case.Buy.BuyInputBoundary;
import use_case.Buy.BuyInputData;

/**
* Handles the user's input and passes it to the interactor.
*/
public class BuyController {
final private BuyInputBoundary buyInteractor;

/**
* @param buyInteractor The interactor to be used for the execution of the use case.
*/
public BuyController(BuyInputBoundary buyInteractor) {
this.buyInteractor = buyInteractor;
}

/**
* @param amount The amount of stocks to be bought.
* @param ticker The ticker of the stock to be bought.
*/
public void execute(String amount, String ticker) {
try {
BuyInputData buyInputData = new BuyInputData(Double.parseDouble(amount), ticker);
Expand All @@ -20,10 +30,18 @@ public void execute(String amount, String ticker) {
}
}

/**
* @param ticker The ticker of the stock to be searched.
*/
public void execute(String ticker) {
BuyInputData buyInputData = new BuyInputData(ticker);
buyInteractor.execute(buyInputData);
}

/**
* Executes the use case with no input data.
* The point of this is to get the balance.
*/
public void execute() {
BuyInputData buyInputData = new BuyInputData();
buyInteractor.execute(buyInputData);
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/interface_adapter/Buy/BuyPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
import use_case.Buy.BuyOutputData;
import use_case.Buy.BuySearchOutputData;

/**
* Encapusaltes methods related to the presenter for BuyViewModel
*/
public class BuyPresenter implements BuyOutputBoundary {

private final BuyViewModel buyViewModel;
private ViewManagerModel viewManagerModel;

/**
* @param viewManagerModel The model for the view manager
* @param buyViewModel The view model for the BuyView
*/
public BuyPresenter(
ViewManagerModel viewManagerModel,
BuyViewModel buyViewModel
Expand All @@ -18,6 +25,9 @@ public BuyPresenter(
this.buyViewModel = buyViewModel;
}

/**
* @param response The output from the use case when the interactor executed a purchase (or failure thereof).
*/
@Override
public void prepareSuccessView(BuyOutputData response) {
BuyState state = buyViewModel.getState();
Expand All @@ -29,6 +39,10 @@ public void prepareSuccessView(BuyOutputData response) {
buyViewModel.firePropertyChanged();
}
}

/**
* @param response The output from the use case when the interactor executed a search.
*/
@Override
public void prepareSuccessView(BuySearchOutputData response) {
BuyState state = buyViewModel.getState();
Expand All @@ -41,6 +55,9 @@ public void prepareSuccessView(BuySearchOutputData response) {
buyViewModel.firePropertyChanged();
}

/**
* @param error The error message from the use case when the interactor failed to execute a purchase or a search.
*/
@Override
public void prepareFailView(String error) {
BuyState state = buyViewModel.getState();
Expand Down
58 changes: 55 additions & 3 deletions src/main/java/interface_adapter/Buy/BuyState.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.Map;

/**
* Stores the state of the BuyView and BuyViewModel.
*/
public class BuyState {
private String amount = "";
private String amountError = null;
Expand All @@ -12,72 +15,121 @@ public class BuyState {
private Double currentlyHeld;
private Double curBalance;

/**
* @return true if the user has just bought a stock or made a search, false otherwise
*/
public Boolean getRenderNewInfo() {
return renderNewInfo;
}

/**
* @return the current balance of the user
*/
public Double getCurBalance() {
return curBalance;
}

/**
* @return true if the user has just bought a stock, false otherwise
*/
public Boolean getBoughtStock() {
return boughtStock;
}

/**
* @param boughtStock true if the user has just bought a stock, false otherwise
*/
public void setBoughtStock(Boolean boughtStock) {
this.boughtStock = boughtStock;
}

/**
* @return the amount of the stock the user currently holds
*/
public Double getCurrentlyHeld() {
return currentlyHeld;
}

/**
* @param currentlyHeld the amount of the stock the user currently holds
*/
public void setCurrentlyHeld(Double currentlyHeld) {
this.currentlyHeld = currentlyHeld;
}

/**
* @param curBalance the current balance of the user
*/
public void setCurBalance(Double curBalance) {
this.curBalance = curBalance;
}

/**
* @param renderNewInfo true if the user has just bought a stock or made a search, false otherwise
*/
public void setRenderNewInfo(Boolean renderNewInfo) {
this.renderNewInfo = renderNewInfo;
}

/**
* @return the ticker of the stock the user is searching for or purchasing
*/
public String getTicker() {
return ticker;
}

/**
* @return information about the stock the user is searching for or purchasing
*/
public Map<String, String> getStockInfo() {
return stockInfo;
}

/**
* @param stockInfo information about the stock the user is searching for or purchasing
*/
public void setStockInfo(Map<String, String> stockInfo) {
this.stockInfo = stockInfo;
}

/**
* @param ticker the ticker of the stock the user is searching for or purchasing
*/
public void setTicker(String ticker) {
this.ticker = ticker;
}

/**
* @return the amount of stock the user is purchasing
*/
public String getAmount() {
return amount;
}

/**
* @param amount the amount of stock the user is purchasing
*/
public void setAmount(String amount) {
this.amount = amount;
}

/**
* @return an error message if the user has entered an invalid amount, null otherwise
*/
public String getAmountError() {
return amountError;
}

/**
* @param amountError an error message if the user has entered an invalid amount, null otherwise
*/
public void setAmountError(String amountError) {
this.amountError = amountError;
}

public BuyState() {

}
/**
* Default constructor.
*/
public BuyState() {}

}
25 changes: 25 additions & 0 deletions src/main/java/interface_adapter/Buy/BuyViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
* ViewModel for BuyView
*/
public class BuyViewModel extends ViewModel {

/**
* Labels for the view
*/
public final String TITLE_LABEL = "Buy Stock";
public final String AMOUNT_LABEL = "Enter amount";
public final String BACK_BUTTON_LABEL = "Back";
Expand All @@ -16,25 +23,43 @@ public class BuyViewModel extends ViewModel {

private BuyState state = new BuyState();

/**
* Constructor
*/
public BuyViewModel() {
super("buy");
}

/**
* Set the state of the view model
* @param state the new state
*/
public void setState(BuyState state) {
this.state = state;
}

private final PropertyChangeSupport support = new PropertyChangeSupport(this);

/**
* Fires a property change event
*/
public void firePropertyChanged() {
support.firePropertyChange("state", null, this.state);
}

/**
* Adds a property change listener
* @param listener the listener to add
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
support.addPropertyChangeListener(listener);
}

/**
* @return the current state of the view model
*/
public BuyState getState() {
return state;
}

}
12 changes: 12 additions & 0 deletions src/main/java/use_case/Buy/BuyDataAccessInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

import entity.User;

/**
* Defines the methods that will be used by the BuyInteractor class.
*/
public interface BuyDataAccessInterface {

/**
* Saves the user's data.
*/
void save();

/**
* @return the user's data.
*/
User get();

}
8 changes: 8 additions & 0 deletions src/main/java/use_case/Buy/BuyInputBoundary.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package use_case.Buy;

/**
* Defines the input boundary for the Buy use case.
*/
public interface BuyInputBoundary {

/**
* @param buyInputData The input data for the Buy use case.
*/
void execute(BuyInputData buyInputData);

}
11 changes: 10 additions & 1 deletion src/main/java/use_case/Buy/BuyInputData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package use_case.Buy;

/**
* This class represents the input data for the BuyInteractor.
*/
public class BuyInputData {
private final Double amount;
private final String ticker;
Expand Down Expand Up @@ -34,12 +37,18 @@ public BuyInputData() {
this.ticker = null;
}


/**
* @return The amount of the stock to be purchased.
*/
public Double getAmount() {
return amount;
}

/**
* @return The ticker symbol of the stock to be purchased.
*/
public String getTicker() {
return ticker;
}

}
20 changes: 20 additions & 0 deletions src/main/java/use_case/Buy/BuyInteractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@
import java.time.LocalDateTime;
import java.util.HashMap;

/**
* Applies the enterprise application rules for the Buy use case.
* Handles the business logic for the Buy use case.
*/
public class BuyInteractor extends BaseStockInteractor implements BuyInputBoundary {

/** The data access object for the user. */
final BuyDataAccessInterface userDataAccessObject;

/** The presenter for the Buy use case. */
BuyOutputBoundary buyPresenter;

/** The API driver for the Buy use case. */
APIAccessInterface driverAPI;

/**
* @param userDataAccessInterface The data access object for the user.
* @param buyPresenter The presenter for the Buy use case.
* @param driverAPI The API driver for the Buy use case.
*/
public BuyInteractor(
BuyDataAccessInterface userDataAccessInterface,
BuyOutputBoundary buyPresenter,
Expand All @@ -31,6 +46,10 @@ private Transaction createBuyTransaction(Double amount, Double currentPrice) {
currentPrice
));
}

/**
* @param buyInputData The input data for the Buy use case. Contains the ticker and amount.
*/
@Override
public void execute(BuyInputData buyInputData) {
String ticker = buyInputData.getTicker();
Expand Down Expand Up @@ -104,4 +123,5 @@ public void execute(BuyInputData buyInputData) {

buyPresenter.prepareSuccessView(result);
}

}
Loading
Loading