forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Update delete contact functionality #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CJ-Lee01
merged 41 commits into
AY2324S1-CS2103T-W08-3:master
from
CJ-Lee01:branch-delete-contacts
Oct 17, 2023
Merged
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
53ab114
Add factory method for DeleteCommand
CJ-Lee01 ead20a1
Add subclass for DeleteCommand
CJ-Lee01 5f132cf
Add tasks in comments
CJ-Lee01 ed10bab
Add getChildren method for Contact
CJ-Lee01 e9f6f02
Add addChild method for Contact
CJ-Lee01 b077f23
Add new exception for illegal operations
CJ-Lee01 ff7ae08
Add exception thrown when calling addChild
CJ-Lee01 2805ec6
Add javadocs to delete commands
CJ-Lee01 1ad1b59
Add javadocs for Contact methods
CJ-Lee01 5722054
Fix style issues in DeleteCommand
CJ-Lee01 8ef6769
Add ContactId
CJ-Lee01 5033786
Add DeleteByIdCommand
CJ-Lee01 26f4670
Add DeleteByIdWithChildrenCommand
CJ-Lee01 538c16d
Update javadocs of delete commands
CJ-Lee01 f87453f
Add select ID for delete command
CJ-Lee01 4dfabe6
Add functionality to delete child contacts
CJ-Lee01 5a14f7b
Merge branch 'master' into branch-delete-contacts
CJ-Lee01 8a35390
Add hashcode function to ContactId
CJ-Lee01 f66a7ff
Add regex to ContactId
CJ-Lee01 79db31c
Add functionality to get contact by id
CJ-Lee01 93add45
Add javadocs to AddressBook
CJ-Lee01 6e99018
Add functionality to get contact by id in Model
CJ-Lee01 ee662e9
Implement delete by id commands
CJ-Lee01 ea0c0d3
Fix formatting and spelling errors
CJ-Lee01 a9b73c1
Fix checkstyle issues
CJ-Lee01 83126be
Implement new model method in test
CJ-Lee01 ad8194f
Nuke delete by id commands
CJ-Lee01 6b30a6e
Add no such contact exception message
CJ-Lee01 74baba9
Implement delete by id in DeleteCommand classes
CJ-Lee01 59cc772
Update javadocs for DeleteCommand classes
CJ-Lee01 70d7ca0
Add parseContactId method
CJ-Lee01 7fbe9a7
Merge branch 'master' into branch-delete-contacts
CJ-Lee01 fc915f9
Change ContactId to Id
CJ-Lee01 667451d
Add recursive flag to CliSyntax
CJ-Lee01 91d7f6f
Update DeleteCommandParser to delete id
CJ-Lee01 df0eeea
Fix wrong recursive delete message
CJ-Lee01 39aa1a6
Merge branch 'master' into branch-delete-contacts
CJ-Lee01 8dc9d58
Remove unncessary comment
CJ-Lee01 2e72dc4
Fix name for static field in Contact
CJ-Lee01 91974fe
Add todo for Organization
CJ-Lee01 3503f6e
Merge branch 'master' into branch-delete-contacts
CJ-Lee01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/java/seedu/address/commons/exceptions/IllegalOperationException.java
This file contains hidden or 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,21 @@ | ||
package seedu.address.commons.exceptions; | ||
|
||
/** | ||
* Exception thrown when attempting to make illegal. | ||
*/ | ||
public class IllegalOperationException extends Exception { | ||
/** | ||
* @param message that informs the user that it has attempted an illegal operation. | ||
*/ | ||
public IllegalOperationException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* @param message that informs the user that it has attempted an illegal operation. | ||
* @param cause of the main exception. | ||
*/ | ||
public IllegalOperationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
56 changes: 56 additions & 0 deletions
56
src/main/java/seedu/address/logic/commands/DeleteWithChildrenCommand.java
This file contains hidden or 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,56 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Arrays; | ||
|
||
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.Contact; | ||
import seedu.address.model.person.Id; | ||
|
||
/** | ||
* Deletes a contact and also deletes its child contacts. | ||
*/ | ||
public class DeleteWithChildrenCommand extends DeleteCommand { | ||
|
||
public static final String MESSAGE_DELETE_CONTACT_SUCCESS = DeleteCommand.MESSAGE_DELETE_CONTACT_SUCCESS + " with" | ||
+ ":\n%2$s"; | ||
|
||
|
||
/** | ||
* @param targetIndex of the contact to be deleted in the current contact list | ||
*/ | ||
public DeleteWithChildrenCommand(Index targetIndex) { | ||
// TODO add documentation in DG | ||
super(targetIndex); | ||
} | ||
|
||
public DeleteWithChildrenCommand(Id targetId) { | ||
super(targetId); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
Contact contactToDelete = super.getContact(model); | ||
super.execute(model); | ||
// At this point if the contact is null, the superclass would have thrown exception. | ||
// Superclass would have also deleted the contact from the list. | ||
assert contactToDelete != null; | ||
Contact[] childContacts = contactToDelete.getChildren(); | ||
Arrays.stream(childContacts).forEach(contact -> { | ||
model.deleteContact(contactToDelete); | ||
}); | ||
return new CommandResult(String.format( | ||
MESSAGE_DELETE_CONTACT_SUCCESS, | ||
Messages.format(contactToDelete), | ||
Arrays.stream(childContacts) | ||
.map(c -> Messages.format(c) + "\n") | ||
.reduce((c1, c2) -> c1 + c2) | ||
.orElse("No other contacts found") // I can't find a better method. | ||
)); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.