AY2425S1-CS2103T-T15-1 / tp

Other
0 stars 5 forks source link

Customer List of Rental Information is Being Saved Incorrectly on Exit #197

Open RobotWizzard opened 4 hours ago

RobotWizzard commented 4 hours ago

The customerList field of rental information is saved with extra enclosing square brackets on app exit is the rview command is run on the client. This causes the UI to incorrectly display the customer list.


image


State of data/addressbook.json

Before exiting:

{
  "clients" : [ {
    "name" : "John Doe",
    "phone" : "98765432",
    "email" : "johnd@example.com",
    "tags" : [ "owesMoney", "friends" ],
    "rentalInformationList" : [ {
      "address" : "BLK 1 Bishan",
      "rentalStartDate" : "01/01/2024",
      "rentalEndDate" : "31/12/2024",
      "rentDueDate" : "15",
      "monthlyRent" : "2700.00",
      "deposit" : "8100.00",
      "customerList" : "[Steven, David]"
    } ]
  }, {
    "name" : "Bernice Yu",
    "phone" : "12345789",
    "email" : "berniceyu@example.com",
    "tags" : [ "colleagues", "friends" ],
    "rentalInformationList" : [ ]
  } ]
}

After running rview 1 then exiting:

{
  "clients" : [ {
    "name" : "John Doe",
    "phone" : "98765432",
    "email" : "johnd@example.com",
    "tags" : [ "owesMoney", "friends" ],
    "rentalInformationList" : [ {
      "address" : "BLK 1 Bishan",
      "rentalStartDate" : "01/01/2024",
      "rentalEndDate" : "31/12/2024",
      "rentDueDate" : "15",
      "monthlyRent" : "2700.00",
      "deposit" : "8100.00",
      "customerList" : "[[Steven, David]]"
    } ]
  }, {
    "name" : "Bernice Yu",
    "phone" : "12345789",
    "email" : "berniceyu@example.com",
    "tags" : [ "colleagues", "friends" ],
    "rentalInformationList" : [ ]
  } ]
}
RobotWizzard commented 4 hours ago

This bug is caused by customerList being stored as a String, and not being extracted correctly on app launch.

The main issue is in the convertStringToCustomerArrayList(String) method in RentalUtil. The "[" and "]" is being interpreted as part of the first and last customers' names, so if any operations involving that client's list of rental information is executed, the app will save the new names, which are "[Steven" and "David]" for example.