Skip to content

Commit

Permalink
Merge pull request #220 from nicholastng010601/back-up-latest
Browse files Browse the repository at this point in the history
Update delete time message
  • Loading branch information
Kailash201 authored Nov 4, 2023
2 parents 17237fe + 9e834be commit 910d8d3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public DeleteGroupTimeCommand(Group group, ArrayList<TimeInterval> timeIntervals
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
String commandOutcome;
if (model.hasGroup(group)) {
model.deleteTimeFromGroup(group, timeIntervalsToDelete);
commandOutcome = model.deleteTimeFromGroup(group, timeIntervalsToDelete);
} else {
throw new CommandException("Group does not exists");
}
return new CommandResult(String.format(MESSAGE_DELETE_TIME_SUCCESS, group.getGroupName()));
return new CommandResult(String.format(MESSAGE_DELETE_TIME + "\n" + commandOutcome, group.getGroupName()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public DeletePersonTimeCommand(Name personName, ArrayList<TimeInterval> timeInte
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
String status;
String commandOutcome;
if (model.hasPerson(personName)) {
status = model.deleteTimeFromPerson(personName, timeIntervalsToDelete);
commandOutcome = model.deleteTimeFromPerson(personName, timeIntervalsToDelete);
} else {
throw new CommandException("Person does not exist \n");
}
return new CommandResult(String.format(MESSAGE_DELETE_TIME_SUCCESS + status, personName.fullName));
return new CommandResult(String.format(MESSAGE_DELETE_TIME + "\n" + commandOutcome, personName.toString()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Deletes time from the individual and group.
*/
public abstract class DeleteTimeCommand extends Command {
public static final String MESSAGE_DELETE_TIME_SUCCESS = "Deleted Time from: %1$s";
public static final String MESSAGE_DELETE_TIME = "Attempted to delete Time from: %1$s";
public static final String COMMAND_WORD = "deletetime";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes free time from an existing person or group. \n"
+ "For person, parameters: "
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public String deleteTimeFromPerson(Name personName,
requireNonNull(personName);
Person person = addressBook.getPerson(personName.fullName);
try {
String status = person.deleteFreeTime(toDeleteTime);
String commandOutcome = person.deleteFreeTime(toDeleteTime);
forceUpdateList();
return status;
return commandOutcome;
} catch (CommandException e) {
throw new CommandException(e.getMessage());
}
Expand Down Expand Up @@ -262,9 +262,9 @@ public String deleteTimeFromGroup(Group group,
requireNonNull(group);
Group groupToDeleteTime = addressBook.getGroup(group.getGroupName());
try {
String status = groupToDeleteTime.deleteTime(toDeleteTime);
String commandOutcome = groupToDeleteTime.deleteTime(toDeleteTime);
forceUpdateList();
return status;
return commandOutcome;
} catch (CommandException e) {
forceUpdateList();
throw new CommandException(e.getMessage());
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/seedu/address/model/TimeIntervalList.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,23 @@ public Stream<TimeInterval> toStream() {
public String addTime(ArrayList<TimeInterval> timeIntervals) throws CommandException{
boolean isPass = false;
boolean isFail = false;
StringBuilder errorCompilation = new StringBuilder();
StringBuilder passMessage = new StringBuilder();
errorCompilation.append("There is a clash in these input timings with your existing timing:\n");
StringBuilder errorMessage = new StringBuilder("There is a clash in these input timings with your existing timings:\n");
StringBuilder passMessage = new StringBuilder("These times have been added:\n");
for (TimeInterval interval : timeIntervals) {
if (isTimeIntervalOverlap(interval)) {
isFail = true;
errorCompilation.append(interval + "\n");
errorMessage.append(interval + "\n");
} else {
if (!isPass) {
passMessage.append("These times have been added:\n");
}
isPass = true;
internalList.add(interval);
passMessage.append(interval.toString() + "\n");
}
}

if (isFail && isPass) {
return errorCompilation.append(passMessage).toString();
return errorMessage.append(passMessage).toString();
} else if (isFail) {
return errorCompilation.toString();
return errorMessage.toString();
} else {
return passMessage.toString();
}
Expand All @@ -66,27 +62,23 @@ public void addAll(TimeIntervalList timeIntervalList) {
public String deleteTime(ArrayList<TimeInterval> timeIntervals) throws CommandException {
boolean isPass = false;
boolean isFail = false;
StringBuilder errorCompilation = new StringBuilder();
StringBuilder passMessage = new StringBuilder();
errorCompilation.append("These times are not in the list:\n");
StringBuilder errorMessage = new StringBuilder("These times were not in the list:\n");
StringBuilder passMessage = new StringBuilder("These times have been deleted:\n");
for (TimeInterval interval : timeIntervals) {
if (!internalList.contains(interval)) {
isFail = true;
errorCompilation.append(interval + "\n");
errorMessage.append(interval + "\n");
} else {
if (!isPass) {
passMessage.append("These times have been added:\n");
}
isPass = true;
internalList.remove(interval);
passMessage.append(interval.toString() + "\n");
}
}

if (isFail && isPass) {
return errorCompilation.append(passMessage).toString();
return errorMessage.append(passMessage).toString();
} else if (isFail) {
return errorCompilation.toString();
return errorMessage.toString();
} else {
return passMessage.toString();
}
Expand Down

0 comments on commit 910d8d3

Please sign in to comment.