Skip to content

Commit b6cf083

Browse files
authored
Merge pull request #165 from sheexiong/master
Create a new UserPrefs class for both features and update DG for listamount function.
2 parents ec8317f + 7de513f commit b6cf083

File tree

8 files changed

+212
-9
lines changed

8 files changed

+212
-9
lines changed

docs/DeveloperGuide.adoc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ image::activityDiagram_for_expensesplitter.png[]
299299

300300
The following is a detailed explanation of the operations `DeleteItemCommand` performs. +
301301

302-
1. The `DeieteItemCommand#execute(Model model)` method is executed and it validates that the specified `INDEX` to delete
302+
1. The `DeleteItemCommand#execute(Model model)` method is executed and it validates that the specified `INDEX` to delete
303303
is within range. If valid, the item to be deleted will be retrieved from Receipt using its I`Index`.
304304

305305
2. The method `Model#deleteEntry(int Index) will then be called to remove the Item from the Receipt.
@@ -326,6 +326,21 @@ The following
326326

327327
==== List Amount Command
328328

329+
*Implementation*
330+
331+
The following is a detailed explanation of the operations `ListAmountCommand` performs. +
332+
333+
1. The `ListAmountCommand#execute(Model model)` method is executed.
334+
335+
2. The method `Model#listAmount()` will then be called to return the list of person with amount.
336+
337+
3. `PersonAmountBook#toString()` will convert list of person in the list to the expected format.
338+
339+
The following is a sample sequence diagram of the ListAmountCommand.
340+
341+
image::ExpenseSplitterListAmountCommandSequenceDiagram.png[]
342+
343+
329344
==== Paid Command
330345

331346
==== Back Command

docs/UserGuide.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ EYLAH will calculate the rest for you!
193193
Add item and the person involved in the splitting for that item.
194194

195195
Format: +
196-
`addfood -i ITEMNAME -p PRICE -n ALL` +
197-
`addfood -i ITEMNAME -p PRICE -n NAME [-n NAME]...` +
196+
`additem -i ITEMNAME -p PRICE -n ALL` +
197+
`additem -i ITEMNAME -p PRICE -n NAME [-n NAME]...` +
198198

199199
NOTE: Entering `ALL` will split that item with all Person(s) currently in PersonList.
200200

201201
Example: +
202-
`addfood -i pizza -p 30 -n all` +
203-
`addfood -i pasta -p 19.90 -n john -n bob -n daniel`
202+
`additem -i pizza -p 30 -n all` +
203+
`additem -i pasta -p 19.90 -n john -n bob -n daniel`
204204

205205
==== Delete item `deleteitem`
206206
Delete the item(s) in a receipt:
@@ -214,7 +214,7 @@ Use `listreceipt` to view your item indices before deletion.
214214
Example: +
215215
`deleteitem 3`
216216

217-
==== List person(s) `listamount`
217+
==== List person's amount `listamount`
218218

