Skip to content

Commit a8ff9f9

Browse files
authored
Merge branch 'master' into branch-ListCategory
2 parents 35144e4 + b1ac682 commit a8ff9f9

13 files changed

+131
-30
lines changed

docs/UserGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ Action | Format, Examples
198198
**List** | `list`
199199
**Delete** | `delete INDEX`<br> e.g., `delete 3`
200200
**View** | `view INDEX`<br> e.g., `view 5`
201+
**View existing categori labels** | `viewCategory`
201202
**Add Description** | `addDes INDEX d/DESCRIPTION`<br> e.g., `addDes 2 d/ENTERTAINMENT`
202203
**Delete Description** | `deleteDes INDEX`<br> e.g., `deleteDes 2`
203204
**Set Budget** | `setBudget a/AMOUNT`<br> e.g., `setBudget a/1000`

src/main/java/seedu/address/ExpenseMainApp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public void init() throws Exception {
6969
}
7070

7171
/**
72-
* Returns a {@code ExpenseModelManager} with the data from {@code storage}'s expense book and {@code userPrefs}. <br>
72+
* Returns a {@code ExpenseModelManager} with the data from {@code storage}'s expense book
73+
* and {@code userPrefs}. <br>
7374
* The data from the sample expense book will be used instead if {@code storage}'s expense book is not found,
7475
* or an empty expense book will be used instead if errors occur when reading {@code storage}'s expense book.
7576
*/

src/main/java/seedu/address/logic/commands/DeleteDescriptionCommand.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import seedu.address.commons.core.index.Index;
99
import seedu.address.logic.commands.exceptions.CommandException;
1010
import seedu.address.model.Model;
11-
import seedu.address.model.person.Expense;
1211
import seedu.address.model.person.Description;
12+
import seedu.address.model.person.Expense;
13+
1314

1415

