capacitor-community / capacitor-community/contacts

RFC: support for updating a contact

Open
#86 3 comments 9 reactions 0 assignees View on GitHub
enhancement good first issue help wanted
Dominant language
Java
Stars
144
Forks
75
PR merge metrics
No merged PRs in 30d

Description

Updating a contact may be considered a fairly basic feature that should probably be implemented. However, it is not as straight forward as one might think.

---

If you are in need of this functionality, please +1 this post **by means of a GitHub reaction** (so not with a comment).

---

**Approach 1**

The easiest approach would be to implement a PUT instead of PATCH (REST-API analogy). That means that the contact will get completely overwritten with the newly defined values. Essentially, this would be the same as removing the contact and creating a new one.

This is quite easy to implement, but the developer experience, and (maybe moreover) the user experience is sub-optimal to say the least.

If the developer only wants to update a single contact's phone number, he would still have to retrieve all of that user's data, and consequently put all that data into the `updateContact` method. Not very ideal.

If the developer forgets to do above said things, a user might end up with a contact with only the newly updated phone number, with all "old" data deleted. Not very user friendly.

---

**Approach 2**

It would be possible to do a "partial PUT". This would entail that the developer does not have to supply **all** data, but just the data for the object he is updating. So if, for example, the developer wants to update a contact's phone number, he will only have to supply all the other phone numbers that are supposed to be kept.

This approach has a better developer experience than approach # 1, but it's still not very ideal.

---

**Approach 3**

Arguably the best approach is this: make it possible to retrieve the IDs of a contact's phone, email, postal address etc. This way a developer can just specify which object (phone, email, postal address) object should be updated, by simply providing the correct id.

Still this has some quirks that should be thought about. For example:

The developer wants to updated the postal address with id 123. **But** he only wants to update the street, not all the other fields... What should be done now? Does the developer have to specify all the other "old" fields, so we can overwrite the whole object. Or does the API only update the given fields. But in the latter case, how would it be possible to delete / empty fields?

Of course, this approach, will also take the longest to develop and test.

---

All in all, still some questions. Unfortunately, I don't have the time, nor the need, to implement this. But of course, suggestions, comments, PRs, or any input for that matter, is very welcome.

Contributor guide

Open the contributing guide

Research direction

Start with the existing updateContact method and review how contacts and their phone, email, and postal-address objects are represented. Compare the three proposed approaches, including partial updates, object IDs, and clearing fields. Done requires a decided update contract plus implementation and tests for the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.