forked from se-edu/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 54
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 #34 from daviddl9/create_JsonAdaptedRequest_and_Js…
…onAdaptedHealthWorker Create json adapted request and json adapted health worker
- Loading branch information
Showing
21 changed files
with
1,137 additions
and
10 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/main/java/seedu/address/logic/commands/request/CreateCommand.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,66 @@ | ||
package seedu.address.logic.commands.request; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_CONDITION; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
|
||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.request.Request; | ||
|
||
/** | ||
* Creates a new request to the request book. | ||
*/ | ||
public class CreateCommand extends RequestCommand { | ||
|
||
public static final String COMMAND_WORD = "create"; | ||
|
||
public static final String MESSAGE_USAGE = RequestCommand.COMMAND_WORD + " " + COMMAND_WORD | ||
+ ": Creates a new request in the request book. " + "Parameters: " | ||
+ PREFIX_NAME + "NAME " | ||
+ PREFIX_PHONE + "PHONE " | ||
+ PREFIX_ADDRESS + "ADDRESS " | ||
+ PREFIX_DATE + "DATETIME" | ||
+ PREFIX_CONDITION + "CONDITION...\n" | ||
+ "Example: " + RequestCommand.COMMAND_WORD + " " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_PHONE + "81234567 " | ||
+ PREFIX_ADDRESS + "123, Sengkang Ave 3, #04-12, 214632 " | ||
+ PREFIX_DATE + "01-01-2019 08:00:00 " | ||
+ PREFIX_CONDITION + "Physiotherapy"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Created new request successfully: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_REQUEST = "This request already exists."; | ||
|
||
private final Request newRequest; | ||
|
||
public CreateCommand(Request newRequest) { | ||
requireNonNull(newRequest); | ||
this.newRequest = newRequest; | ||
} | ||
|
||
/** | ||
* Executes the command and returns the result message. | ||
* | ||
* @param model {@code Model} which the command should operate on. | ||
* @param history {@code CommandHistory} which the command should operate on. | ||
* @return feedback message of the operation result for display | ||
* @throws CommandException If an error occurs during command execution. | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
requireNonNull(model); | ||
// TODO write created request into the JSON file | ||
// if (model.hasRequest(this.newRequest)) { | ||
// throw new CommandException(MESSAGE_DUPLICATE_REQUEST); | ||
// } | ||
// model.addRequest(newRequest); | ||
// model.commitRequestBook(); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, newRequest)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/seedu/address/logic/commands/request/RequestCommand.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,10 @@ | ||
package seedu.address.logic.commands.request; | ||
|
||
import seedu.address.logic.commands.Command; | ||
|
||
/** | ||
* Base command for all request commands | ||
*/ | ||
public abstract class RequestCommand extends Command { | ||
public static final String COMMAND_WORD = "/request"; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/seedu/address/model/ReadOnlyRequestBook.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,15 @@ | ||
package seedu.address.model; | ||
|
||
import javafx.beans.Observable; | ||
import javafx.collections.ObservableList; | ||
import seedu.address.model.request.Request; | ||
|
||
/** | ||
* Unmodifiable view of a request book. | ||
*/ | ||
public interface ReadOnlyRequestBook extends Observable { | ||
/** | ||
* @return an unmodifiable view of the request list. This list will not contain any duplicate requests. | ||
*/ | ||
ObservableList<Request> getRequestList(); | ||
} |
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,136 @@ | ||
package seedu.address.model; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import javafx.beans.InvalidationListener; | ||
import javafx.collections.ObservableList; | ||
import seedu.address.commons.util.InvalidationListenerManager; | ||
import seedu.address.model.request.Request; | ||
import seedu.address.model.request.UniqueRequestList; | ||
|
||
/** | ||
* Wraps all data at the request-book level | ||
* Duplicates are not allowed (by .isSameRequest comparison) | ||
*/ | ||
public class RequestBook implements ReadOnlyRequestBook { | ||
|
||
private final UniqueRequestList requests = new UniqueRequestList(); | ||
private final InvalidationListenerManager invalidationListenerManager = new InvalidationListenerManager(); | ||
|
||
public RequestBook() {} | ||
|
||
/** | ||
* Creates a RequestBook using the Requests in the {@code toBeCopied} | ||
*/ | ||
public RequestBook(ReadOnlyRequestBook toBeCopied) { | ||
this(); | ||
resetData(toBeCopied); | ||
} | ||
|
||
//// list overwrite operations | ||
|
||
/** | ||
* Replaces the contents of the request list with {@code requests}. | ||
* {@code requests} must not contain duplicate requests. | ||
*/ | ||
public void setRequests(List<Request> requests) { | ||
this.requests.setRequests(requests); | ||
indicateModified(); | ||
} | ||
|
||
/** | ||
* Resets the existing data of this {@code RequestBook} with {@code newData}. | ||
*/ | ||
public void resetData(ReadOnlyRequestBook newData) { | ||
requireNonNull(newData); | ||
setRequests(newData.getRequestList()); | ||
} | ||
|
||
//// request-level operations | ||
|
||
/** | ||
* Returns true if a request with the same identity as {@code req} exists in the request book. | ||
*/ | ||
public boolean hasRequest(Request req) { | ||
requireNonNull(req); | ||
return requests.contains(req); | ||
} | ||
|
||
/** | ||
* Adds a request to the request book. | ||
* The request must not already exist in the request book. | ||
*/ | ||
public void addRequest(Request r) { | ||
requests.add(r); | ||
indicateModified(); | ||
} | ||
|
||
/** | ||
* Replaces the given person {@code target} in the list with {@code editedPerson}. | ||
* {@code target} must exist in the request book. | ||
* The request identity of {@code editedPerson} must not be the same as another existing request in the request | ||
* book. | ||
*/ | ||
public void setRequest(Request target, Request editedRequest) { | ||
requireNonNull(editedRequest); | ||
|
||
requests.setRequest(target, editedRequest); | ||
indicateModified(); | ||
} | ||
|
||
/** | ||
* Removes {@code key} from this {@code RequestBook}. | ||
* {@code key} must exist in the request book. | ||
*/ | ||
public void removeRequest(Request key) { | ||
requests.remove(key); | ||
indicateModified(); | ||
} | ||
|
||
/** | ||
* @return an unmodifiable view of the request list. This list will not contain any duplicate requests. | ||
*/ | ||
@Override | ||
public ObservableList<Request> getRequestList() { | ||
return requests.asUnmodifiableObservableList(); | ||
} | ||
|
||
@Override | ||
public void addListener(InvalidationListener listener) { | ||
invalidationListenerManager.addListener(listener); | ||
} | ||
|
||
@Override | ||
public void removeListener(InvalidationListener listener) { | ||
invalidationListenerManager.removeListener(listener); | ||
} | ||
|
||
/** | ||
* Notifies listeners that the request book has been modified. | ||
*/ | ||
protected void indicateModified() { | ||
invalidationListenerManager.callListeners(this); | ||
} | ||
|
||
//// util methods | ||
|
||
@Override | ||
public String toString() { | ||
return requests.asUnmodifiableObservableList().size() + " persons"; | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof RequestBook // instanceof handles nulls | ||
&& requests.equals(((RequestBook) other).requests)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return requests.hashCode(); | ||
} | ||
} |
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.