forked from business4s/workflows4s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
238 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
22 changes: 13 additions & 9 deletions
22
workflow4s-example/src/main/scala/workflow4s/example/WithdrawalData.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
package workflow4s.example | ||
|
||
import workflow4s.example.WithdrawalService.Fee | ||
import workflow4s.example.WithdrawalService.{Fee, Iban} | ||
import workflow4s.example.checks.ChecksState | ||
|
||
sealed trait WithdrawalData | ||
|
||
object WithdrawalData { | ||
case class Empty(txId: String) extends WithdrawalData { | ||
def initiated(amount: BigDecimal) = Initiated(txId, amount) | ||
case class Empty(txId: String) extends WithdrawalData { | ||
def initiated(amount: BigDecimal, recipient: Iban) = Initiated(txId, amount, recipient) | ||
} | ||
case class Initiated(txId: String, amount: BigDecimal) extends WithdrawalData { | ||
def validated(fee: Fee) = Validated(txId, amount, fee) | ||
case class Initiated(txId: String, amount: BigDecimal, recipient: Iban) extends WithdrawalData { | ||
def validated(fee: Fee) = Validated(txId, amount, recipient, fee) | ||
} | ||
case class Validated(txId: String, amount: BigDecimal, fee: Fee) extends WithdrawalData { | ||
def checked(checksState: ChecksState) = Checked(txId, amount, fee, checksState) | ||
case class Validated(txId: String, amount: BigDecimal, recipient: Iban, fee: Fee) extends WithdrawalData { | ||
def checked(checksState: ChecksState) = Checked(txId, amount, recipient, fee, checksState) | ||
} | ||
case class Checked(txId: String, amount: BigDecimal, recipient: Iban, fee: Fee, checkResults: ChecksState) extends WithdrawalData { | ||
def netAmount = amount - fee.value | ||
def executed(externalTxId: String) = Executed(txId, amount, recipient, fee, checkResults, externalTxId) | ||
} | ||
case class Checked(txId: String, amount: BigDecimal, fee: Fee, checkResults: ChecksState) extends WithdrawalData | ||
|
||
case class Executed(txId: String, amount: BigDecimal, fee: Fee, checkResults: ChecksState, externalTransactionId: String) extends WithdrawalData | ||
case class Executed(txId: String, amount: BigDecimal, recipient: Iban, fee: Fee, checkResults: ChecksState, externalTransactionId: String) | ||
extends WithdrawalData | ||
|
||
case class Completed() extends WithdrawalData | ||
} |
This file contains 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
This file contains 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
12 changes: 11 additions & 1 deletion
12
workflow4s-example/src/main/scala/workflow4s/example/WithdrawalService.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
package workflow4s.example | ||
|
||
import cats.effect.IO | ||
import workflow4s.example.WithdrawalService.{Fee, NotEnoughFunds} | ||
import workflow4s.example.WithdrawalService.{ExecutionResponse, Fee, Iban, NotEnoughFunds} | ||
|
||
trait WithdrawalService { | ||
def calculateFees(amount: BigDecimal): IO[Fee] | ||
|
||
def putMoneyOnHold(amount: BigDecimal): IO[Either[NotEnoughFunds, Unit]] | ||
|
||
def initiateExecution(amount: BigDecimal, recepient: Iban): IO[ExecutionResponse] | ||
} | ||
|
||
object WithdrawalService { | ||
|
||
case class NotEnoughFunds() | ||
|
||
case class Fee(value: BigDecimal) | ||
|
||
case class Iban(value: String) | ||
|
||
sealed trait ExecutionResponse | ||
object ExecutionResponse { | ||
case class Accepted(externalId: String) extends ExecutionResponse | ||
case class Rejected(error: String) extends ExecutionResponse | ||
} | ||
} |
9 changes: 8 additions & 1 deletion
9
workflow4s-example/src/main/scala/workflow4s/example/WithdrawalSignal.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package workflow4s.example | ||
|
||
import workflow4s.example.WithdrawalService.Iban | ||
|
||
object WithdrawalSignal { | ||
|
||
case class CreateWithdrawal(amount: BigDecimal) | ||
case class CreateWithdrawal(amount: BigDecimal, recipient: Iban) | ||
|
||
sealed trait ExecutionCompleted | ||
object ExecutionCompleted { | ||
case object Succeeded extends ExecutionCompleted | ||
case object Failed extends ExecutionCompleted | ||
} | ||
} |
This file contains 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
Oops, something went wrong.