Refactored API DTOs to be more straight forward.

This commit is contained in:
2026-09-26 18:27:18 +02:00
parent 4737bd5c81
commit 9279258ff1
6 changed files with 250 additions and 192 deletions
@@ -67,18 +67,18 @@ fn decode(row: RecurringTransactionRow) -> Result<RecurringTransaction, DecodeEr
let recurrence = Recurrence {
every: RecurrenceInterval::try_from(row.recurrence_every)?,
unit: decode_recurrence_unit(row.recurrence_unit)?,
weekend_adjustment: row
.weekend_adjustment
.map(decode_weekend_adjustment)
.transpose()?,
};
let weekend_adjustment = row
.weekend_adjustment
.map(decode_weekend_adjustment)
.transpose()?;
Ok(RecurringTransaction {
id: row.id,
name: row.name,
amount: Cents::try_from(row.amount_cents)?,
direction: decode_direction(row.direction)?,
schedule: Schedule::new(row.starts_at, row.ends_at, recurrence)?,
schedule: Schedule::new(row.starts_at, row.ends_at, recurrence, weekend_adjustment)?,
})
}
@@ -94,8 +94,9 @@ fn encode(transaction: RecurringTransaction) -> RecurringTransactionRow {
ends_at: transaction.schedule.end(),
recurrence_every: recurrence.every.into(),
recurrence_unit: encode_recurrence_unit(recurrence.unit).to_owned(),
weekend_adjustment: recurrence
.weekend_adjustment
weekend_adjustment: transaction
.schedule
.weekend_adjustment()
.map(|adjustment| encode_weekend_adjustment(adjustment).to_owned()),
}
}
@@ -138,7 +139,7 @@ mod tests {
assert_eq!(recurrence.every.get(), 1);
assert_eq!(recurrence.unit, RecurrenceUnit::Month);
assert_eq!(
recurrence.weekend_adjustment,
transaction.schedule.weekend_adjustment(),
Some(WeekendAdjustment::NextBusinessDay)
);
}