forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
338 additions
and
3 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/main/java/seedu/address/logic/commands/ViewClientCommand.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,62 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.function.Predicate; | ||
import java.util.logging.Logger; | ||
|
||
import seedu.address.commons.core.LogsCenter; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.commons.core.index.Index; | ||
|
||
public class ViewClientCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "viewclient"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Views the client identified by the index number used in the listclient list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Viewed Client Successfully"; | ||
public static final String MESSAGE_INVALID_INDEX = "Invalid Client index"; | ||
public static final String MESSAGE_NOT_A_CLIENT = "The person at the specified index is not a client."; | ||
|
||
|
||
public static final Logger logger = LogsCenter.getLogger(ViewClientCommand.class); | ||
|
||
private final Index targetIndex; | ||
|
||
public ViewClientCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
|
||
if (targetIndex.getZeroBased() < 0) { | ||
return new CommandResult(MESSAGE_INVALID_INDEX); | ||
} | ||
|
||
Person clientToView = model.getFilteredPersonList().get(targetIndex.getZeroBased()); | ||
|
||
Predicate<Person> VIEW_CLIENT_PREDICATE = person -> person.equals(clientToView); | ||
|
||
model.updateFilteredPersonList(VIEW_CLIENT_PREDICATE); | ||
|
||
if (!VIEW_CLIENT_PREDICATE.test(clientToView)) { | ||
return new CommandResult(MESSAGE_NOT_A_CLIENT); | ||
} | ||
|
||
logger.info("Target Index: " + targetIndex.getZeroBased()); | ||
logger.info("Client to View: " + clientToView); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
} | ||
|
||
|
||
|
31 changes: 31 additions & 0 deletions
31
src/main/java/seedu/address/logic/commands/ViewCommand.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,31 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
public class ViewCommand extends Command { | ||
public static final String COMMAND_WORD = "view"; | ||
|
||
public static final String MESSAGE_SUCCESS = "View person success"; | ||
|
||
private final int targetIndex; | ||
|
||
public ViewCommand(int targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
Person personToView = model.getPersonByIndex(targetIndex); | ||
|
||
if (personToView != null) { | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} else { | ||
return new CommandResult("Person not found at index " + targetIndex); | ||
} | ||
} | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
src/main/java/seedu/address/logic/commands/ViewLeadCommand.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,62 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.function.Predicate; | ||
import java.util.logging.Logger; | ||
|
||
import seedu.address.commons.core.LogsCenter; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.commons.core.index.Index; | ||
|
||
public class ViewLeadCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "viewlead"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Views the client identified by the index number used in the listlead list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Viewed Client Successfully"; | ||
public static final String MESSAGE_INVALID_INDEX = "Invalid Client index"; | ||
public static final String MESSAGE_NOT_A_LEAD = "The person at the specified index is not a lead."; | ||
|
||
|
||
public static final Logger logger = LogsCenter.getLogger(ViewClientCommand.class); | ||
|
||
private final Index targetIndex; | ||
|
||
public ViewLeadCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
|
||
if (targetIndex.getZeroBased() < 0 || targetIndex.getZeroBased() >= model.getFilteredPersonList().size()) { | ||
return new CommandResult(MESSAGE_INVALID_INDEX); | ||
} | ||
|
||
Person leadToView = model.getFilteredPersonList().get(targetIndex.getZeroBased()); | ||
|
||
Predicate<Person> VIEW_LEAD_PREDICATE = person -> person.equals(leadToView); | ||
|
||
model.updateFilteredPersonList(VIEW_LEAD_PREDICATE); | ||
|
||
if (!VIEW_LEAD_PREDICATE.test(leadToView)) { | ||
return new CommandResult(MESSAGE_NOT_A_LEAD); | ||
} | ||
|
||
logger.info("Target Index: " + targetIndex.getZeroBased()); | ||
logger.info("Client to View: " + leadToView); | ||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
|
||
} | ||
|
||
|
||
|
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
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/ViewClientCommandParser.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,29 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.ViewClientCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteCommand object | ||
*/ | ||
public class ViewClientCommandParser implements Parser<ViewClientCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns a DeleteCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ViewClientCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new ViewClientCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewClientCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/ViewLeadCommandParser.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,29 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.ViewLeadCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new DeleteCommand object | ||
*/ | ||
public class ViewLeadCommandParser implements Parser<ViewLeadCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns a DeleteCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ViewLeadCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new ViewLeadCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewLeadCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.