mirror of https://gitlab.com/famedly/conduit
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
2 years ago
|
mod data;
|
||
|
pub use data::Data;
|
||
3 years ago
|
|
||
2 years ago
|
use crate::service::*;
|
||
4 years ago
|
|
||
2 years ago
|
pub struct Service<D: Data> {
|
||
|
db: D,
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
impl Service<_> {
|
||
4 years ago
|
pub fn add_txnid(
|
||
|
&self,
|
||
|
user_id: &UserId,
|
||
4 years ago
|
device_id: Option<&DeviceId>,
|
||
2 years ago
|
txn_id: &TransactionId,
|
||
4 years ago
|
data: &[u8],
|
||
|
) -> Result<()> {
|
||
|
let mut key = user_id.as_bytes().to_vec();
|
||
|
key.push(0xff);
|
||
4 years ago
|
key.extend_from_slice(device_id.map(|d| d.as_bytes()).unwrap_or_default());
|
||
4 years ago
|
key.push(0xff);
|
||
|
key.extend_from_slice(txn_id.as_bytes());
|
||
|
|
||
3 years ago
|
self.userdevicetxnid_response.insert(&key, data)?;
|
||
4 years ago
|
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
pub fn existing_txnid(
|
||
|
&self,
|
||
|
user_id: &UserId,
|
||
4 years ago
|
device_id: Option<&DeviceId>,
|
||
2 years ago
|
txn_id: &TransactionId,
|
||
3 years ago
|
) -> Result<Option<Vec<u8>>> {
|
||
4 years ago
|
let mut key = user_id.as_bytes().to_vec();
|
||
|
key.push(0xff);
|
||
4 years ago
|
key.extend_from_slice(device_id.map(|d| d.as_bytes()).unwrap_or_default());
|
||
4 years ago
|
key.push(0xff);
|
||
|
key.extend_from_slice(txn_id.as_bytes());
|
||
|
|
||
|
// If there's no entry, this is a new transaction
|
||
3 years ago
|
self.userdevicetxnid_response.get(&key)
|
||
4 years ago
|
}
|
||
|
}
|