Skip to content

Commit

Permalink
feat(example-server): add customize send cmd endpoint
Browse files Browse the repository at this point in the history
- Add new POST endpoint /cart/{userId} to send custom commands
- Implement functionality to add items to user's cart using AddCartItem command- Update CartController to include new method for handling custom commands
  • Loading branch information
Ahoo-Wang committed Jan 20, 2025
1 parent b1f3e56 commit 3e2d1ab
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -13,18 +13,26 @@

package me.ahoo.wow.example.server.cart

import io.swagger.v3.oas.annotations.Operation
import me.ahoo.wow.apiclient.query.queryState
import me.ahoo.wow.command.CommandGateway
import me.ahoo.wow.command.CommandResult
import me.ahoo.wow.command.toCommandMessage
import me.ahoo.wow.example.api.cart.AddCartItem
import me.ahoo.wow.example.api.cart.CartData
import me.ahoo.wow.example.api.client.CartQueryClient
import me.ahoo.wow.example.api.client.CartQuerySyncClient
import me.ahoo.wow.query.dsl.singleQuery
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.service.annotation.GetExchange
import org.springframework.web.service.annotation.PostExchange
import reactor.core.publisher.Mono
import reactor.core.scheduler.Schedulers

@RestController
class CartController(
private val commandGateway: CommandGateway,
private val cartQueryClient: CartQueryClient,
private val cartQuerySyncClient: CartQuerySyncClient
) {
@@ -44,4 +52,15 @@ class CartController(
}.queryState(cartQuerySyncClient)
}.subscribeOn(Schedulers.boundedElastic())
}

@Operation(description = "自定义发送命令")
@PostExchange("/cart/{userId}/customize-send-cmd")
fun customizeSendCmd(@PathVariable userId: String): Mono<CommandResult> {
val addCartItem = AddCartItem(
id = userId,
productId = "productId",
quantity = 1
)
return commandGateway.sendAndWaitForSnapshot(addCartItem.toCommandMessage())
}
}

0 comments on commit 3e2d1ab

Please sign in to comment.