Skip to content
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

Create permission for friend commands #189

Merged
merged 17 commits into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ This section explains the implementation of the features associated with the Sch

==== Design considerations

For EditCommand, despite the fact that schedule piggybacks off the original edit command, the original person did not include a schedule object, and so adjustments have to be made.
For EditCommand, despite the fact that schedule piggybacks off the original edit command, the original person did not include a schedule object, and so adjustments have to be made.
Firstly, if the person does not have the schedule object, a new schedule object would be created by the logic layer. This is to ensure backwards compatibility with past test cases without schedule objects. Next, the schedule needs to be stored in the xml file in a concise way so that it would not be bloated. As the persons in the applications are students, we can be certain that their schedules will be likely the same through the week, thus only the weekly schedule is stored.

===== Aspect: Storage of schedule in person
Expand Down
94 changes: 68 additions & 26 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ e.g. typing *`help`* and pressing kbd:[Enter] will open the help window.
. Some example commands you can try:

* *`listUser`* : lists all users in the Event Organiser
* **`addUser`**`n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01` : creates new user named `John Doe` to the Event Organiser.
* **`addUser`**`n/John Doe p/98765432 e/johnd@example.com pass/password a/John street, block 123, #01-01` : creates new user named `John Doe` to the Event Organiser.
* **`addEvent`**`n/CS2103 Project Meeting a/SoC Canteen t/Urgent` : adds an event named CS2103 Project Meeting to be held at SoC Canteen.
* *`exit`* : exits the app

Expand All @@ -47,7 +47,7 @@ e.g. typing *`help`* and pressing kbd:[Enter] will open the help window.

* To use the application, you must first create an account using the `addUser` command, and then `login`.
* If you are not yet logged in, you can still view event details using `selectEvent`, and find events using `findEvent` and `findEventByTime`, and list events using `listEvent`.
* Without logging in, you can also use the `selectUser`, `findUser` and `listUser` commands.
* Without logging in, you can also use the `selectUser`, `findUser`, `listUser`, `listFriends`, `suggestFriendsByInterests` commands.
* When you are done, simply `logout` or `exit` the application.

=== Organise an event
Expand Down Expand Up @@ -141,7 +141,7 @@ Format: `listUser`
==== Find users by name, phone number, email, address, interest, tag : `findUser`

Finds users with any matching name, phone number, email, address, interest, tag. +
Format: `findUser n/[NAME] p/[PHONE_NUMBER] e/[EMAIL] a/[ADDRESS] i/[INTEREST] t/[TAG]...`
Format: `findUser [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [i/INTEREST] [t/TAG]...`

****
* Prefixes (e.g. "n/", "p/", "e/", "a/", "i/", "t/") of the attributes that they want to search for must be included.
Expand Down Expand Up @@ -192,7 +192,7 @@ Selects the 1st user in the results of the `find` command.

==== Edit a user : `editUser`

Edits an existing user in the Event Organiser. +
Edits the currently logged-in user in the Event Organiser. +
Format: `editUser [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [i/INTEREST] [tt/TIMETABLE] [su/SCHEDULE_UPDATE] [t/tags]...`

****
Expand Down Expand Up @@ -226,8 +226,8 @@ Example:
* http://modsn.us/H4v8s

****
* Two possible error messages may be returned by the download, namely A - "Cannot retrieve NUSMODS module information" and B - "Invalid NUSMODS URL".
* Note that the timetable download may take a while regardless if the link is valid or not.
* Two possible error messages may be returned by the download, namely A - "Cannot retrieve NUSMODS module information" and B - "Invalid NUSMODS URL".
* Note that the timetable download may take a while regardless if the link is valid or not.
* Only the current semester timetable will be downloaded. Other semesters timetable will not be downloaded.
* In the case of slow internet speeds, the download will return with A. Please try again with a better internet connection as we are not able to control such factors.
* If the link given is not a http link such as fakelink, hscp:// or any other random string, the download will return A.
Expand All @@ -240,32 +240,41 @@ Example:

==== Add a friend : `addFriend`

For two persons, adds friend with each other. +
Format: `addFriend INDEX,INDEX`
Adds a person to the logged-in user's friend list. +
Format: `addFriend INDEX`

