Moved domain logic out of the database layer, to the user app route.
This commit is contained in:
@@ -12,18 +12,19 @@ impl<T> Upsert<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub enum GuardedUpsert<T> {
|
||||
Created(T),
|
||||
Updated(T),
|
||||
Rejected,
|
||||
pub struct Upserted<T> {
|
||||
pub current: T,
|
||||
pub previous: Option<T>,
|
||||
}
|
||||
|
||||
impl<T> GuardedUpsert<T> {
|
||||
pub fn try_map<U, E>(self, f: impl FnOnce(T) -> Result<U, E>) -> Result<GuardedUpsert<U>, E> {
|
||||
Ok(match self {
|
||||
Self::Created(value) => GuardedUpsert::Created(f(value)?),
|
||||
Self::Updated(value) => GuardedUpsert::Updated(f(value)?),
|
||||
Self::Rejected => GuardedUpsert::Rejected,
|
||||
impl<T> Upserted<T> {
|
||||
pub fn try_map<U, E>(self, mut f: impl FnMut(T) -> Result<U, E>) -> Result<Upserted<U>, E> {
|
||||
Ok(Upserted {
|
||||
current: f(self.current)?,
|
||||
previous: match self.previous {
|
||||
Some(value) => Some(f(value)?),
|
||||
None => None,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user