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

Implemented ability to add new loans using templates #357

Merged
merged 27 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
45d520b
Added skeleton classes for Parse
Deculsion Oct 10, 2019
907d911
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 10, 2019
2b6e7a0
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/ma…
Deculsion Oct 12, 2019
8d3cda2
Added toString() and modified some javadocs for it.
Deculsion Oct 14, 2019
a96fe29
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 15, 2019
e343c96
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 16, 2019
79e4603
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 17, 2019
d69b302
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 17, 2019
5a7d1a4
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 17, 2019
fd55fe5
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 18, 2019
f5af5d3
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 24, 2019
a4a3f6c
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 25, 2019
7413e74
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 29, 2019
c20a03f
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 29, 2019
c3009c5
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 30, 2019
88da583
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 31, 2019
7f81e83
docs/User Guide.md created from https://stackedit.io/
Deculsion Oct 31, 2019
dd6c48d
Add UG markdown
Deculsion Oct 31, 2019
0c519e2
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Oct 31, 2019
bf78ffc
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Nov 1, 2019
acbf4f4
Merge remote-tracking branch 'self_origin/master'
Deculsion Nov 1, 2019
9b0f310
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Nov 5, 2019
276791c
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Nov 6, 2019
cea4768
Merge branch 'master' of https://github.com/AY1920S1-CS2113T-F09-3/main
Deculsion Nov 6, 2019
033a3a4
Add addloanbytemplate function
Deculsion Nov 6, 2019
6f892d9
Add addloanbytemplate function
Deculsion Nov 6, 2019
4d4db6e
Small fixes
Deculsion Nov 6, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CommandDictionary() {
// Add Commands
commandDict.add(new Pair<>("add stock", "<StockType> <StockCode> <Quantity> <Description>"));
commandDict.add(new Pair<>("add stocktype", "<StockType>"));
commandDict.add(new Pair<>("add loan", "<StockCode> <Quantity>"));
commandDict.add(new Pair<>("add loan", "<MatricNo> <StockCode> <Quantity>"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice thanks

commandDict.add(new Pair<>("add stocktype", "<StockType>"));
commandDict.add(new Pair<>("add person", "<MatricNo> <Name>"));
commandDict.add(new Pair<>("add template", "<TemplateName> {<StockCode>, <Quantity>}"));
Expand Down
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;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cLAIM YOUR CODE

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iTS NOT EVEN THAT MANY LINES

Copy link

Choose a reason for hiding this comment

The 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;
}
}
18 changes: 12 additions & 6 deletions src/main/java/eggventory/logic/parsers/ParseAdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Copy link

Choose a reason for hiding this comment

The 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]));
}

Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -151,8 +161,4 @@ public Command parse(String inputString) throws InsufficientInfoException, BadIn

}

private void checkIfCommandComplete() {

}

}
11 changes: 9 additions & 2 deletions src/main/java/eggventory/model/LoanList.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,23 @@ public static void addLoan(String stockCode, String matricNo, int quantity,
* Add multiple loans using a template.
* @param matricNo Matriculation number of student to assign loans to.
* @param template Name of the template.
* @return String of the loans added.
*/
public static void addLoan(String matricNo, String template) {
public static String addLoan(String matricNo, String template) {
Loan[] loans = TemplateList.getTemplateLoans(template);
if (loans == null) {
return;
return null;
}

StringBuilder output = new StringBuilder(String.format(
"The following loans have been added to %s:", matricNo));

for (Loan loan : loans) {
addLoan(loan.getStockCode(), matricNo, loan.getQuantity());
output.append(String.format("%s: %d", loan.getStockCode(), loan.getQuantity()));
}

return output.toString();
}

//@@author cyanoei
Expand Down