Skip to content

Commit

Permalink
Merge branch 'master' into branch-add-diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
Incogdino authored Nov 12, 2024
2 parents 77eaa80 + 0f179cc commit 48827f2
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 2 deletions.
81 changes: 79 additions & 2 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* This project is based on the AddressBook-Level3 project created by the [SE-EDU initiative](https://se-education.org/).
* We took references from [OpenCSV](https://opencsv.sourceforge.net/) for import and export commands.
* ChatGPT was used to check for errors and generate some test cases.
* It was used to generate the first two test cases in RemoveGradeCommandParserTest.java
* It was used to generate the first two test cases in RemoveGradeCommandParserTest.java, MarkCommandParserTest.java & MarkCommandTest.java.
* It was also used for the usage of `.getStyleClass()` & `.add()` methods in PersonCard.java to display the information clearly.
* It was consulted to get a plan of how `PersonComparator` can be implemented.
* It was consulted to fix and improve the UI.
Expand Down Expand Up @@ -74,7 +74,6 @@ Each of the four main components (also shown in the diagram above),
- defines its _API_ in an `interface` with the same name as the Component.
- implements its functionality using a concrete `{Component Name}Manager` class (which follows the corresponding API `interface` mentioned in the previous point.

{{ newPage }}

For example, the `Logic` component defines its API in the `Logic.java` interface and implements its functionality using the `LogicManager.java` class which follows the `Logic` interface. Other components interact with a given component through its interface rather than the concrete class (reason: to prevent outside component's being coupled to the implementation of a component), as illustrated in the (partial) class diagram below.

Expand Down Expand Up @@ -195,6 +194,53 @@ This section describes some noteworthy details on how certain features are imple

---

### Add contacts

**Overview**

The `add` command allows user to add students' contact into KonTActs.

The Sequence Diagram below shows how the logic component handles the user input.

<puml src="diagrams/AddSequenceDiagram.puml" width="550"/>

Note: While the diagram shows the lifeline of objects even after their deletion, this is a limitattion of plantUML.

**Details**

1. The user inputs "add n/John tele/@John g/Johnny e/[email protected]". (Not shown in diagram)
2. The `LogicManager` object will be called to `execute` the input.
3. The `AddressBookParser` will identify the type of command is `AddCommand`, before creating a `AddCommandParser` to parse the details.
4. The `AddCommandParser` will `parse` the `USER_DETAILS` before creating a `AddCommand`.
5. The new `AddCommand` will be returned to `LogicManager`.
6. The `LogicManager` will then calls `exectute` on `AddCommand` while providing the model.
7. This causes the `AddCommand` to call the `addPerson` method of model, adding the person to the model.
8. A `CommandResult` object is subsequently created which indicates the success of `AddCommand`.

**Example Usage**
1. User inputs the command "add n/Tom tele/@Tom g/Tommy e/[email protected]".
2. KonTActs will create a contact of Tom with the given details before adding it to the contact list.
3. The contact is then displayed in the UI, along with a success message.

---

### MarkCommand

<puml src="diagrams/MarkCommandActivityDiagram.puml" width="750" />


* The `MarkCommand` is used by KonTActs to allow TAs to mark the attendance for a student.
* It follows the activity diagram as shown above where it first checks if the person exists.
* If the person exists, it will check if the weeksPresent contains the week to be marked.
* If the weeksPresent does not contain the week to be marked yet, it will add it in and return a success message. Else it will throw a mark already success message to tell the TA that the attendance for the TA for that week has been marked.

**Example Usage**
1. User inputs the command "mark n/John Doe w/1".
2. KonTActs will set the week 1 attendance for John Doe to be true.
3. The update is then displayed in the UI, along with a success message.

---

### Export Command implementation
**API** [`Export.java`](https://github.com/AY2425S1-CS2103T-T11-2/tp/blob/master/src/main/java/seedu/address/storage/Export.java)

Expand All @@ -212,6 +258,37 @@ A visual representation is shown below of how a typical user might use the `Expo

<puml src="diagrams/Export.puml" width="550"></puml>

---

### Command History implementation
**API** : [`CommandHistory.java`](https://github.com/AY2425S1-CS2103T-T11-2/tp/blob/master/src/main/java/seedu/address/storage/CommandHistory.java)

The `CommandHistory` is used by KonTActs to allow users to navigate and retrieve previous inputted commands. It follows a singleton pattern where only a single instance can be created.

- `CommandHistory` makes use of an `ArrayList` to store the commands of the current user session.
- The `ArrayList` is destroyed at the end of the program and a new one will be created at the start of every session of KonTActs.
- An `index` points to the current command displayed in the command box of the Graphical user interface (GUI).

When a user enters a command,
1. If an existing `CommandHistory` instance already exists, then the command will be added to it
2. Else, a new `CommandHistory` instance will be instantiated and the command will be added to it

This is illustrated in the activity diagram below:
<center>
<puml src="diagrams/commandHistoryActivityDiagram.puml" width="450" />
</center>

When a user retrieves a command that was previously executed using <kbd>↑</kbd> or <kbd>↓</kbd>,
- `CommandHistory` instance first checks if there are fields in the `ArrayList` of the `CommandHistory` instance.
- `CommandHistory` instance then checks for the correct `index`. (i.e. The `index` is valid when it is between 0 and the size of the `ArrayList`).

If both conditions are satisfied, the `ArrayList` is accessed with the `index` and the command string (that was previously entered) will be returned and displayed on the command box of the GUI.

A visual representation is shown below of how a typical user might use the `CommandHistory`,

<center>
<puml src="diagrams/commandHistoryUserInteractionActivityDiagram.puml" width="700" />
</center>

{{ newPage }}

Expand Down
23 changes: 23 additions & 0 deletions docs/diagrams/MarkCommandActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@startuml
start
:User keys in MarkCommand with name and week;

:Retrieve person from Model using name;

if () then ([Person not found])
:Throw MESSAGE_INVALID_PERSON_DISPLAYED_NAME;
stop
else ([Else])
:Retrieve weeksPresent for the person;
if () then ([Week already marked])
:Return MESSAGE_MARK_ALREADY_SUCCESS;
stop
else ([Else])
:Add week to weeksPresent;
:Update person with new weeksPresent;
:Save updated person back to Model;
:Return MESSAGE_MARK_SUCCESS;
stop
endif
endif
@enduml
77 changes: 77 additions & 0 deletions docs/diagrams/addSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":AddCommandParser" as AddCommandParser LOGIC_COLOR
participant "a:AddCommand" as AddCommand LOGIC_COLOR
participant "r:CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant "m:Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("add n/John tele/@John \n g/Johnny e/[email protected]")
note left of LogicManager: From this point on we will refer\n "add n/John tele/@John g/Johnny e/[email protected]" \n as USER_DETAILS
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("add USER_DETAILS")
activate AddressBookParser

create AddCommandParser
AddressBookParser -> AddCommandParser
activate AddCommandParser

AddCommandParser --> AddressBookParser
deactivate AddCommandParser

AddressBookParser -> AddCommandParser : parse(USER_DETAILS)
activate AddCommandParser

create AddCommand
AddCommandParser -> AddCommand
activate AddCommand

AddCommand --> AddCommandParser :
deactivate AddCommand

AddCommandParser --> AddressBookParser : a
deactivate AddCommandParser
'Hidden arrow to position the destroy marker below the end of the activation bar.
AddCommandParser -[hidden]-> AddressBookParser
destroy AddCommandParser

AddressBookParser --> LogicManager : a
deactivate AddressBookParser

LogicManager -> AddCommand : execute(m)
activate AddCommand

AddCommand -> Model : addPerson(person)
activate Model

Model --> AddCommand
deactivate Model

create CommandResult
AddCommand -> CommandResult
activate CommandResult

CommandResult --> AddCommand
deactivate CommandResult
'Hidden arrow to position the destroy marker below the end of the activation bar.
CommandResult -[hidden]-> AddCommand
destroy CommandResult

AddCommand --> LogicManager : r
deactivate AddCommand
'Hidden arrow to position the destroy marker below the end of the activation bar.
AddCommand -[hidden]-> LogicManager
destroy AddCommand

[<--LogicManager
deactivate LogicManager
@enduml
17 changes: 17 additions & 0 deletions docs/diagrams/commandHistoryActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@startuml
'https://plantuml.com/activity-diagram-beta

start
:User types a command input;
if () then ([CommandHistory exists])

else ([else])
:KonTActs creates a new CommandHistory;
endif

:User input command is added to CommandHistory;


stop

@enduml
23 changes: 23 additions & 0 deletions docs/diagrams/commandHistoryUserInteractionActivityDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@startuml
'https://plantuml.com/activity-diagram-beta

start
:User access previous command
using the keyboard up key;
if () then ([CommandHistory exists])
if () then ([CommandHistory is empty])
: KonTActs informs users that
there is no previous commands;
else ([CommandHistory is not empty])])
:KonTActs gets previous command
from the CommandHistory's ArrayList;
:Previous command is displayed to the user;
endif
else ([CommandHistory does not exist])
:KonTActs creates a new CommandHistory;
:KonTActs informs users
that there is no previous commands;
endif
stop

@enduml
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public PersonCard(Person person, int displayedIndex) {
github.setText("GitHub username unspecified");
}

//@@author swaminathanViswa
// Inspiration from GPT on the usage of .add() and .getStyleClass() methods.
Label labelOfWeek = new Label("Weeks attended: ");
if (!person.getWeeksPresent().isEmpty()) {
labelOfWeek.getStyleClass().add("information-label");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class MarkCommandTest {

private Model model;

//@@author swaminathanViswa
//took inspiration from GPT regarding the use of BeforeEach and the writing of the first test case.
@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), new PredefinedAssignmentsData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MarkCommandParserTest {

private final MarkCommandParser parser = new MarkCommandParser();

// This test case was generated by GPT.
@Test
public void parse_validArgs_returnsMarkCommand() throws ParseException {
String userInput = " n/Benson Meier w/4";
Expand All @@ -23,6 +24,7 @@ public void parse_validArgs_returnsMarkCommand() throws ParseException {
assertEquals(expectedCommand, actualCommand);
}

// This test case was generated by GPT.
@Test
public void parse_missingName_throwsParseException() {
String userInput = " w/1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
public class RemoveGradeCommandParserTest {
private final RemoveGradeCommandParser parser = new RemoveGradeCommandParser();

// GPT was used to generate this test case.
@Test
public void parse_allFieldsSpecified_success() throws ParseException {
String userInput = NAME_DESC_AMY + ASSIGNMENT_DESC_ONE;
Expand All @@ -30,6 +31,7 @@ public void parse_allFieldsSpecified_success() throws ParseException {
assertParseSuccess(parser, userInput, expectedCommand);
}

// GPT was used to generate this test case.
@Test
public void parse_notAllFieldSpecified_error() {
String userInput = NAME_DESC_AMY;
Expand Down

0 comments on commit 48827f2

Please sign in to comment.