Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borrowing add deadline #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.axonframework.extensions.kotlin.applyEvent
import org.axonframework.modelling.command.AggregateIdentifier
import org.axonframework.modelling.command.TargetAggregateIdentifier
import org.axonframework.spring.stereotype.Aggregate
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.*

/**
Expand All @@ -18,10 +20,14 @@ import java.util.*
class BorrowingAggregate() {

@AggregateIdentifier
lateinit var borrowing: UUID
lateinit var borrowingId: UUID

var copyState = CopyState.AVAILABLE
var borrower: Party? = null
var returnDeadline: Instant? = null

@CommandHandler
constructor(command: RegisterNewBorrowing): this() {
constructor(command: RegisterNewBorrowing) : this() {
applyEvent(RegisteredNewBorrowing(command.isbn, UUID.randomUUID()))
}

Expand All @@ -40,25 +46,27 @@ class BorrowingAggregate() {
borrower != returnCopy.borrower -> throw OnlyBorrowerMayReturnCopy()
else -> applyEvent(CopyReturned())
}

@EventSourcingHandler
fun on(evt: CopyBorrowed) {
this.copyState = CopyState.BORROWED
this.borrower = evt.borrower
this.returnDeadline = Instant.now().plus(30, ChronoUnit.DAYS)
}

@EventSourcingHandler
fun on(evt: CopyReturned) {
this.copyState = CopyState.AVAILABLE
this.borrower = null
this.returnDeadline = null
}
var copyState = CopyState.AVAILABLE
var borrower: Party? = null

}

data class FindBorrowings (val isbn: String)
data class FindBorrowings(val isbn: String)

data class RegisterNewBorrowing (val isbn: String)
data class RegisteredNewBorrowing (val isbn: String, val uuid: UUID)
data class RegisterNewBorrowing(val isbn: String)
data class RegisteredNewBorrowing(val isbn: String, val uuid: UUID)

data class BorrowCopy(@TargetAggregateIdentifier val copyId: UUID, val borrower: Party)
data class ReturnCopy(@TargetAggregateIdentifier val copyId: UUID, val borrower: Party)
Expand All @@ -69,6 +77,7 @@ enum class CopyState {
RESERVED,
BORROWED,
}

class CopyAlreadyBorrowed() : Exception("Copy Already Borrowed")
class CopyAlreadyAvailable() : Exception("Copy Already Returned")
class OnlyBorrowerMayReturnCopy() : Exception("Copy Returned By Wrong Party")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.axonframework.commandhandling.CommandHandler
import org.axonframework.eventsourcing.EventSourcingHandler
import org.axonframework.modelling.command.AggregateIdentifier
import org.axonframework.modelling.command.AggregateLifecycle.apply
import org.axonframework.modelling.command.TargetAggregateIdentifier
import org.axonframework.spring.stereotype.Aggregate
import java.util.*

Expand Down