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

Kotlin solution branch #1

Open
wants to merge 2 commits into
base: main
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
17 changes: 11 additions & 6 deletions core-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@

<artifactId>core-api</artifactId>

<properties>
<kotlin.version>1.7.20</kotlin.version>
</properties>

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to root pom

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

</project>
</project>

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.axoniq.demo.bikerental.coreapi.payment

import jakarta.persistence.Entity
import jakarta.persistence.Id

@Entity
data class PaymentStatus(
@Id var id: String,
val amount: Int,
val reference: String,
val status: Status = Status.PENDING,
) {
fun approved() = this.copy(status = Status.APPROVED)
fun rejected() = this.copy(status = Status.REJECTED)

enum class Status { PENDING, APPROVED, REJECTED }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.axoniq.demo.bikerental.coreapi.payment

import org.axonframework.commandhandling.RoutingKey
import org.axonframework.modelling.command.TargetAggregateIdentifier

data class PreparePaymentCommand(
val amount: Int,
@RoutingKey val paymentReference: String
)

data class ConfirmPaymentCommand(
@TargetAggregateIdentifier val paymentId: String
)

data class RejectPaymentCommand(
@TargetAggregateIdentifier val paymentId: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.axoniq.demo.bikerental.coreapi.payment

data class PaymentConfirmedEvent(
val paymentId: String,
val paymentReference: String
)

data class PaymentPreparedEvent(
val paymentId: String,
val amount: Int,
val paymentReference: String
)

data class PaymentRejectedEvent(
val paymentId: String,
val paymentReference: String
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.axoniq.demo.bikerental.coreapi.rental

import jakarta.persistence.Entity
import jakarta.persistence.Id

@Entity
data class BikeStatus(
@Id
var bikeId: String,
val bikeType: String,
val location: String,
val status: RentalStatus = RentalStatus.AVAILABLE,
val renter: String? = null,
) {

fun returnedAt(location: String) = this.copy(
location = location,
status = RentalStatus.AVAILABLE,
renter = null
)

fun requestedBy(renter: String) = this.copy(
status = RentalStatus.REQUESTED,
renter = renter
)

fun rentedBy(renter: String) = this.copy(
status = RentalStatus.RENTED,
renter = renter
)

val description: String
get() = when (status) {
RentalStatus.RENTED -> "Bike $bikeId was rented by $renter in $location"
RentalStatus.AVAILABLE -> "Bike $bikeId is available for rental in $location."
RentalStatus.REQUESTED -> "Bike $bikeId is requested by $renter in $location"
}
}

enum class RentalStatus {
AVAILABLE,
REQUESTED,
RENTED
}
Loading