Creates a new address book entry.
(
&self,
input: AddAddressBookEntryOperationInput,
)
| 109 | |
| 110 | /// Creates a new address book entry. |
| 111 | pub async fn create_entry( |
| 112 | &self, |
| 113 | input: AddAddressBookEntryOperationInput, |
| 114 | ) -> ServiceResult<AddressBookEntry> { |
| 115 | let uuid = generate_uuid_v4().await; |
| 116 | let key = AddressBookEntry::key(*uuid.as_bytes()); |
| 117 | |
| 118 | let new_entry = AddressBookMapper::from_create_input(input.to_owned(), *uuid.as_bytes())?; |
| 119 | new_entry.validate()?; |
| 120 | |
| 121 | if let Some(v) = self |
| 122 | .address_book_repository |
| 123 | .find_by_address(new_entry.blockchain.clone(), new_entry.address.clone()) |
| 124 | { |
| 125 | return Err(AddressBookError::DuplicateAddress { |
| 126 | id: Uuid::from_bytes(v.id).hyphenated().to_string(), |
| 127 | })?; |
| 128 | } |
| 129 | |
| 130 | // Inserting the address book entry into the repository and its associations is the last step of the address book entry creation |
| 131 | // process to avoid potential consistency issues due to the fact that some of the calls to create the address book entry |
| 132 | // happen in an asynchronous way. |
| 133 | self.address_book_repository.insert(key, new_entry.clone()); |
| 134 | |
| 135 | Ok(new_entry) |
| 136 | } |
| 137 | |
| 138 | /// Edits an existing address book entry. |
| 139 | pub async fn edit_entry( |
no test coverage detected