****
* For two users at the 2 specified `INDEX`, adds each other as friend.
* Only two indexes can be stated, seperated by a comma(,) with no spaces in between.
* Each index *must be a positive integer* 1, 2, 3, ..., and must be different from each other.
* The two users cannot be already friends.
* Login is required.
* The index refers to the index number shown in the displayed user list.
* Adds the person at the specified `INDEX` into the logged-in user's friend list.
* The index *must be a positive integer* 1, 2, 3, ...
* The person specified at the `INDEX` cannot be the logged-in user himself/herself.
* The person specified at the `INDEX` cannot be already in the logged-in user's friend list.
****

Examples:

* `addFriend 1,2` +
1st and 2nd user becomes friends with each other and appear on each other's friend list.
* `addFriend 2` +
User specified at `INDEX` 2 is added to the logged-in user's friend list.

==== Delete a friend : `deleteFriend`

For two persons, deletes each other as friend. +
Format: `deleteFriend INDEX,INDEX`
Deletes a person from the logged-in user's friend list. +
Format: `deleteFriend INDEX`

****
* For two users at the 2 specified `INDEX`, deletes each other as friend.
* Only two indexes can be stated, separated by a comma(,) with no spaces in between.
* Each index *must be a positive integer* 1, 2, 3, ..., and must be different from each other.
* The two users must already be friends.
* Login is required.
* The index refers to the index number shown in the displayed user list.
* Deletes the person at the specified `INDEX` from the logged-in user's friend list.
* The index *must be a positive integer* 1, 2, 3, ...
* The person specified at the `INDEX` cannot be the logged-in user himself/herself.
* The person specified at the `INDEX` must be already in the logged-in user's friend list.
****

Examples:

* `deleteFriend 2` +
User specified at `INDEX` 2 is deleted from the logged-in user's friend list.
// end::addDeleteFriend[]

// tag::suggestFriends[]
Expand All @@ -279,16 +288,33 @@ Format: `suggestFriendsByInterests INDEX`
* The index refers to the index number shown in the displayed user list.
* The index *must be a positive integer* 1, 2, 3, ...
* Users who have at least one similar interest with the selected user will be displayed.
* Users who are already friends with the selected user will not be displayed.
* The selected user will also be displayed, so that he/she can activate the `AddFriendCommand` immediately after that with the other displayed users.
* Users who are already in the friend list of the selected user will not be displayed.
****

Examples:

* `suggestFriendsByInterests 1` +
Suggests friends for the 1st user in the Event Organiser that have at least one similar interest with the selected user.
Suggests friends for the 1st user in the Event Organiser that have at least one similar interest with the selected user, and are not yet in the selected user's friend list.
// end::suggestFriends[]

// tag::listFriends[]
==== List all friends of a user : `listFriends`

List all the users that are in the friend list of the selected user. +
Format: `listFriends INDEX`

****
* List all the users that are in the friend list of the selected user at the specified `INDEX`.
* The index refers to the index number shown in the displayed user list.
* The index *must be a positive integer* 1, 2, 3, ...
****

Examples:

* `listFriends 1` +
List all the users who are in the friend list of the 1st user in the Event Organiser.
// end::listFriends[]

// tag::maxschedule[]
==== Get free time between users : `maxSchedule`

Expand Down Expand Up @@ -600,11 +626,25 @@ e.g. `login n/John Doe pass/password`
e.g. `findUser n/James i/basketball`
// end::yaofeng(commandsummary)[]

* *Delete User* : `deleteUser INDEX` +
e.g. `deleteUser 3`
* *Delete User* : `deleteUser` +
e.g. `deleteUser`

// tag::agendazhang(commandsummary)[]
* *Add a friend* `addFriend INDEX`
e.g. `addFriend 2`

* *Delete a friend* `deleteFriend INDEX`
e.g. `addFriend 2`

* *Suggest friends based on similar interests* : `suggestFriendsByInterests INDEX`
e.g. `suggestFriendsByInterests 1`

* *List all friends* : `listFriends INDEX`
e.g. `listFriends 1`
// end::agendazhang(commandsummary)[]

