-
Notifications
You must be signed in to change notification settings - Fork 5
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
Implemented ability to add new loans using templates #357
Changes from all commits
45d520b
907d911
2b6e7a0
8d3cda2
a96fe29
e343c96
79e4603
d69b302
5a7d1a4
fd55fe5
f5af5d3
a4a3f6c
7413e74
c20a03f
c3009c5
88da583
7f81e83
dd6c48d
0c519e2
bf78ffc
acbf4f4
9b0f310
276791c
cea4768
033a3a4
6f892d9
4d4db6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package eggventory.logic.commands.add; | ||
|
||
import eggventory.commons.enums.CommandType; | ||
import eggventory.commons.exceptions.BadInputException; | ||
import eggventory.logic.commands.Command; | ||
import eggventory.model.LoanList; | ||
import eggventory.model.StockList; | ||
import eggventory.model.TemplateList; | ||
import eggventory.model.loans.Loan; | ||
import eggventory.storage.Storage; | ||
import eggventory.ui.Ui; | ||
|
||
import javax.imageio.ImageTranscoder; | ||
import java.util.ArrayList; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cLAIM YOUR CODE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iTS NOT EVEN THAT MANY LINES There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iTS WHAT THEY WANT TO SEE |
||
public class AddLoanByTemplateCommand extends Command { | ||
|
||
private String matricNo; | ||
private String name; | ||
|
||
/** | ||
* Adds new loans to a matric using a loan template. | ||
* @param matricNo Matric number of student to add the loans to. | ||
* @param name Name of template to get loans from. | ||
*/ | ||
public AddLoanByTemplateCommand(CommandType type, String matricNo, String name) { | ||
super(type); | ||
this.matricNo = matricNo; | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String execute(StockList list, Ui ui, Storage storage) throws BadInputException { | ||
|
||
String output = LoanList.addLoan(matricNo, name); | ||
|
||
if (output == null) { | ||
output = "OOPS! Template does not exist!"; | ||
} | ||
|
||
ui.print(output); | ||
|
||
return output; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,11 @@ | |
import eggventory.logic.commands.add.AddStockCommand; | ||
import eggventory.logic.commands.add.AddStockTypeCommand; | ||
import eggventory.logic.commands.add.AddTemplateCommand; | ||
import eggventory.logic.commands.add.AddLoanByTemplateCommand; | ||
import eggventory.commons.enums.CommandType; | ||
import eggventory.commons.exceptions.BadInputException; | ||
import eggventory.commons.exceptions.InsufficientInfoException; | ||
import eggventory.model.TemplateList; | ||
import javafx.util.Pair; | ||
|
||
import java.util.ArrayList; | ||
|
@@ -81,12 +83,20 @@ private Command processAddTemplate(String input) throws BadInputException { | |
} | ||
|
||
//@@author cyanoei | ||
private Command processAddLoan(String input) throws BadInputException { | ||
private Command processAddLoan(String input) throws BadInputException, InsufficientInfoException { | ||
String[] addInput = input.split(" +"); | ||
if (Parser.isReserved(addInput[0])) { | ||
throw new BadInputException("'" + addInput[0] + "' is an invalid name as it is a keyword" | ||
+ " for an existing command."); | ||
} | ||
|
||
if (TemplateList.templateExists(addInput[1])) { | ||
return new AddLoanByTemplateCommand(CommandType.ADD, addInput[0], addInput[1]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thats a nice way to do it |
||
} | ||
|
||
if (!Parser.isCommandComplete(input, 2)) { | ||
throw new InsufficientInfoException(CommandDictionary.getCommandUsage("add loan")); | ||
} | ||
return new AddLoanCommand(CommandType.ADD, addInput[0], addInput[1], Integer.parseInt(addInput[2])); | ||
} | ||
|
||
|
@@ -122,7 +132,7 @@ public Command parse(String inputString) throws InsufficientInfoException, BadIn | |
break; | ||
|
||
case "loan": | ||
if (!Parser.isCommandComplete(inputString, 3)) { | ||
if (!Parser.isCommandComplete(inputString, 2)) { | ||
throw new InsufficientInfoException(CommandDictionary.getCommandUsage("add loan")); | ||
} | ||
addCommand = processAddLoan(addInput[1]); | ||
|
@@ -151,8 +161,4 @@ public Command parse(String inputString) throws InsufficientInfoException, BadIn | |
|
||
} | ||
|
||
private void checkIfCommandComplete() { | ||
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice thanks