forked from halo-dev/halo
/
ReplyQuery.java
54 lines (47 loc) · 1.87 KB
/
ReplyQuery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package run.halo.app.content.comment;
import static run.halo.app.extension.index.query.QueryFactory.equal;
import static run.halo.app.extension.router.selector.SelectorUtil.labelAndFieldSelectorToListOptions;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Sort;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.ServerWebInputException;
import run.halo.app.core.extension.content.Reply;
import run.halo.app.extension.ListOptions;
import run.halo.app.extension.PageRequest;
import run.halo.app.extension.PageRequestImpl;
import run.halo.app.extension.router.SortableRequest;
/**
* Query criteria for {@link Reply} list.
*
* @author guqing
* @since 2.0.0
*/
public class ReplyQuery extends SortableRequest {
public ReplyQuery(ServerWebExchange exchange) {
super(exchange);
}
@Schema(description = "Replies filtered by commentName.")
public String getCommentName() {
String commentName = queryParams.getFirst("commentName");
if (StringUtils.isBlank(commentName)) {
throw new ServerWebInputException("The required parameter 'commentName' is missing.");
}
return commentName;
}
/**
* Build list options from query criteria.
*/
public ListOptions toListOptions() {
var listOptions =
labelAndFieldSelectorToListOptions(getLabelSelector(), getFieldSelector());
var newFieldSelector = listOptions.getFieldSelector()
.andQuery(equal("spec.commentName", getCommentName()));
listOptions.setFieldSelector(newFieldSelector);
return listOptions;
}
public PageRequest toPageRequest() {
var sort = getSort().and(Sort.by("spec.creationTime").ascending());
return PageRequestImpl.of(getPage(), getSize(), sort);
}
}