From ccb6d208204fb286e469e87ad9c85a8c8b7be72a Mon Sep 17 00:00:00 2001 From: PROINT <> Date: Wed, 22 Jul 2026 17:03:47 +0700 Subject: Added JournalEntryRepository --- src/types/journal.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/types/journal.rs') diff --git a/src/types/journal.rs b/src/types/journal.rs index b09c50f..7dd3d63 100644 --- a/src/types/journal.rs +++ b/src/types/journal.rs @@ -22,12 +22,13 @@ pub enum InvalidJournalEntry { AmountTooLarge(u64), } -#[derive(PartialEq)] +#[derive(PartialEq, Clone, Copy)] pub enum PostingType { Debit, Credit } +#[derive(Clone)] pub struct Posting { posting_id: PostingId, pub posting_type: PostingType, @@ -41,6 +42,12 @@ pub struct NewPosting { pub amount: u64 } +impl Posting { + pub(crate) fn from_parts(posting_id: PostingId, posting_type: PostingType, account_id: AccountId, amount: u64) -> Self { + Posting { posting_id, posting_type, account_id, amount } + } +} + impl NewPosting { fn new(posting_type: PostingType, account_id: AccountId, amount: u64) -> NewPosting { NewPosting { @@ -51,6 +58,7 @@ impl NewPosting { } } +#[derive(Clone)] pub struct JournalEntry { journal_entry_id: JournalEntryId, pub date: DateTime, @@ -64,6 +72,16 @@ pub struct NewJournalEntry { pub description: String } +impl JournalEntry { + pub(crate) fn from_parts(journal_entry_id: JournalEntryId, date: DateTime, postings: Vec, description: String) -> Self { + JournalEntry { journal_entry_id, date, postings, description } + } + + pub fn id(&self) -> JournalEntryId { + self.journal_entry_id + } +} + impl NewJournalEntry { fn new(date: DateTime, postings: Vec, description: impl Into) -> NewJournalEntry { NewJournalEntry { -- cgit v1.3