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

Add view all loans command #81

Merged

Conversation

narwhalsilent
Copy link

@narwhalsilent narwhalsilent commented Mar 28, 2024

Fixes #55 and #32.

Refactor LoanRecords as UniqueLoanList

  • The new class use UniquePersonList as a model in implementing methods.

Extract individual loan lists to global loan lists

  • The UniqueLoanList is now a field of AddressBook as opposed individual persons.
  • The class Loan now holds the assignee Person as a field.

Refactor the display of loans

Class changes:

  • ModelManager now holds a sortedLoanList of loans wrapped around a filteredLoanList.
  • This filteredLoanList, in turn, wraps around the uniqueLoanList of the AddressBook, analogous to filteredPersonList.

Implementation changes:

  • The filteredLoanList controls which loans are shown. Currently there are two options: show all active loans or show active loans attached to a person.
  • The sortedLoanList controls the order of loans. Currently it is hardcoded that loans due earlier are placed higher.

Add new command viewloans

  • With above changes, this command is implemented similarly to list. It displays all active loans

Refactor viewloan command

  • Instead of getting a personal LoanRecords, this command now simply updates the predicate on filteredLoanList, similar to filter command.

Refactor deleteloan and markloan command

  • Referring to the index of person is no longer required due to previous change.
  • New syntax is deleteloan/markloan INDEX where INDEX is the index of the loan in the last shown loan list.

Refactor storage

  • The storage system is comprehensively revised to accomodate all changes above.

Change generic data

  • The generic data for when addressbook.json does not exist is changed to reflect the above changes.

Bugs and issues

The following are essential changes that are not covered in this PR:

  • Change the command messages of deleteloan and markloan to reflect the change of parameters.
  • Change the DG to reflect the change of implementation of deleteloan and markloan methods.
  • Change the automated tests to reflect the refactoring of Person, Loan and LoanRecords.
  • Refactor the generation of Analytics in this new implementation.
  • Refactor EditCommand related objects to reflect the deletion of LoanRecords from Person.

@narwhalsilent narwhalsilent added help wanted Extra attention is needed priority.High Must do labels Mar 28, 2024
@narwhalsilent narwhalsilent added this to the v1.3 milestone Mar 28, 2024
@narwhalsilent narwhalsilent self-assigned this Mar 28, 2024
Copy link

codecov bot commented Mar 28, 2024

Codecov Report

Attention: Patch coverage is 18.57923% with 149 lines in your changes are missing coverage. Please review.

Project coverage is 54.63%. Comparing base (a84d7c7) to head (6e17a24).
Report is 4 commits behind head on master.

Files Patch % Lines
...ava/seedu/address/model/person/UniqueLoanList.java 18.51% 38 Missing and 6 partials ⚠️
...rc/main/java/seedu/address/model/ModelManager.java 15.00% 16 Missing and 1 partial ⚠️
.../java/seedu/address/model/util/SampleDataUtil.java 12.50% 14 Missing ⚠️
src/main/java/seedu/address/model/AddressBook.java 29.41% 11 Missing and 1 partial ⚠️
...eedu/address/logic/commands/DeleteLoanCommand.java 0.00% 10 Missing ⚠️
.../seedu/address/logic/commands/MarkLoanCommand.java 0.00% 10 Missing ⚠️
src/main/java/seedu/address/model/person/Loan.java 0.00% 9 Missing ⚠️
...seedu/address/logic/commands/ViewLoansCommand.java 0.00% 5 Missing ⚠️
...in/java/seedu/address/storage/JsonAdaptedLoan.java 0.00% 5 Missing ⚠️
.../seedu/address/storage/JsonAdaptedLoanRecords.java 0.00% 4 Missing ⚠️
... and 12 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #81      +/-   ##
============================================
- Coverage     60.69%   54.63%   -6.07%     
+ Complexity      462      429      -33     
============================================
  Files            87       90       +3     
  Lines          1865     1898      +33     
  Branches        183      181       -2     
============================================
- Hits           1132     1037      -95     
- Misses          681      819     +138     
+ Partials         52       42      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@marcus-ny marcus-ny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me. The app seems to behave as expected.

Just one or two minor nits to fix and should be gtg!

public Loan(int id, float value, Date startDate, Date returnDate) {
requireAllNonNull(id, value, startDate, returnDate);
public Loan(int id, float value, Date startDate, Date returnDate, Person assignee) {
requireAllNonNull(id, value, startDate, returnDate, assignee);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good defensive coding

@@ -44,7 +43,8 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs
this.addressBook = new AddressBook(addressBook);
this.userPrefs = new UserPrefs(userPrefs);
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
currLoanList = FXCollections.observableList(new ArrayList<>());
filteredLoans = new FilteredList<>(this.addressBook.getLoanList());
sortedLoans = new SortedList<>(filteredLoans, Loan::compareTo);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making use of the behaviour of SortedList is really nice here. Removes the need for implicit sorting through functions at every change. 👍

public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredLoanList(PREDICATE_SHOW_ALL_ACTIVE_LOANS);
return new CommandResult(MESSAGE_SUCCESS, false, false, true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new CommandResult(MESSAGE_SUCCESS, false, false, true);
model.updateFilteredPersonList(unused -> false);
return new CommandResult(MESSAGE_SUCCESS, false, false, true);

Copy link

@marcus-ny marcus-ny Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for cosmetic purposes and not really important. But when we call viewloans targeting all active loans, we should not show any particular contact's name at the top.

The UI will show a blank space at the top after this change. We will leave it to be fixed as an issue later on as this task is more suitable for another issue and PR on its own.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. In the "view all loans" GUI, the name of the loanee should also be shown for each loan,

@marcus-ny marcus-ny merged commit 5c1b43b into AY2324S2-CS2103T-W13-1:master Mar 30, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed priority.High Must do
Projects
None yet
2 participants