use super::BatchStoreOperations;
use crate::batches::store::{diesel::schema::batches, BatchStoreError};
use crate::error::InternalError;
use diesel::{dsl::update, prelude::*};
pub(in crate::batches::store::diesel) trait ChangeBatchToSubmittedOperation {
fn change_batch_to_submitted(&self, id: &str) -> Result<(), BatchStoreError>;
}
#[cfg(feature = "postgres")]
impl<'a> ChangeBatchToSubmittedOperation for BatchStoreOperations<'a, diesel::pg::PgConnection> {
fn change_batch_to_submitted(&self, id: &str) -> Result<(), BatchStoreError> {
self.conn.transaction::<_, BatchStoreError, _>(|| {
update(batches::table)
.filter(batches::header_signature.eq(id))
.set(batches::submitted.eq(true))
.execute(self.conn)
.map(|_| ())
.map_err(|err| {
BatchStoreError::InternalError(InternalError::from_source(Box::new(err)))
})
})
}
}
#[cfg(feature = "sqlite")]
impl<'a> ChangeBatchToSubmittedOperation
for BatchStoreOperations<'a, diesel::sqlite::SqliteConnection>
{
fn change_batch_to_submitted(&self, id: &str) -> Result<(), BatchStoreError> {
self.conn.transaction::<_, BatchStoreError, _>(|| {
update(batches::table)
.filter(batches::header_signature.eq(id))
.set(batches::submitted.eq(true))
.execute(self.conn)
.map(|_| ())
.map_err(|err| {
BatchStoreError::InternalError(InternalError::from_source(Box::new(err)))
})
})
}
}