feat(db): Implement ReverseLookupInterface for MockDb (#2119)

This commit is contained in:
Hudson C. Dalprá
2023-09-12 21:46:18 +12:00
committed by GitHub
parent d52fe7f140
commit f2df2d6d01
3 changed files with 34 additions and 4 deletions

View File

@ -48,14 +48,31 @@ impl ReverseLookupInterface for Store {
impl ReverseLookupInterface for MockDb {
async fn insert_reverse_lookup(
&self,
_new: ReverseLookupNew,
new: ReverseLookupNew,
) -> CustomResult<ReverseLookup, errors::StorageError> {
Err(errors::StorageError::MockDbError.into())
let reverse_lookup_insert = ReverseLookup::from(new);
self.reverse_lookups
.lock()
.await
.push(reverse_lookup_insert.clone());
Ok(reverse_lookup_insert)
}
async fn get_lookup_by_lookup_id(
&self,
_id: &str,
lookup_id: &str,
) -> CustomResult<ReverseLookup, errors::StorageError> {
Err(errors::StorageError::MockDbError.into())
self.reverse_lookups
.lock()
.await
.iter()
.find(|reverse_lookup| reverse_lookup.lookup_id == lookup_id)
.ok_or(
errors::StorageError::ValueNotFound(format!(
"No reverse lookup found for lookup_id = {}",
lookup_id
))
.into(),
)
.cloned()
}
}