forked from nus-cs2113-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Chinorea/branch-display-income
Add Display Income with Filters
- Loading branch information
Showing
9 changed files
with
192 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/seedu/budgetbuddy/commands/DisplayIncomeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package seedu.budgetbuddy.commands; | ||
|
||
import seedu.budgetbuddy.transaction.income.IncomeManager; | ||
|
||
import java.time.YearMonth; | ||
|
||
public class DisplayIncomeCommand extends Command { | ||
|
||
private YearMonth month; | ||
|
||
/** | ||
* Constructs a DisplayIncomeCommand with no specified month | ||
*/ | ||
public DisplayIncomeCommand() { | ||
this.month = null; | ||
} | ||
|
||
/** | ||
* Constructs a DisplayIncomeCommand with a valid month field | ||
* @param month | ||
*/ | ||
public DisplayIncomeCommand(YearMonth month) { | ||
this.month = month; | ||
} | ||
|
||
/** | ||
* Checks if the provided command matches the command to display income. | ||
* | ||
* @param command The command to be checked. | ||
* @return True if the command matches "display expenses", false otherwise. | ||
*/ | ||
public static boolean isCommand(String command) { return command.startsWith("display incomes"); } | ||
|
||
@Override | ||
public void execute() { | ||
if(month == null) { | ||
IncomeManager.listIncomes(); | ||
} | ||
else{ | ||
IncomeManager.displayIncomeWithMonth(month); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/seedu/budgetbuddy/validators/DisplayIncomeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package seedu.budgetbuddy.validators; | ||
|
||
import seedu.budgetbuddy.commands.Command; | ||
import seedu.budgetbuddy.commands.DisplayIncomeCommand; | ||
import seedu.budgetbuddy.commands.IncorrectCommand; | ||
|
||
import java.time.YearMonth; | ||
|
||
import static seedu.budgetbuddy.validators.DateValidator.validateYearMonth; | ||
|
||
public class DisplayIncomeValidator { | ||
|
||
/** | ||
* Processes the command string to determine if it is valid for displaying income. | ||
* If valid, it returns a DisplayIncomeCommand with the parsed date. | ||
* | ||
* @param command | ||
* @return | ||
*/ | ||
public static Command processCommand(String command) { | ||
if (command.equals("display income")){ | ||
return new DisplayIncomeCommand(); | ||
} | ||
|
||
String trimmedCommand = command.substring("display income ".length()); | ||
String[] parts = trimmedCommand.split(" "); | ||
|
||
//Process Initial Value | ||
YearMonth month = null; | ||
|
||
//Process parts to extract details | ||
for (String part : parts) { | ||
if (part.startsWith("m/")) { | ||
month = validateYearMonth(part); | ||
if (month == null) { | ||
return new IncorrectCommand("Invalid month format. Use m/MM/yyyy."); | ||
} | ||
} | ||
} | ||
|
||
return new DisplayIncomeCommand(month); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters