Skip to content

Commit

Permalink
Merge pull request AY2425S1-CS2103-F09-1#53 from WinstonJin/Telegram-…
Browse files Browse the repository at this point in the history
…Handle

Telegram Handle
  • Loading branch information
LowXiSi authored Oct 10, 2024
2 parents 07e3c69 + 96aef89 commit b1b2790
Show file tree
Hide file tree
Showing 30 changed files with 334 additions and 330 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
public static String format(Person person) {
final StringBuilder builder = new StringBuilder();
builder.append(person.getName())
.append("; Phone: ")
.append(person.getPhone())
.append("; Telegram: ")
.append(person.getTelegram())
.append("; Email: ")
.append(person.getEmail())
.append("; Address: ")
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NICKNAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;

import seedu.address.commons.util.ToStringBuilder;
Expand All @@ -24,14 +24,14 @@ public class AddCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_TELEGRAM + "TELEGRAM "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_ROLE + "ROLE]...\n"
+ "[" + PREFIX_NICKNAME + "NICKNAME]\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_TELEGRAM + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_ROLE + "Admin "
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

Expand All @@ -25,7 +25,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Telegram;
import seedu.address.model.tag.Nickname;
import seedu.address.model.tag.Role;

Expand All @@ -41,12 +41,12 @@ public class EditCommand extends Command {
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_TELEGRAM + "TELEGRAM] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_ROLE + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_TELEGRAM + "91234567 "
+ PREFIX_EMAIL + "[email protected]";

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s";
Expand Down Expand Up @@ -97,12 +97,12 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
assert personToEdit != null;

Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName());
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone());
Telegram updatedTelegram = editPersonDescriptor.getTelegram().orElse(personToEdit.getTelegram());
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Role> updatedRoles = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Nickname updatedNickname = editPersonDescriptor.getNickname().orElse(personToEdit.getNickname());
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedRoles, updatedNickname);
return new Person(updatedName, updatedTelegram, updatedEmail, updatedAddress, updatedRoles, updatedNickname);
}

@Override
Expand Down Expand Up @@ -135,7 +135,7 @@ public String toString() {
*/
public static class EditPersonDescriptor {
private Name name;
private Phone phone;
private Telegram telegram;
private Email email;
private Address address;
private Set<Role> roles;
Expand All @@ -149,7 +149,7 @@ public EditPersonDescriptor() {}
*/
public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setName(toCopy.name);
setPhone(toCopy.phone);
setTelegram(toCopy.telegram);
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.roles);
Expand All @@ -160,7 +160,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, roles);
return CollectionUtil.isAnyNonNull(name, telegram, email, address, roles);
}

public void setName(Name name) {
Expand All @@ -171,12 +171,12 @@ public Optional<Name> getName() {
return Optional.ofNullable(name);
}

public void setPhone(Phone phone) {
this.phone = phone;
public void setTelegram(Telegram telegram) {
this.telegram = telegram;
}

public Optional<Phone> getPhone() {
return Optional.ofNullable(phone);
public Optional<Telegram> getTelegram() {
return Optional.ofNullable(telegram);
}

public void setEmail(Email email) {
Expand Down Expand Up @@ -233,7 +233,7 @@ public boolean equals(Object other) {

EditPersonDescriptor otherEditPersonDescriptor = (EditPersonDescriptor) other;
return Objects.equals(name, otherEditPersonDescriptor.name)
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(telegram, otherEditPersonDescriptor.telegram)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(roles, otherEditPersonDescriptor.roles)
Expand All @@ -244,7 +244,7 @@ public boolean equals(Object other) {
public String toString() {
return new ToStringBuilder(this)
.add("name", name)
.add("phone", phone)
.add("telegram", telegram)
.add("email", email)
.add("address", address)
.add("tags", roles)
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NICKNAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;

import java.util.Set;
Expand All @@ -17,7 +17,7 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Telegram;
import seedu.address.model.tag.Nickname;
import seedu.address.model.tag.Role;

Expand All @@ -33,24 +33,22 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS,
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TELEGRAM, PREFIX_EMAIL, PREFIX_ADDRESS,
PREFIX_ROLE, PREFIX_NICKNAME);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ROLE)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_TELEGRAM, PREFIX_EMAIL, PREFIX_ROLE)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_TELEGRAM, PREFIX_EMAIL, PREFIX_ADDRESS);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Telegram telegram = ParserUtil.parseTelegram(argMultimap.getValue(PREFIX_TELEGRAM).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Role> roleList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_ROLE));

Nickname nickname = ParserUtil.parseNickname(argMultimap.getValue(PREFIX_NICKNAME).orElse(""));

Person person = new Person(name, phone, email, address, roleList, nickname);
Person person = new Person(name, telegram, email, address, roleList, nickname);

return new AddCommand(person);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ public class CliSyntax {

/* Prefix definitions */
public static final Prefix PREFIX_NAME = new Prefix("n/");
public static final Prefix PREFIX_PHONE = new Prefix("p/");
public static final Prefix PREFIX_TELEGRAM = new Prefix("th/");
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_ROLE = new Prefix("r/");
public static final Prefix PREFIX_NICKNAME = new Prefix("nn/");

}
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;

import java.util.Collection;
Expand All @@ -31,7 +31,7 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_ROLE);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_TELEGRAM, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_ROLE);