1516
/**
@@ -30,8 +31,8 @@ public class DeleteDescriptionCommand extends Command {
3031
public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Description: %2$s";
3132
public static final String MESSAGE_ADD_DESCRIPTION_SUCCESS = "Added description to Expense: %1$s \n";
3233
public static final String MESSAGE_DELETE_DESCRIPTION_SUCCESS = "Removed description from Expense: %1$s \n";
33-
private final Index index;
3434
private static final Description EMPTY_DESCRIPTION = new Description("");
35+
private final Index index;
3536

3637
/**
3738
* @param index of the expense in the filtered expense list to edit the description
@@ -51,7 +52,8 @@ public CommandResult execute(Model model) throws CommandException {
5152
}
5253

5354
Expense expenseToEdit = lastShownList.get(index.getZeroBased());
54-
Expense editedExpense = new Expense(expenseToEdit.getAmount(), expenseToEdit.getDate(), expenseToEdit.getCategory(),
55+
Expense editedExpense = new Expense(expenseToEdit.getAmount(), expenseToEdit.getDate(),
56+
expenseToEdit.getCategory(),
5557
EMPTY_DESCRIPTION);
5658

5759
model.setExpense(expenseToEdit, editedExpense);
@@ -85,4 +87,4 @@ private String generateSuccessMessage(Expense expenseToEdit) {
8587
String message = MESSAGE_DELETE_DESCRIPTION_SUCCESS;
8688
return String.format(message, expenseToEdit);
8789
}
88-
}
90+
}
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
11
package seedu.address.logic.commands;
22

3-
public class ViewCategoryCommand {
3+
import seedu.address.logic.commands.exceptions.CommandException;
4+
import seedu.address.model.Model;
5+
import seedu.address.model.person.Category;
6+
import seedu.address.model.person.Expense;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
public class ViewCategoryCommand extends Command {
12+
13+
public static final String COMMAND_WORD = "viewCategory";
14+
15+
public static final String MESSAGE_USAGE = COMMAND_WORD
16+
+ ": Finds all the category labels used in the ExpenseBook so far. \n"
17+
+ "Example: " + COMMAND_WORD ;
18+
19+
public static final String MESSAGE_VIEW_CATEGORY_LABELS_SUCCESS =
20+
"View all the existing category labels: \n";
21+
22+
public ViewCategoryCommand() {
23+
}
24+
25+
@Override
26+
public CommandResult execute(Model model) throws CommandException {
27+
String message = "";
28+
List<Category> categories = model.getCategoryLabels();
29+
for (int i = 0; i < categories.size(); i++){
30+
message = message + categories.get(i).categoryName + "\n";
31+
}
32+
return new CommandResult(MESSAGE_VIEW_CATEGORY_LABELS_SUCCESS + message);
33+
}
34+
435
}

src/main/java/seedu/address/logic/commands/ViewCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ViewCommand extends Command {
2020
+ "Parameters: INDEX (must be a positive integer)\n"
2121
+ "Example: " + COMMAND_WORD + " 1";
2222

23-
public static final String MESSAGE_VIEW_EXPENSE_SUCCESS = "View Expense: %1$s";
23+
public static final String MESSAGE_VIEW_EXPENSE_SUCCESS = "View Expense: %s";
2424

2525
private final Index targetIndex;
2626

@@ -37,9 +37,9 @@ public CommandResult execute(Model model) throws CommandException {
3737
}
3838

3939
Expense expenseToView = lastShownList.get(targetIndex.getZeroBased());
40-
String message = targetIndex.toString() + "\n" + expenseToView.toString();
41-
// model.viewExpense(targetIndex);
42-
return new CommandResult(String.format(MESSAGE_VIEW_EXPENSE_SUCCESS, message));
40+
String prefix = String.format(MESSAGE_VIEW_EXPENSE_SUCCESS, targetIndex.getOneBased());
41+
String message = prefix + "\n" + expenseToView.toString();
42+
return new CommandResult(message);
4343
}
4444

4545
@Override

src/main/java/seedu/address/logic/parser/ExpenseBookParser.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package seedu.address.logic.parser;
22

3-
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4-
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
3+
import seedu.address.logic.commands.*;
4+
import seedu.address.logic.parser.exceptions.ParseException;
55

66
import java.util.regex.Matcher;
77
import java.util.regex.Pattern;
@@ -17,9 +17,11 @@
1717
import seedu.address.logic.commands.ViewCommand;
1818
import seedu.address.logic.commands.SetBudgetCommand;
1919
import seedu.address.logic.commands.ShowBudgetCommand;
20-
2120
import seedu.address.logic.parser.exceptions.ParseException;
2221

22+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
23+
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;
24+
2325
/**
2426
* Parses user input.
2527
*/
@@ -57,6 +59,21 @@ public Command parseCommand(String userInput) throws ParseException {
5759
case ListExpenseCommand.COMMAND_WORD:
5860
return new ListExpenseCommand();
5961

62+
case ViewCommand.COMMAND_WORD:
63+
return new ViewCommandParser().parse(arguments);
64+
65+
case ViewCategoryCommand.COMMAND_WORD:
66+
return new ViewCategoryCommandParser().parse(arguments);
67+
68+
case DeleteDescriptionCommand.COMMAND_WORD:
69+
return new DeleteDescriptionCommandParser().parse(arguments);
70+
71+
case DeleteExpenseCommand.COMMAND_WORD:
72+
return new DeleteExpenseCommandParser().parse(arguments);
73+
74+
case ListExpenseCommand.COMMAND_WORD:
75+
return new ListExpenseCommand();
76+
6077
case ListExpenseByCategoryCommand.COMMAND_WORD:
6178
return new ListExpenseByCategoryCommandParser().parse(arguments);
6279

@@ -71,7 +88,7 @@ public Command parseCommand(String userInput) throws ParseException {
7188

7289
case SetBudgetCommand.COMMAND_WORD:
7390
return new SetBudgetCommandParser().parse(arguments);
74-
91+
7592
default:
7693
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
7794
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
package seedu.address.logic.parser;
22

3-
public class ViewCategoryCommandParser {
3+
import seedu.address.commons.core.index.Index;
4+
import seedu.address.commons.exceptions.IllegalValueException;
5+
import seedu.address.logic.commands.DescriptionCommand;
6+
import seedu.address.logic.commands.ShowBudgetCommand;
7+
import seedu.address.logic.commands.ViewCategoryCommand;
8+
import seedu.address.logic.parser.exceptions.ParseException;
9+
import seedu.address.model.person.Description;
10+
11+
import static java.util.Objects.requireNonNull;
12+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
13+
import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY;
14+
15+
public class ViewCategoryCommandParser implements Parser<ViewCategoryCommand>{
16+
@Override
17+
public ViewCategoryCommand parse(String args) throws ParseException {
18+
return new ViewCategoryCommand();
19+
}
420
}

src/main/java/seedu/address/model/ExpenseBook.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import javafx.collections.ObservableList;
88
import seedu.address.commons.core.index.Index;
9+
import seedu.address.model.person.Category;
910
import seedu.address.model.person.Expense;
1011
import seedu.address.model.person.UniqueExpenseList;
1112

@@ -145,4 +146,8 @@ public double getRemainingBudget() {
145146
}
146147
//end of yuanxing edits
147148

149+
public List<Category> getCategoryLabels(){
150+
return expenses.getCategoryLabels();
151+
}
152+
148153
}

src/main/java/seedu/address/model/ExpenseModelManager.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
55

66
import java.nio.file.Path;
7+
import java.util.List;
78
import java.util.function.Predicate;
89
import java.util.logging.Logger;
910

@@ -12,6 +13,7 @@
1213
import seedu.address.commons.core.GuiSettings;
1314
import seedu.address.commons.core.LogsCenter;
1415
import seedu.address.commons.core.index.Index;
16+
import seedu.address.model.person.Category;
1517
import seedu.address.model.person.Expense;
1618
import seedu.address.model.person.Person;
1719

@@ -26,6 +28,7 @@ public class ExpenseModelManager implements Model {
2628
private final FilteredList<Expense> filteredExpenses;
2729

2830

31+
2932
/**
3033
* Initializes a ModelManager with the given addressBook and userPrefs.
3134
*/
@@ -120,15 +123,6 @@ public void setExpense(Expense target, Expense editedExpense) {
120123
expenseBook.setExpense(target, editedExpense);
121124
}
122125

123-
/**
124-
* View the detals of a certain expense.
125-
*
126-
* @param index The index of the expense to be viewed in the ExpenseBook.
127-
*/
128-
public void viewExpense(Index index) {
129-
expenseBook.viewExpense(index);
130-
}
131-
132126
//=========== Filtered Expense List Accessors =============================================================
133127

134128
/**
@@ -191,5 +185,10 @@ public void setExpenseBookBudget(double budget) {
191185
expenseBook.setBudget(budget);
192186
}
193187

188+
@Override
189+
public List<Category> getCategoryLabels() {
190+
return expenseBook.getCategoryLabels();
191+
}
192+
194193

195194
}

src/main/java/seedu/address/model/Model.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package seedu.address.model;
22

33
import java.nio.file.Path;
4+
import java.util.List;
45
import java.util.function.Predicate;
56

67
import javafx.collections.ObservableList;
78
import seedu.address.commons.core.GuiSettings;
9+
import seedu.address.commons.core.index.Index;
10+
import seedu.address.model.person.Category;
811
import seedu.address.model.person.Expense;
912
import seedu.address.model.person.Person;
1013

@@ -101,4 +104,6 @@ public interface Model {
101104
double getExpenseBookRemaining();
102105

103106
void setExpenseBookBudget(double budget);
107+
108+
List<Category> getCategoryLabels();
104109
}

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
55

66
import java.nio.file.Path;
7+
import java.util.List;
78
import java.util.function.Predicate;
89
import java.util.logging.Logger;
910

1011
import javafx.collections.ObservableList;
1112
import javafx.collections.transformation.FilteredList;
1213
import seedu.address.commons.core.GuiSettings;
1314
import seedu.address.commons.core.LogsCenter;
15+
import seedu.address.commons.core.index.Index;
16+
import seedu.address.model.person.Category;
1417
import seedu.address.model.person.Expense;
1518
import seedu.address.model.person.Person;
1619

@@ -26,7 +29,6 @@ public class ModelManager implements Model {
2629

2730
private final FilteredList<Expense> filteredExpenses;
2831

29-
private Expense expenseToBeViewed;
3032

3133
/**
3234
* Initializes a ModelManager with the given addressBook and userPrefs.
@@ -198,6 +200,11 @@ public void setExpenseBookBudget(double budget) {
198200

199201
}
200202

203+
@Override
204+
public List<Category> getCategoryLabels() {
205+
return null;
206+
}
207+
201208
@Override
202209
public boolean equals(Object obj) {
203210
// short circuit if same object

src/main/java/seedu/address/model/person/Expense.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,27 @@ public String toString() {
8989
if (description.isEmpty()) {
9090
builder.append(" Amount: ")
9191
.append(this.getAmount())
92+
.append("\n")
9293
.append(" Date: ")
9394
.append(this.getDate())
95+
.append("\n")
9496
.append(" Category: ")
95-
.append(this.getCategory());
97+
.append(this.getCategory())
98+
.append("\n");
9699
return builder.toString();
97100
} else {
98101
builder.append(" Amount: ")
99102
.append(this.getAmount())
100-
.append("/n")
103+
.append("\n")
101104
.append(" Date: ")
102105
.append(this.getDate())
106+
.append("\n")
103107
.append(" Category: ")
104-
.append("/n")
105108
.append(this.getCategory())
109+
.append("\n")
106110
.append(" Description: ")
107111
.append(this.getDescription())
108-
.append("/n");
112+
.append("\n");
109113
return builder.toString();
110114
}
111115
}

src/main/java/seedu/address/model/person/UniqueExpenseList.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static java.util.Objects.requireNonNull;
55
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
66

7+
import java.util.ArrayList;
78
import java.util.Iterator;
89
import java.util.List;
910

@@ -159,9 +160,21 @@ public double getBudget() {
159160

160161
public double getRemainingBudget() {
161162
double used = 0;
162-
for (int i = 0; i < internalList.size() - 1; i++) {
163+
for (int i = 0; i < internalList.size(); i++) {
163164
used += internalList.get(i).getAmount().getValue();
164165
}
165166
return this.budget - used;
166167
}
168+
169+
public List<Category> getCategoryLabels(){
170+
List<Category> categories = new ArrayList<>();
171+
for(int i = 0; i < internalList.size(); i++) {
172+
Expense current = internalList.get(i);
173+
Category currentCategory = current.getCategory();
174+
if(!categories.contains(currentCategory)){
175+
categories.add(currentCategory);
176+
}
177+
}
178+
return categories;
179+
}
167180
}

0 commit comments

Comments
 (0)