This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kakeibo | |
import cats.effect.{IO, IOApp} | |
import edomata.core.CommandMessage | |
import kakeibo.JournalEntry.AccountTitle.* | |
import java.time.{Instant, LocalDate} | |
object Main extends IOApp.Simple { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kakeibo | |
import cats.effect.Async | |
import cats.effect.kernel.Resource | |
import cats.effect.std.Console | |
import fs2.io.net.Network | |
import natchez.Trace.Implicits.noop | |
import skunk.Session | |
final case class Application[F[_]]( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BalanceSheetApp { | |
given BackendCodec[BsEvent] = CirceCodec.json | |
given BackendCodec[BsNotification] = CirceCodec.json | |
given BackendCodec[BalanceSheet] = CirceCodec.json | |
def backend[F[_]: Async](pool: Resource[F, Session[F]]) = Backend | |
.builder(BalanceSheetService) | |
.use(SkunkDriver("edomata_kakeibo", pool)) | |
.build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.Id | |
"初期化" should { | |
"コマンドを受け付ける" in { | |
// Given | |
val initA = Map(Cash -> BigDecimal(1_000_000)) | |
val initL = Map(AccruedLiability -> BigDecimal(100_000)) | |
val initializeScenario = RequestContext( | |
command = CommandMessage( | |
id = "some-id", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BalanceSheetService | |
extends BalanceSheet.Service[BsCommand, BsNotification] { | |
def apply[F[_]: Monad]: App[F, Unit] = App.router { | |
case BsCommand.Initialize(a, l) => | |
for { | |
ready <- App.state.decide(_.initialize(a, l)) | |
aggId <- App.aggregateId | |
_ <- App.publish(BsNotification.BalanceSheetPrepared(aggId, ready)) | |
} yield () | |
case BsCommand.Journalize(e) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"負数の残高にはできない" in { | |
// Given | |
val initA = Map(Cash -> BigDecimal(1_000_000)) | |
val initL = Map.empty[AccountTitle, BigDecimal] | |
val entry = JournalEntry( | |
date = LocalDate.now(), | |
debit = BankAccount, | |
credit = Cash, | |
amount = BigDecimal(2_000_000), | |
description = "入金" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"仕訳の記帳" should { | |
"BS を更新する" in { | |
// Given | |
val initA = Map(Cash -> BigDecimal(1_000_000)) | |
val initL = Map(AccruedLiability -> BigDecimal(100_000)) | |
val entry1 = JournalEntry( | |
date = LocalDate.now(), | |
debit = BankAccount, | |
credit = Cash, | |
amount = BigDecimal(500_000), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"初期化" should { | |
"任意の資産と負債を受け取り、準備ができる" in { | |
// Given | |
val initialAssets = ... | |
val initialLiabilities = ... | |
// When | |
val result = BalanceSheet.NotReady.initialize( | |
assets = initialAssets, | |
liabilities = initialLiabilities | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BalanceSheet extends DomainModel[BalanceSheet, BsEvent, BsRejection] { | |
override def initial: BalanceSheet = NotReady | |
override def transition | |
: BsEvent => BalanceSheet => ValidatedNec[BsRejection, BalanceSheet] = { | |
case Initialized(as, ls) => _ => Ready(as, ls).validNec | |
case Journalized(e) => | |
_.mustBeReady.map { bs => | |
bs.copy( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import edomata.core.* | |
import edomata.syntax.all.* | |
enum BalanceSheet { | |
case NotReady | |
case Ready( | |
assets: Map[AccountTitle, BigDecimal], | |
liabilities: Map[AccountTitle, BigDecimal] | |
) |
NewerOlder