Skip to content

Commit

Permalink
Merge pull request #204 from dillontkh/Fix-LongNameQRCodeGeneration
Browse files Browse the repository at this point in the history
Fix generation of QR codes for long names
  • Loading branch information
jjchee77 authored Mar 29, 2024
2 parents bcebd30 + 3270af5 commit 6bbde3f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ Thus, we chose to only generate QR codes when the person is successfully added t

This approach was also taken for the editing/deleting of QR codes.

#### QR Code Image Naming
#### QR Code Image File Naming

QR codes associated with a client are named according to the format: [FULL NAME]_[PHONE_NUMBER].png
QR codes associated with a client are saved in the `data/qrcodes` folder as `.png` files, and named according to the following format:

This format was chosen as clients with the same name and phone number are not allowed in FitBook, so these two fields are enough to uniquely identify every client.
* [HASHCODE].png, where [HASHCODE] is the result of the `hashCode()` function of a `Person`.

### Deleting a client from FitBook

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/QrCodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ private static String createVCardString(Person person) {
* @return the file path for the QR code
*/
public static Path getQrCodePath(Person person) {
return Paths.get(QR_CODE_FOLDER.toString(),
person.getName().toString() + "_" + person.getPhone().toString() + ".png");
return Paths.get(QR_CODE_FOLDER.toString(), person.hashCode() + ".png");
}
}
3 changes: 1 addition & 2 deletions src/test/java/seedu/address/QrCodeGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ void generateQrCode_validPerson_success() throws IOException, WriterException {
@Test
void getQrCodePath_validPerson_success() {
Path path = QrCodeGenerator.getQrCodePath(ALICE);
String expected = Paths.get(QrCodeGenerator.QR_CODE_FOLDER.toString(),
ALICE.getName().toString() + "_" + ALICE.getPhone().toString() + ".png").toString();
String expected = Paths.get(QrCodeGenerator.QR_CODE_FOLDER.toString(), ALICE.hashCode() + ".png").toString();
assertEquals(expected, path.toString());
}
}

0 comments on commit 6bbde3f

Please sign in to comment.