// tag::scheduletimetable[]
* *Edit User* : `editUser INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [i/INTEREST] [tt/TIMETABLE] [s/SCHEDULE] [su/SCHEDULE_UPDATE] ...` +
* *Edit User* : `editUser [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [i/INTEREST] [tt/TIMETABLE] [s/SCHEDULE] [su/SCHEDULE_UPDATE] ...` +
e.g. `editUser n/James Lee e/jameslee@example.com` +
e.g. `editUser tt/ http://modsn.us/H4v8s` +
e.g. `editUser su/ monday 0000`
Expand All @@ -615,6 +655,8 @@ e.g.`selectUser 2`

* *History* : `history`



// tag::maxschedule[]
* *Free time between persons*: `maxSchedule INDEX INDEX ... [sl/ LIMIT]` +
e.g. `maxSchedule 1 2 3`
Expand Down
18 changes: 11 additions & 7 deletions docs/team/agendazhang.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ who prefer to work with a Command Line Interface (CLI) while still having the be
== Summary of

* *Major enhancement*: Added the ability to specify friendships among users
** What it does: Allows the users to add or delete friends with each other and have their friend lists displayed
** Justification: This feature allows users to keep a friendship list which they can refer to it themselves when creating new events. For example, if they would like to organize a friends meetup, they will know who to add to the event. Also, it allows users to search for friends with common interests and expand their friendship lists.
** What it does: Allows the users to add or delete users from their friend lists and have their friend lists displayed
** Justification: This feature allows users to keep a list of friends where they can be updated of their details and the events that they join, similar to following someone on Instagram. For example, a user can look through the displayed profile of the users in their friend list to see what are the current events that they are in. Also, this feature allows users to search for friends with common interests and add them into their friend lists.

* *Minor enhancement*: Added a new attribute Interest for a user
** Justification: This attribute allows users to specify any number of interests, which can be identified for friendships and events.
** Justification: The original tag attribute allows users to specify the groups that they are associated with (eg faculty and tutorial class names). This new Interest attribute allows users to specify the things that they are interested in (eg hobbies). This improves the connectivity among users in the Event Organiser as they can now find friends through common interests.

