forked from nus-cs2103-AY2324S1/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 #58 from MadLamprey/branch-addLCommand
Add LinkedIn and Github Command functionalities
- Loading branch information
Showing
27 changed files
with
690 additions
and
75 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
51 changes: 51 additions & 0 deletions
51
src/main/java/seedu/address/logic/commands/GithubCommand.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,51 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import java.awt.Desktop; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Redirects user to the Github account of a specific candidates. | ||
*/ | ||
public class GithubCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "github"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Redirects to user's Github account. " | ||
+ "Parameters: " + "[" + COMMAND_WORD + " <USERID>]...\n" | ||
+ "Example: " + COMMAND_WORD + " 2"; | ||
public static final String MESSAGE_SUCCESS = "Redirecting to Github ..."; | ||
|
||
private final Index index; | ||
|
||
public GithubCommand(Index index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
String username = personToEdit.getGithub().value; | ||
String githubUrl = "https://github.com/" + username; | ||
try { | ||
Desktop.getDesktop().browse(new URI(githubUrl)); | ||
} catch (IOException | URISyntaxException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
|
||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/seedu/address/logic/commands/LinkedInCommand.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,51 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import java.awt.Desktop; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Redirects the user to the LinkedIn account of a specific candidate. | ||
*/ | ||
public class LinkedInCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "linkedin"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Redirects to user's LinkedIn account. " | ||
+ "Parameters: " + "[" + COMMAND_WORD + " <USERID>]...\n" | ||
+ "Example: " + COMMAND_WORD + " 2"; | ||
public static final String MESSAGE_SUCCESS = "Redirecting to LinkedIn ..."; | ||
|
||
private final Index index; | ||
|
||
public LinkedInCommand(Index index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToEdit = lastShownList.get(index.getZeroBased()); | ||
String username = personToEdit.getLinkedIn().value; | ||
String linkedInUrl = "https://www.linkedin.com/in/" + username; | ||
try { | ||
Desktop.getDesktop().browse(new URI(linkedInUrl)); | ||
} catch (IOException | URISyntaxException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
|
||
return new CommandResult(MESSAGE_SUCCESS); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/seedu/address/logic/parser/AddGCommandParser.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,39 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_USERNAME; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AddGCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.Github; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddLCommand object | ||
*/ | ||
public class AddGCommandParser implements Parser<AddGCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddLCommand | ||
* and returns an AddLCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddGCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultiMap = ArgumentTokenizer.tokenize(args, PREFIX_USERNAME); | ||
|
||
Index index; | ||
|
||
try { | ||
index = ParserUtil.parseIndex(argMultiMap.getPreamble()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddGCommand.MESSAGE_USAGE), pe); | ||
} | ||
|
||
index = ParserUtil.parseIndex(argMultiMap.getPreamble()); | ||
String username = argMultiMap.getValue(PREFIX_USERNAME).orElse(""); | ||
|
||
return new AddGCommand(index, new Github(username)); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/seedu/address/logic/parser/AddLCommandParser.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,38 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_USERNAME; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AddLCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.person.LinkedIn; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddLCommand object | ||
*/ | ||
public class AddLCommandParser implements Parser<AddLCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddLCommand | ||
* and returns an AddLCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddLCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultiMap = ArgumentTokenizer.tokenize(args, PREFIX_USERNAME); | ||
Index index; | ||
|
||
try { | ||
index = ParserUtil.parseIndex(argMultiMap.getPreamble()); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddLCommand.MESSAGE_USAGE), pe); | ||
} | ||
|
||
index = ParserUtil.parseIndex(argMultiMap.getPreamble()); | ||
String username = argMultiMap.getValue(PREFIX_USERNAME).orElse(""); | ||
|
||
return new AddLCommand(index, new LinkedIn(username)); | ||
} | ||
} |
Oops, something went wrong.