Skip to content

Commit

Permalink
Update README examples to use DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstyl committed Nov 23, 2021
1 parent b4fc7a1 commit 594b34e
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,35 @@ permission before calling `execute()`.
```kotlin
val store = ContactStore.newInstance(application)

store.execute(SaveRequest().apply {
insert(MutableContact().apply {
store.execute {
insert {
firstName = "Paolo"
lastName = "Melendez"
phones.add(
LabeledValue(
value = PhoneNumber("555"),
label = Label.PhoneNumberMobile
)
phone(
value = PhoneNumber("555"),
label = Label.PhoneNumberMobile
)
})
})
mail(
address = "[email protected]",
label = Label.LocationWork
)
event(
dayOfMonth = 23,
month = 11,
year = 2021,
label = Label.DateBirthday
)
postalAddress(
street = "85 Somewhere Str",
label = Label.LocationHome
)
webAddress(
address = "[email protected]",
label = Label.LocationWork
)
groupMembership(groupId = 123)
}
}
```

### Update an existing contact
Expand All @@ -132,21 +149,21 @@ if (foundContacts.isEmpty()) return // the contact was not found

val contact = foundContacts.first()

store.execute(SaveRequest().apply {
store.execute {
update(contact.mutableCopy().apply {
note = Note("To infinity and beyond!")
})
})
}
```

### Deleting a contact

The following code shows how to delete a contact by id:

```kotlin
store.execute(SaveRequest().apply {
store.execute {
delete(contactId = 5L)
})
}
```

## Using ContactStore in unit tests (experimental)
Expand Down

0 comments on commit 594b34e

Please sign in to comment.