219219
Display all the Person(s) in the PersonList with the amount they owe you.
220220

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@startuml
2+
!include style.puml
3+
4+
Actor User as user USER_COLOR
5+
Participant ":EYLAH" as ui UI_COLOR
6+
Participant ":LogicManager" as logic LOGIC_COLOR
7+
Participant ":ModelManager" as model MODEL_COLOR
8+
Participant ":PersonAmountBook" as personAmountBook MODEL_COLOR
9+
10+
user -[USER_COLOR]> ui : "listamount"
11+
activate ui UI_COLOR
12+
13+
ui -[UI_COLOR]> logic : execute("listamount")
14+
activate logic LOGIC_COLOR
15+
16+
logic -[LOGIC_COLOR]> model : listAmount()
17+
activate model MODEL_COLOR
18+
19+
model -[MODEL_COLOR]> personAmountBook : toString()
20+
activate personAmountBook MODEL_COLOR
21+
22+
personAmountBook --[STORAGE_COLOR]> model : String
23+
deactivate personAmountBook
24+
25+
model --[STORAGE_COLOR]-> logic : String
26+
deactivate model
27+
28+
logic --[LOGIC_COLOR]> ui : CommandResult
29+
deactivate logic
30+
31+
ui--[UI_COLOR]> user : CommandResult
32+
deactivate ui
33+
@enduml
33.4 KB
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package seedu.eylah.commons.model;
2+
3+
import java.nio.file.Path;
4+
5+
/**
6+
* Unmodifiable view of user prefs.
7+
*/
8+
public interface ReadOnlyUserPrefs {
9+
10+
Path getFoodBookFilePath();
11+
12+
Path getPersonAmountFilePath();
13+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package seedu.eylah.commons.model;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
import java.util.Objects;
8+
9+
/**
10+
* Represents User's preferences.
11+
*/
12+
public class UserPrefs implements ReadOnlyUserPrefs {
13+
14+
private Path foodBookFilePath = Paths.get("data" , "foodbook.json");
15+
private Path personAmountFilePath = Paths.get("data", "personamount.json");
16+
17+
/**
18+
* Creates a {@code UserPrefs} with default values.
19+
*/
20+
public UserPrefs() {}
21+
22+
/**
23+
* Creates a {@code UserPrefs} with the prefs in {@code userPrefs}.
24+
*/
25+
public UserPrefs(UserPrefs userPrefs) {
26+
this();
27+
resetData(userPrefs);
28+
}
29+
30+
/**
31+
* Resets the existing data of this {@code UserPrefs} with {@code newUserPrefs}.
32+
*/
33+
public void resetData(ReadOnlyUserPrefs newUserPrefs) {
34+
requireNonNull(newUserPrefs);
35+
setFoodBookFilePath(newUserPrefs.getFoodBookFilePath());
36+
setPersonAmountFilePath(newUserPrefs.getPersonAmountFilePath());
37+
}
38+
39+
/**
40+
* Returns the FoodBook file path.
41+
*
42+
* @return FoodBook file path
43+
*/
44+
public Path getFoodBookFilePath() {
45+
return foodBookFilePath;
46+
}
47+
48+
/**
49+
* Set the FoodBook file path based on the given path.
50+
*
51+
* @param foodBookFilePath the given file path.
52+
*/
53+
public void setFoodBookFilePath(Path foodBookFilePath) {
54+
requireNonNull(foodBookFilePath);
55+
this.foodBookFilePath = foodBookFilePath;
56+
}
57+
58+
/**
59+
* Returns the PersonAmount file path.
60+
*
61+
* @return PersonAmount file path
62+
*/
63+
public Path getPersonAmountFilePath() {
64+
return personAmountFilePath;
65+
}
66+
67+
/**
68+
* Set the Person Amount file path based on the given path.
69+
*
70+
* @param personAmountFilePath the given file path.
71+
*/
72+
public void setPersonAmountFilePath(Path personAmountFilePath) {
73+
requireNonNull(personAmountFilePath);
74+
this.personAmountFilePath = personAmountFilePath;
75+
}
76+
77+
@Override
78+
public boolean equals(Object other) {
79+
if (other == this) {
80+
return true;
81+
}
82+
if (!(other instanceof UserPrefs)) { //this handles null as well.
83+
return false;
84+
}
85+
86+
UserPrefs o = (UserPrefs) other;
87+
88+
return foodBookFilePath.equals(o.foodBookFilePath)
89+
&& personAmountFilePath.equals(o.personAmountFilePath);
90+
}
91+
92+
@Override
93+
public int hashCode() {
94+
return Objects.hash(foodBookFilePath, personAmountFilePath);
95+
}
96+
97+
@Override
98+
public String toString() {
99+
StringBuilder sb = new StringBuilder();
100+
sb.append(String.format("Local data file location : %s %s", foodBookFilePath, personAmountFilePath));
101+
return sb.toString();
102+
}
103+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package seedu.eylah.commons.storage;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Path;
5+
import java.util.Optional;
6+
7+
import seedu.eylah.commons.exceptions.DataConversionException;
8+
import seedu.eylah.commons.model.ReadOnlyUserPrefs;
9+
import seedu.eylah.commons.model.UserPrefs;
10+
11+
/**
12+
* Represents a storage for {@link UserPrefs}.
13+
*/
14+
public interface UserPrefsStorage {
15+
16+
/**
17+
* Returns the file path of the UserPrefs data file.
18+
*/
19+
Path getUserPrefsFilePath();
20+
21+
/**
22+
* Returns UserPrefs data from storage.
23+
* Returns {@code Optional.empty()} if storage file is not found.
24+
* @throws DataConversionException if the data in storage is not in the expected format.
25+
* @throws IOException if there was any problem when reading from the storage.
26+
*/
27+
Optional<UserPrefs> readUserPrefs() throws DataConversionException, IOException;
28+
29+
/**
30+
* Saves the given {@link ReadOnlyUserPrefs} to the storage.
31+
* @param userPrefs cannot be null.
32+
* @throws IOException if there was any problem writing to the file.
33+
*/
34+
void saveUserPrefs(ReadOnlyUserPrefs userPrefs) throws IOException;
35+
}

src/main/java/seedu/eylah/expensesplitter/storage/JsonUserPrefsStorage.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public JsonUserPrefsStorage(Path filePath) {
2222

2323
@Override
2424
public Path getUserPrefsFilePath() {
25-
2625
return filePath;
2726
}
2827

@@ -31,8 +30,13 @@ public Optional<UserPrefs> readUserPrefs() throws DataConversionException {
3130
return readUserPrefs(filePath);
3231
}
3332

34-
public Optional<UserPrefs> readUserPrefs(Path presFilePath) throws DataConversionException {
35-
return JsonUtil.readJsonFile(presFilePath, UserPrefs.class);
33+
/**
34+
* Similar to {@link #readUserPrefs()}
35+
* @param prefsFilePath location of the data. Cannot be null.
36+
* @throws DataConversionException if the file format is not as expected.
37+
*/
38+
public Optional<UserPrefs> readUserPrefs(Path prefsFilePath) throws DataConversionException {
39+
return JsonUtil.readJsonFile(prefsFilePath, UserPrefs.class);
3640
}
3741

3842
@Override

0 commit comments

Comments
 (0)