Skip to content

Commit fa6ad8e

Browse files
authored
feat(doc): Update query.md (#1073)
1 parent 35b6638 commit fa6ad8e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

documentation/docs/guide/query.md

+30
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,36 @@ pagedQuery {
248248
}.query(queryService)
249249
```
250250

251+
## 重写查询
252+
253+
```kotlin
254+
@Component
255+
@Order(ORDER_FIRST)
256+
@FilterType(SnapshotQueryHandler::class)
257+
class DataFilterSnapshotQueryFilter : SnapshotQueryFilter {
258+
259+
override fun filter(
260+
context: QueryContext<*, *>,
261+
next: FilterChain<QueryContext<*, *>>,
262+
): Mono<Void> {
263+
264+
return Mono.deferContextual {
265+
/**
266+
* 重写查询,将仓库ID附加到查询条件中。
267+
*/
268+
context.asRewritableQuery().rewriteQuery { query ->
269+
val warehouseIdCondition = condition {
270+
nestedState()
271+
WarehouseIdCapable::warehouseId.name eq warehouseId
272+
}
273+
query.appendCondition(warehouseIdCondition)
274+
}
275+
next.filter(context)
276+
}
277+
}
278+
}
279+
```
280+
251281
## OpenAPI
252282

253283
**Wow** 除了为命令(`Command`)自动生成了 _OpenAPI_ 端点,另外还提供了查询(`Query`) _OpenAPI_ 端点。

0 commit comments

Comments
 (0)