CodeSeoul / event_member_management_backend

ISC License
2 stars 1 forks source link

Fixed member issues #23

Closed xstrengthofonex closed 1 year ago

xstrengthofonex commented 1 year ago
xstrengthofonex commented 1 year ago

The code for making sure the username, email and phoneNumber are unique is not very efficient as it's making multiple queries. However, I can't think of a better way right now. I'm basing the tests off of the Member entity constraints on those fields, which require unique values.

I added NotBlank and Email validations which will catch initial errors when making a post or put request. Unfortunately, the unique constraint annotations cause 500 errors and don't provide any information about what went wrong, so I've added guards for each of the fields. If any of the values are present in the database, an error, along with a message, is appended to an error list.

Also, the update member method as is, requires a look up for fetching the old member and a lookup for each changed field. Those looksup only happen if the username, email or phoneNumber are changed otherwise there are no additional lookups.

xstrengthofonex commented 1 year ago

I assumed the Email validator would count a blank email as invalid but apparently it doesn't.

xstrengthofonex commented 1 year ago

I managed to simplify the query and also refactor the validateNewMember and validateExistingMember into one method. It's not the prettiest code but it passes all the tests.