* *Code contributed*: [https://nus-cs2103-ay1819s1.github.io/cs2103-dashboard/#=undefined&search=agendazhang[Functional code]]

* *Other contributions*:

** Project management
** Enhancements to existing features:
*** Updated the GUI browser display (Pull request https://github.com/CS2103-AY1819S1-W10-3/main/pull/123[#123])
*** Wrote additional tests for existing features to increase coverage from 88% to 92% (Pull request https://github.com/CS2103-AY1819S1-W10-3/main/pull/163[#163])
*** Updated the GUI browser display (Pull request https://github.com/CS2103-AY1819S1-W10-3/main/pull/123 [#123])
*** Wrote additional tests for existing features to increase coverage from 88% to 92% (Pull request https://github.com/CS2103-AY1819S1-W10-3/main/pull/163 [#163], https://github.com/CS2103-AY1819S1-W10-3/main/pull/189 [#189])
** Documentation:
*** Finalise User Stories: https://github.com/CS2103-AY1819S1-W10-3/main/pull/18[#18]
*** Updated the original user commands (from Address Book Level 4) in the developer guide (Pull request https://github.com/CS2103-AY1819S1-W10-3/main/pull/189 [#189])
** Community:
*** PRs reviewed (with non-trivial review comments): https://github.com/CS2103-AY1819S1-W10-3/main/pull/164[#164], https://github.com/CS2103-AY1819S1-W10-3/main/pull/165[#165]
*** PRs reviewed (with non-trivial review comments): https://github.com/CS2103-AY1819S1-W10-3/main/pull/164 [#164], https://github.com/CS2103-AY1819S1-W10-3/main/pull/165 [#165]
*** Reported bugs and suggestions for other teams in the class (No reference as it was done verbally with group W10-2)

== Contributions to the User Guide
Expand All @@ -44,6 +44,10 @@ include::../UserGuide.adoc[tag=addDeleteFriend]

include::../UserGuide.adoc[tag=suggestFriends]

include::../UserGuide.adoc[tag=listFriends]

include::../UserGuide.adoc[tag=agendazhang(commandsummary)]

== Contributions to the Developer Guide

|===
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Messages {
public static final String MESSAGE_NO_EVENT_SELECTED = "There is no event selected.";
public static final String MESSAGE_ALREADY_JOINED = "You have already joined this event.";
public static final String MESSAGE_NO_USER_LOGGED_IN = "There is no user logged-in.";
public static final String MESSAGE_USER_DOES_NOT_HAVE_AUTHORITY = "The current user does not have the authority "
+ "for this command.";
public static final String MESSAGE_NOT_EVENT_ORGANISER = "You are not the organiser of this event.";
public static final String MESSAGE_NO_POLL_AT_INDEX = "No poll exists at this index.";
public static final String MESSAGE_NO_SUCH_OPTION = "No such option exists for this poll.";
Expand Down
37 changes: 1 addition & 36 deletions src/main/java/seedu/address/commons/core/index/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
public class Index {
private int zeroBasedIndex;
private int zeroBasedIndex2;

/**
* Index can only be created by calling {@link Index#fromZeroBased(int)} or
Expand All @@ -24,32 +23,13 @@ private Index(int zeroBasedIndex) {
this.zeroBasedIndex = zeroBasedIndex;
}

/**
* Index can only be created by calling {@link Index#fromZeroBased(int)} or
* {@link Index#fromOneBased(int)}.
*/
private Index(int zeroBasedIndex, int zeroBasedIndex2) {
if (zeroBasedIndex < 0 || zeroBasedIndex2 < 0) {
throw new IndexOutOfBoundsException();
}

this.zeroBasedIndex = zeroBasedIndex;
this.zeroBasedIndex2 = zeroBasedIndex2;
}

public int getZeroBased() {
return zeroBasedIndex;
}
public int getZeroBased2() {
return zeroBasedIndex2;
}

public int getOneBased() {
return zeroBasedIndex + 1;
}
public int getOneBased2() {
return zeroBasedIndex2 + 1;
}

/**
* Creates a new {@code Index} using a zero-based index.
Expand All @@ -58,32 +38,17 @@ public static Index fromZeroBased(int zeroBasedIndex) {
return new Index(zeroBasedIndex);
}

/**
* Creates a new {@code Index} using a zero-based index.
*/
public static Index fromZeroBased(int zeroBasedIndex, int zeroBasedIndex2) {
return new Index(zeroBasedIndex, zeroBasedIndex2);
}

/**
* Creates a new {@code Index} using a one-based index.
*/
public static Index fromOneBased(int oneBasedIndex) {
return new Index(oneBasedIndex - 1);
}

/**
* Creates a new {@code Index} using a one-based index.
*/
public static Index fromOneBased(int oneBasedIndex, int oneBasedIndex2) {
return new Index(oneBasedIndex - 1, oneBasedIndex2 - 1);
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Index // instanceof handles nulls
&& zeroBasedIndex == ((Index) other).zeroBasedIndex
&& zeroBasedIndex2 == ((Index) other).zeroBasedIndex2); // state check
&& zeroBasedIndex == ((Index) other).zeroBasedIndex); // state check
}
}
43 changes: 2 additions & 41 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
* Helper functions for handling strings.
Expand Down Expand Up @@ -63,47 +61,10 @@ public static String getDetails(Throwable t) {
public static boolean isNonZeroUnsignedInteger(String s) {
requireNonNull(s);
try {
ArrayList<Integer> values = new ArrayList<>();
if (s.contains(COMMA) && countCommas(s) <= 1) { // check if more than two indexes are passed
values = splitIntegersWithComma(s);
} else {
values.add(Integer.parseInt(s));
}
for (int value : values) {
if (!(value > 0 && !s.startsWith("+"))) { // "+1" successfully parsed by Integer#parseInt(String)
return false;
}
}
return true;
int value = Integer.parseInt(s);
return value > 0 && !s.startsWith("+"); // "+1" is successfully parsed by Integer#parseInt(String)
} catch (NumberFormatException nfe) {
return false;
}
}

/**
* Given a string that separates two integers with a comma (eg "1,2"), this function returns
* an ArrayList that contains the two integers
*/
public static ArrayList<Integer> splitIntegersWithComma(String s) throws NumberFormatException {
ArrayList<Integer> values = new ArrayList<>();
StringTokenizer st = new StringTokenizer(s, COMMA);
while (st.hasMoreTokens()) {
values.add(Integer.parseInt(st.nextToken()));
}
return values;
}

/**
* Given a string that separates two integers with a comma (eg "1,2,3"), this function returns
* the number of commas in the string.
*/
public static int countCommas(String s) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ',') {
count++;
}
}
return count;
}
}
Loading