Skip to content

Commit

Permalink
Merge pull request #28 from vvhuiling/view-feature
Browse files Browse the repository at this point in the history
Add the ability to view
  • Loading branch information
spaceman03 authored Oct 18, 2023
2 parents 237dc46 + 55109d6 commit 3dec0fc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/seedu/nuscents/commands/ListOfCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class ListOfCommands {
public static final String COMMAND_EVENT = "event";
public static final String COMMAND_DELETE = "delete";
public static final String COMMAND_FIND = "find";
public static final String COMMAND_VIEW = "view";
public static final String COMMAND_HELP = "help";
}
15 changes: 15 additions & 0 deletions src/main/java/seedu/nuscents/commands/ViewCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package seedu.nuscents.commands;

import seedu.nuscents.data.TransactionList;

public class ViewCommand extends Command {
private int taskIndex;

public ViewCommand (int taskIndex) {
this.taskIndex = taskIndex;
}
@Override
public void execute(TransactionList tasks) {
tasks.viewTransaction(taskIndex);
}
}
5 changes: 5 additions & 0 deletions src/main/java/seedu/nuscents/data/TransactionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,10 @@ public void findTask(String keyword) {
}
System.out.println(LINE);
}

public void viewTransaction(int transactionIndex) {
Transaction transaction = transactions.get(transactionIndex-1);
Ui.showTransactionViewMessage(transaction);
}
}

4 changes: 4 additions & 0 deletions src/main/java/seedu/nuscents/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.nuscents.commands.FindCommand;
import seedu.nuscents.commands.HelpCommand;
import seedu.nuscents.commands.InvalidCommand;
import seedu.nuscents.commands.ViewCommand;


import seedu.nuscents.data.Transaction;
Expand All @@ -26,6 +27,7 @@
import static seedu.nuscents.commands.ListOfCommands.COMMAND_DELETE;
import static seedu.nuscents.commands.ListOfCommands.COMMAND_FIND;
import static seedu.nuscents.commands.ListOfCommands.COMMAND_HELP;
import static seedu.nuscents.commands.ListOfCommands.COMMAND_VIEW;
import static seedu.nuscents.ui.Messages.MESSAGE_EMPTY_ALLOWANCE;
import static seedu.nuscents.ui.Messages.MESSAGE_EMPTY_EXPENSE;
import static seedu.nuscents.ui.Messages.MESSAGE_EMPTY_INDEX;
Expand Down Expand Up @@ -66,6 +68,8 @@ public static <TaskList> Command parseCommand(String text, TaskList tasks) throw
return new DeleteCommand(parseTaskIndex(arguments));
case COMMAND_FIND:
return new FindCommand(parseFind(arguments));
case COMMAND_VIEW:
return new ViewCommand(parseTaskIndex(arguments));
case COMMAND_HELP:
if (arguments != null) {
throw new NuscentsException("OOPS!!! The correct format is 'help' alone.");
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/nuscents/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ public static void showReadDataError() {
System.out.println(LINE);
}

public static void showTransactionViewMessage(Transaction transaction) {
System.out.println(LINE);
System.out.println("Following are details of the transaction:");
if (transaction instanceof Allowance) {
System.out.println("TYPE: ALLOWANCE");
} else if (transaction instanceof Expense) {
System.out.println("TYPE: EXPENSE");
}
System.out.println("DATE: " + transaction.getFormattedDate());
System.out.println("AMOUNT: " + transaction.getAmount());
System.out.println("DESCRIPTION: " + transaction.getDescription());
System.out.println("NOTE: " + transaction.getAdditionalInfo());
System.out.println(LINE);
}


public static void showHelpMenu() {
System.out.println(LINE);
System.out.println(Messages.HELP_MENU);
Expand Down

0 comments on commit 3dec0fc

Please sign in to comment.