-
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.
feat(backend): Replace interceptors with calls to ports
- Loading branch information
1 parent
e70ac83
commit b67263c
Showing
14 changed files
with
171 additions
and
219 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
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
6 changes: 6 additions & 0 deletions
6
...ain/kotlin/me/rasztabiga/thesis/delivery/domain/command/port/CourierOnlineVerifierPort.kt
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package me.rasztabiga.thesis.delivery.domain.command.port | ||
|
||
interface CourierOnlineVerifierPort { | ||
|
||
fun isCourierOnline(courierId: String): Boolean | ||
} |
22 changes: 22 additions & 0 deletions
22
...lin/me/rasztabiga/thesis/delivery/infrastructure/axon/AxonCourierOnlineVerifierAdapter.kt
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package me.rasztabiga.thesis.delivery.infrastructure.axon | ||
|
||
import me.rasztabiga.thesis.delivery.domain.command.port.CourierOnlineVerifierPort | ||
import me.rasztabiga.thesis.shared.adapter.`in`.rest.api.CourierResponse | ||
import me.rasztabiga.thesis.shared.domain.query.query.FindCourierByIdQuery | ||
import org.axonframework.messaging.responsetypes.ResponseTypes | ||
import org.axonframework.queryhandling.QueryGateway | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class AxonCourierOnlineVerifierAdapter( | ||
private val queryGateway: QueryGateway | ||
) : CourierOnlineVerifierPort { | ||
|
||
override fun isCourierOnline(courierId: String): Boolean { | ||
val courier = queryGateway.query( | ||
FindCourierByIdQuery(courierId), | ||
ResponseTypes.instanceOf(CourierResponse::class.java) | ||
).join() | ||
return courier.availability == CourierResponse.Availability.ONLINE | ||
} | ||
} |
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
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
71 changes: 71 additions & 0 deletions
71
...c/main/kotlin/me/rasztabiga/thesis/order/adapter/out/axon/AxonOrderVerificationAdapter.kt
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package me.rasztabiga.thesis.order.adapter.out.axon | ||
|
||
import me.rasztabiga.thesis.order.domain.command.port.OrderVerificationPort | ||
import me.rasztabiga.thesis.shared.adapter.`in`.rest.api.RestaurantResponse | ||
import me.rasztabiga.thesis.shared.adapter.`in`.rest.api.UserResponse | ||
import me.rasztabiga.thesis.shared.domain.query.query.FindRestaurantByIdQuery | ||
import me.rasztabiga.thesis.shared.domain.query.query.FindUserByIdQuery | ||
import org.axonframework.messaging.responsetypes.ResponseTypes | ||
import org.axonframework.queryhandling.QueryGateway | ||
import org.springframework.stereotype.Service | ||
import java.util.* | ||
|
||
@Service | ||
class AxonOrderVerificationAdapter( | ||
private val queryGateway: QueryGateway | ||
) : OrderVerificationPort { | ||
override fun restaurantExists(restaurantId: UUID): Boolean { | ||
val restaurant = queryGateway.query( | ||
FindRestaurantByIdQuery( | ||
restaurantId, | ||
), | ||
ResponseTypes.optionalInstanceOf(RestaurantResponse::class.java) | ||
).get() | ||
|
||
return restaurant.isPresent | ||
} | ||
|
||
override fun isRestaurantOpen(restaurantId: UUID): Boolean { | ||
val restaurant = queryGateway.query( | ||
FindRestaurantByIdQuery( | ||
restaurantId, | ||
), | ||
ResponseTypes.instanceOf(RestaurantResponse::class.java) | ||
).get() | ||
|
||
return restaurant.availability == RestaurantResponse.Availability.OPEN | ||
} | ||
|
||
override fun userExists(userId: String): Boolean { | ||
val user = queryGateway.query( | ||
FindUserByIdQuery( | ||
userId, | ||
), | ||
ResponseTypes.optionalInstanceOf(UserResponse::class.java) | ||
).get() | ||
|
||
return user.isPresent | ||
} | ||
|
||
override fun productExists(productId: UUID, restaurantId: UUID): Boolean { | ||
val restaurant = queryGateway.query( | ||
FindRestaurantByIdQuery( | ||
restaurantId, | ||
), | ||
ResponseTypes.instanceOf(RestaurantResponse::class.java) | ||
).get() | ||
|
||
return restaurant.menu.any { it.id == productId } | ||
} | ||
|
||
override fun deliveryAddressExists(deliveryAddressId: UUID, userId: String): Boolean { | ||
val user = queryGateway.query( | ||
FindUserByIdQuery( | ||
userId, | ||
), | ||
ResponseTypes.instanceOf(UserResponse::class.java) | ||
).get() | ||
|
||
return user.deliveryAddresses.any { it.id == deliveryAddressId } | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
order/src/main/kotlin/me/rasztabiga/thesis/order/config/CommandConfiguration.kt
This file was deleted.
Oops, something went wrong.
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.