-
Notifications
You must be signed in to change notification settings - Fork 19
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
Kotlin solution branch #1
base: main
Are you sure you want to change the base?
Conversation
<properties> | ||
<kotlin.version>1.7.20</kotlin.version> | ||
</properties> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to root pom
fun handle(command: RejectPaymentCommand) { | ||
if (!closed) { | ||
AggregateLifecycle.apply(PaymentRejectedEvent(command.paymentId, paymentReference!!)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any tips to get rid of the non-null assertions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you can make the private vars private lateinit var paymentReference: String
(non-nullable) and make sure to set them when handling the PaymentPreparedEvent
(which you do)
paymentStatusRepository | ||
.findById(event.paymentId) | ||
.map { it.rejected() } | ||
.ifPresent { paymentStatusRepository.save(it) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this .save()
invocation is needed? It was not present in the original solution branch, but I don't know why?
|
||
@Saga | ||
class PaymentSaga{ | ||
@Autowired @Transient lateinit var commandGateway: CommandGateway |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we cannot use constructor injection here?
bikeStatusRepository | ||
.findById(event.bikeId) | ||
.map { it.returnedAt(it.location) } | ||
.ifPresent { bikeStatusRepository.save(it) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this .save()
invocation is needed? It was not present in the original solution branch, but I don't know why? Don't we need to update the entity? Don't we need to update the entity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general to make this more Kotlin-esque you can get rid of the java optional by using this kotlin extension function that's in the spring-data repo;
CrudRepository<T, ID>.findByIdOrNull(...): T?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for example:
val status = bikeStatusRepository.findByIdOrNull(event.bikeId) ?: throw IllegalStateException("Cannot find bike status")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Already did this for some cases :) good suggestion
fun handle(command: RejectPaymentCommand) { | ||
if (!closed) { | ||
AggregateLifecycle.apply(PaymentRejectedEvent(command.paymentId, paymentReference!!)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you can make the private vars private lateinit var paymentReference: String
(non-nullable) and make sure to set them when handling the PaymentPreparedEvent
(which you do)
No description provided.