Skip to content

Commit 35447d7

Browse files
committed
Update DG for update-title
1 parent 13334cb commit 35447d7

File tree

3 files changed

+128
-26
lines changed

3 files changed

+128
-26
lines changed

docs/DeveloperGuide.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -455,51 +455,50 @@ The following UML sequence diagram shows how the `edit-loan BOOK_TITLE [n/BORROW
455455

456456
The `update-title` feature allows the user to update existing book titles. The system ensures that a book of the current title exists in the inventory and before performing the update.
457457

458-
`InputHandler` coordinates with `InputParser`, `BookList`, `Formatter`, and `Storage` classes to implement the feature.
458+
`InputHandler` coordinates with `InputParser`, `BookList`, `Book`, `Formatter`, and `Storage` classes to implement the feature.
459459

460-
The following UML sequence diagram shows how the `update-book BOOK_TITLE [a/AUTHOR] [cat/CATEGORY] [cond/CONDITION] [loc/LOCATION] [note/NOTE]` command is handled.
460+
The following UML sequence diagram shows how the `update-book BOOK_TITLE new/NEW_TITLE` command is handled.
461461

462-
![updateBook.png](images/updateBook.png)
462+
![updateTitle.png](images/updateTitle.png)
463463

464464
1. User issues command:
465-
The user inputs the command in the CLI with the required arguments, e.g., `update-book The Great Gatsby a/F. Scott Fitzgerald cat/Fiction cond/POOR loc/Shelf B3 note/Replace ASAP`.
465+
The user inputs the command in the CLI with the required arguments, e.g., `update-title BOOK_TITLE new/NEW_TITLE`.
466466

467467
2. Command arguments are extracted:
468468
`InputHandler` first calls `InputParser.extractCommandArgs(...)` to split the user input into command arguments.
469469

470-
- For example, the input `update-book The Great Gatsby a/F. Scott Fitzgerald cat/Fiction cond/POOR loc/Shelf B3 note/Replace ASAP` is split into:
471-
- `commandArgs[0]`: `"update-book"`
472-
- `commandArgs[1]`: `"The Great Gatsby a/F. Scott Fitzgerald cat/Fiction cond/POOR loc/Shelf B3 note/Replace ASAP"`
470+
- For example, the input `update-title Great Gatsby new/The Great Gatsby` is split into:
471+
- `commandArgs[0]`: `"update-title"`
472+
- `commandArgs[1]`: `"Great Gatsby new/The Great Gatsby"`
473473

474-
3. Book arguments are parsed:
475-
`InputHandler` invokes `InputParser.extractUpdateBookArgs(...)` to parse the second part of the command (`commandArgs[1]`) into the following components:
474+
3. Title arguments are parsed:
475+
`InputHandler` invokes `InputParser.extractUpdateTitleArgs(...)` to parse the second part of the command (`commandArgs[1]`) into the following components:
476476

477-
- Book title
478-
- Author
479-
- Category
480-
- Condition
481-
- Location
482-
- Note (Optional)
477+
- old Title
478+
- new Title
483479

484-
4. Book is validated:
485-
`InputHandler` calls `BookList.findBookByTitle(bookTitle)` to check if the book exists in the inventory.
480+
4. Title is validated:
481+
`InputHandler` checks if `oldTitle` is the same as `newTitle`. `InputHandler` also calls `BookList.findBookByTitle(newTitle)` to check if there is an existing book with the same title as `newTitle`.
482+
483+
- If the a `oldTitle` and `newTitle` are the same, `InputHandler` uses `Formatter` to print a exception message and exits early.
484+
- If the a book with the same title as `newTitle` is found, `InputHandler` uses `Formatter` to print a exception message and exits early.
485+
- If no book is found, the flow continues.
486+
487+
5. Book is validated:
488+
`InputHandler` calls `BookList.findBookByTitle(oldTitle)` to check if the book exists in the inventory.
486489

487490
- If the book is not found, `InputHandler` uses `Formatter` to print a exception message and exits early.
488491
- If the book is found, the flow continues.
489492

490-
5. Book is updated:
493+
6. Title is updated:
491494
`InputHandler` updates the book details by invoking the following methods from `Book` class:
492495

493-
- `Book.setAuthor(newAuthor)`
494-
- `Book.setCategory(newCategory)`
495-
- `Book.setCondition(newCondition)`
496-
- `Book.setLocation(newLocation)`
497-
- `Book.setNote(newNote)` (only if note is provided)
496+
- `Book.setTitle(newTitle)`
498497

499-
6. Changes are saved to persistent storage:
500-
`InputHandler` calls `Storage.saveLoans(...)` and `Storage.saveInventory(...)` to save the updated book details.
498+
7. Changes are saved to persistent storage:
499+
`InputHandler` calls `Storage.saveLoans(...)` and `Storage.saveInventory(...)` to save the updated book title.
501500

502-
7. Success message is displayed:
501+
8. Success message is displayed:
503502
`InputHandler` uses `Formatter` to print a message indicating that the book was successfully updated.
504503

505504
### Save Inventory

docs/diagrams/updateTitle.puml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
@startuml
2+
actor User
3+
participant InputHandler as ":InputHandler"
4+
participant InputParser as ":InputParser"
5+
participant BookList as ":BookList"
6+
participant Book as ":Book"
7+
participant Formatter as ":Formatter"
8+
participant Storage as ":Storage"
9+
10+
User -> InputHandler: userInputLine
11+
activate InputHandler
12+
13+
InputHandler -> InputParser: extractCommandArgs(userInputLine)
14+
activate InputParser
15+
16+
InputParser --> InputHandler: commandArgs[]
17+
deactivate InputParser
18+
19+
alt commandArgs[0] == update-title
20+
InputHandler -> InputHandler : updateTitle()
21+
activate InputHandler
22+
23+
opt commandArgs.length < 2
24+
note right
25+
rest of sequence is cancelled in error cases denoted in opt frames
26+
end note
27+
InputHandler -> Formatter: Print exception message
28+
activate Formatter
29+
Formatter --> InputHandler
30+
deactivate Formatter
31+
end
32+
33+
InputHandler -> InputParser: extractUpdateTitleArgs(commandArgs[1])
34+
activate InputParser
35+
36+
InputParser --> InputHandler: parsedArgs
37+
deactivate InputParser
38+
39+
opt oldTitle.equals(newTitle)
40+
InputHandler -> Formatter: Print exception message
41+
activate Formatter
42+
Formatter --> InputHandler
43+
deactivate Formatter
44+
end
45+
46+
InputHandler -> BookList: findBookByTitle(newTitle)
47+
activate BookList
48+
49+
BookList --> InputHandler: Book
50+
deactivate BookList
51+
52+
opt Book != null
53+
InputHandler -> Formatter: Print exception message
54+
activate Formatter
55+
Formatter --> InputHandler
56+
deactivate Formatter
57+
end
58+
59+
InputHandler -> BookList: findBookByTitle(oldTitle)
60+
activate BookList
61+
62+
BookList --> InputHandler: Book
63+
deactivate BookList
64+
65+
opt Book == null
66+
InputHandler -> Formatter: Print exception message
67+
activate Formatter
68+
Formatter --> InputHandler
69+
deactivate Formatter
70+
end
71+
InputHandler -> Book : setTitle(newTitle)
72+
activate Book
73+
Book --> InputHandler
74+
deactivate Book
75+
76+
InputHandler -> Formatter: printBorderedMessage("Book Updated: {BOOK}")
77+
activate Formatter
78+
79+
Formatter --> InputHandler
80+
deactivate Formatter
81+
82+
InputHandler -> Storage: saveInventory(bookList)
83+
activate Storage
84+
85+
Storage --> InputHandler
86+
deactivate Storage
87+
88+
InputHandler -> Storage: saveInventory(loanList)
89+
activate Storage
90+
91+
Storage --> InputHandler
92+
deactivate Storage
93+
94+
InputHandler --> InputHandler
95+
deactivate InputHandler
96+
97+
else else
98+
note over InputHandler : other commands
99+
end
100+
101+
InputHandler --> User
102+
deactivate InputHandler
103+
@enduml

docs/images/updateTitle.png

68.6 KB
Loading

0 commit comments

Comments
 (0)