46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
use std::io::{Error, ErrorKind};
|
|
use surveillant_systeme_domain::configuration::port::ConfigurationPort;
|
|
use crate::configuration::repository::ConfigurationSqliteRepository;
|
|
|
|
#[derive(Clone)]
|
|
pub struct ConfigurationSqliteAdapter {
|
|
repository: ConfigurationSqliteRepository
|
|
}
|
|
|
|
impl ConfigurationSqliteAdapter {
|
|
pub fn new(repository: ConfigurationSqliteRepository) -> Self {
|
|
Self {
|
|
repository
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ConfigurationPort for ConfigurationSqliteAdapter {
|
|
fn get_initialisation_code(&self) -> Result<Option<String>, Error> {
|
|
self.repository.get_initialisation_code()
|
|
.map_err(|error| Error::new(
|
|
ErrorKind::Other,
|
|
format!("Unable to retrieve the initialisation code… Cause: {}", error)
|
|
))
|
|
}
|
|
|
|
fn save(&self, initialisation_code: String) -> Result<(), Error> {
|
|
self.repository.save(initialisation_code)
|
|
.map_err(|error| Error::new(
|
|
ErrorKind::Other,
|
|
format!("Unable to save the initialisation code… Cause: {}", error)
|
|
))
|
|
}
|
|
|
|
fn erase_initialisation_code(&self) -> Result<(), Error> {
|
|
self.repository.erase_initialisation_code()
|
|
.map_err(|error| Error::new(
|
|
ErrorKind::Other,
|
|
format!("Unable to erase the initialisation code… Cause: {}", error)
|
|
))
|
|
}
|
|
|
|
fn clone_box(&self) -> Box<dyn ConfigurationPort> {
|
|
Box::new(self.clone())
|
|
}
|
|
} |