#[cfg(feature = "diesel")]
pub(in crate) mod diesel;
mod error;
use crate::paging::Paging;
#[cfg(feature = "diesel")]
pub use self::diesel::{DieselConnectionLocationStore, DieselLocationStore};
pub use error::LocationStoreError;
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct Location {
pub location_id: String,
pub location_address: String,
pub location_namespace: String,
pub owner: String,
pub attributes: Vec<LocationAttribute>,
pub start_commit_num: i64,
pub end_commit_num: i64,
pub service_id: Option<String>,
pub last_updated: Option<i64>,
}
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct LocationList {
pub data: Vec<Location>,
pub paging: Paging,
}
impl LocationList {
pub fn new(data: Vec<Location>, paging: Paging) -> Self {
Self { data, paging }
}
}
#[derive(Clone, Debug, Serialize, PartialEq)]
pub struct LocationAttribute {
pub location_id: String,
pub location_address: String,
pub property_name: String,
pub data_type: String,
pub bytes_value: Option<Vec<u8>>,
pub boolean_value: Option<bool>,
pub number_value: Option<i64>,
pub string_value: Option<String>,
pub enum_value: Option<i32>,
pub struct_values: Option<Vec<LocationAttribute>>,
pub lat_long_value: Option<LatLongValue>,
pub start_commit_num: i64,
pub end_commit_num: i64,
pub service_id: Option<String>,
}
#[derive(Debug, Clone, Copy, Serialize)]
pub struct LatLong;
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct LatLongValue(pub i64, pub i64);
pub trait LocationStore {
fn add_location(&self, location: Location) -> Result<(), LocationStoreError>;
fn get_location(
&self,
location_id: &str,
service_id: Option<&str>,
) -> Result<Option<Location>, LocationStoreError>;
fn list_locations(
&self,
service_id: Option<&str>,
offset: i64,
limit: i64,
) -> Result<LocationList, LocationStoreError>;
fn delete_location(
&self,
address: &str,
current_commit_num: i64,
) -> Result<(), LocationStoreError>;
}
impl<LS> LocationStore for Box<LS>
where
LS: LocationStore + ?Sized,
{
fn add_location(&self, location: Location) -> Result<(), LocationStoreError> {
(**self).add_location(location)
}
fn get_location(
&self,
location_id: &str,
service_id: Option<&str>,
) -> Result<Option<Location>, LocationStoreError> {
(**self).get_location(location_id, service_id)
}
fn list_locations(
&self,
service_id: Option<&str>,
offset: i64,
limit: i64,
) -> Result<LocationList, LocationStoreError> {
(**self).list_locations(service_id, offset, limit)
}
fn delete_location(
&self,
address: &str,
current_commit_num: i64,
) -> Result<(), LocationStoreError> {
(**self).delete_location(address, current_commit_num)
}
}