Index index;

Expand All @@ -41,15 +41,15 @@ public EditCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_TELEGRAM, PREFIX_EMAIL, PREFIX_ADDRESS);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

if (argMultimap.getValue(PREFIX_NAME).isPresent()) {
editPersonDescriptor.setName(ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()));
}
if (argMultimap.getValue(PREFIX_PHONE).isPresent()) {
editPersonDescriptor.setPhone(ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()));
if (argMultimap.getValue(PREFIX_TELEGRAM).isPresent()) {
editPersonDescriptor.setTelegram(ParserUtil.parseTelegram(argMultimap.getValue(PREFIX_TELEGRAM).get()));
}
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Telegram;
import seedu.address.model.tag.Nickname;
import seedu.address.model.tag.Role;

Expand Down Expand Up @@ -52,18 +52,18 @@ public static Name parseName(String name) throws ParseException {
}

/**
* Parses a {@code String phone} into a {@code Phone}.
* Parses a {@code String telegram} into a {@code Telegram}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code phone} is invalid.
* @throws ParseException if the given {@code telegram} is invalid.
*/
public static Phone parsePhone(String phone) throws ParseException {
requireNonNull(phone);
String trimmedPhone = phone.trim();
if (!Phone.isValidPhone(trimmedPhone)) {
throw new ParseException(Phone.MESSAGE_CONSTRAINTS);
public static Telegram parseTelegram(String telegram) throws ParseException {
requireNonNull(telegram);
String trimmedTelegram = telegram.trim();
if (!Telegram.isValidTelegram(trimmedTelegram)) {
throw new ParseException(Telegram.MESSAGE_CONSTRAINTS);
}
return new Phone(trimmedPhone);
return new Telegram(trimmedTelegram);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Person {

// Identity fields
private final Name name;
private final Phone phone;
private final Telegram telegram;
private final Email email;

// Data fields
Expand All @@ -30,10 +30,10 @@ public class Person {
/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Role> roles, Nickname nickname) {
requireAllNonNull(name, phone, email, address, roles, nickname);
public Person(Name name, Telegram telegram, Email email, Address address, Set<Role> roles, Nickname nickname) {
requireAllNonNull(name, telegram, email, address, roles, nickname);
this.name = name;
this.phone = phone;
this.telegram = telegram;
this.email = email;
this.address = address;
this.roles.addAll(roles);
Expand All @@ -44,8 +44,8 @@ public Name getName() {
return name;
}

public Phone getPhone() {
return phone;
public Telegram getTelegram() {
return telegram;
}

public Email getEmail() {
Expand Down Expand Up @@ -98,7 +98,7 @@ public boolean equals(Object other) {

Person otherPerson = (Person) other;
return name.equals(otherPerson.name)
&& phone.equals(otherPerson.phone)
&& telegram.equals(otherPerson.telegram)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& roles.equals(otherPerson.roles)
Expand All @@ -108,14 +108,14 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, address, roles, nickname);
return Objects.hash(name, telegram, email, address, roles, nickname);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("name", name)
.add("phone", phone)
.add("telegram", telegram)
.add("email", email)
.add("address", address)
.add("tags", roles)
Expand Down
Loading

0 comments on commit b1b2790

Please sign in to comment.