新增作者相关参数及接口
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
> 基于原作者v1.4.3代码修改
|
||||
|
||||
#### v1.4.3-2
|
||||
1. 新增URL参数author用于查询作者
|
||||
2. 模板参数新增${authors}返回所有作者
|
||||
|
||||
#### v1.4.3-1
|
||||
1. 大幅增加description字段的字符数上限
|
||||
2. 去除description字段内的微博视频提示
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
version=1.4.3-1
|
||||
version=1.4.3-2
|
||||
|
||||
@@ -25,4 +25,6 @@ public interface FriendFinder {
|
||||
Mono<FriendPostVo> getByName(String friendPostName);
|
||||
|
||||
Flux<LinkGroupVo> linkGroupBy();
|
||||
|
||||
Flux<String> listAllAuthors();
|
||||
}
|
||||
|
||||
@@ -96,6 +96,22 @@ public class FriendFinderImpl implements FriendFinder {
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<String> listAllAuthors() {
|
||||
var listOptions = new ListOptions();
|
||||
// 只查有数据的,排除已删除的
|
||||
var query = isNull("metadata.deletionTimestamp");
|
||||
listOptions.setFieldSelector(FieldSelector.of(query));
|
||||
|
||||
return client.listAll(FriendPost.class, listOptions, defaultSort())
|
||||
// 提取作者名
|
||||
.map(friendPost -> friendPost.getSpec().getAuthor())
|
||||
// 过滤掉空值
|
||||
.filter(StringUtils::isNotBlank)
|
||||
// 去重
|
||||
.distinct();
|
||||
}
|
||||
|
||||
private Mono<ListResult<FriendPostVo>> pageFriendPost(ListOptions queryOptions, PageRequest page){
|
||||
var listOptions = new ListOptions();
|
||||
var query = all();
|
||||
@@ -220,6 +236,8 @@ public class FriendFinderImpl implements FriendFinder {
|
||||
private Integer page;
|
||||
private Integer size;
|
||||
private String linkName;
|
||||
// 作者查询
|
||||
private String author;
|
||||
private List<String> sort;
|
||||
|
||||
public ListOptions toListOptions() {
|
||||
@@ -227,6 +245,10 @@ public class FriendFinderImpl implements FriendFinder {
|
||||
if (StringUtils.isNotBlank(linkName)) {
|
||||
builder.andQuery(equal("spec.linkName", linkName));
|
||||
}
|
||||
// 作者查询
|
||||
if (StringUtils.isNotBlank(author)) {
|
||||
builder.andQuery(equal("spec.author", author));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,12 @@ public class FriendPostQuery extends SortableRequest {
|
||||
return queryParams.getFirst("linkName");
|
||||
}
|
||||
|
||||
// 作者查询
|
||||
@Nullable
|
||||
public String getAuthor() {
|
||||
return StringUtils.defaultIfBlank(queryParams.getFirst("author"), null);
|
||||
}
|
||||
|
||||
|
||||
public ListOptions toListOptions() {
|
||||
var builder = ListOptions.builder(super.toListOptions());
|
||||
@@ -55,6 +61,11 @@ public class FriendPostQuery extends SortableRequest {
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.ifPresent(linkName -> builder.andQuery(equal("spec.linkName", linkName)));
|
||||
|
||||
// 作者查询
|
||||
Optional.ofNullable(getAuthor())
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.ifPresent(author -> builder.andQuery(equal("spec.author", author)));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -102,6 +113,13 @@ public class FriendPostQuery extends SortableRequest {
|
||||
.name("keyword")
|
||||
.description("CronFriendPost filtered by keyword.")
|
||||
.implementation(String.class)
|
||||
.required(false))
|
||||
// 作者查询
|
||||
.parameter(parameterBuilder()
|
||||
.in(ParameterIn.QUERY)
|
||||
.name("author")
|
||||
.description("FriendPost filtered by exact author name.")
|
||||
.implementation(String.class)
|
||||
.required(false));
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ public class FriendRouter {
|
||||
.flatMap( templateName -> ServerResponse.ok().render(templateName,
|
||||
java.util.Map.of(ModelConst.TEMPLATE_ID, templateName,
|
||||
"friends", friendPostList(request),
|
||||
"authors", friendFinder.listAllAuthors().collectList(),
|
||||
"title",getFriendTitle())
|
||||
));
|
||||
}
|
||||
@@ -65,6 +66,24 @@ public class FriendRouter {
|
||||
String linkName = request.queryParam("linkName")
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.orElse(null);
|
||||
// --- 新增:获取 author 参数 ---
|
||||
String author = request.queryParam("author")
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.orElse(null);
|
||||
|
||||
// --- 新增:构建查询参数字符串 ---
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
if (StringUtils.isNotBlank(linkName)) {
|
||||
queryString.append("linkName=").append(linkName);
|
||||
}
|
||||
if (StringUtils.isNotBlank(author)) {
|
||||
if (queryString.length() > 0) {
|
||||
queryString.append("&");
|
||||
}
|
||||
queryString.append("author=").append(author);
|
||||
}
|
||||
final String finalQueryString = queryString.toString();
|
||||
|
||||
return this.settingFetcher.get("base")
|
||||
.map(item -> item.get("pageSize").asInt(10))
|
||||
.defaultIfEmpty(10)
|
||||
@@ -75,16 +94,40 @@ public class FriendRouter {
|
||||
if(StringUtils.isNotBlank(linkName)){
|
||||
params.put("linkName",linkName);
|
||||
}
|
||||
// --- 新增:把 author 也放进 params ---
|
||||
if(StringUtils.isNotBlank(author)){
|
||||
params.put("author",author);
|
||||
}
|
||||
|
||||
return friendFinder.list(params)
|
||||
.map(list -> new UrlContextListResult.Builder<FriendPostVo>()
|
||||
.listResult(list)
|
||||
.nextUrl(PageUrlUtils.nextPageUrl(path, totalPage(list)))
|
||||
.prevUrl(PageUrlUtils.prevPageUrl(path))
|
||||
.build()
|
||||
);
|
||||
.map(list -> {
|
||||
// --- 修改:生成链接时带上查询参数 ---
|
||||
String baseNextUrl = PageUrlUtils.nextPageUrl(path, totalPage(list));
|
||||
String basePrevUrl = PageUrlUtils.prevPageUrl(path);
|
||||
|
||||
String nextUrl = appendQueryString(baseNextUrl, finalQueryString);
|
||||
String prevUrl = appendQueryString(basePrevUrl, finalQueryString);
|
||||
|
||||
return new UrlContextListResult.Builder<FriendPostVo>()
|
||||
.listResult(list)
|
||||
.nextUrl(nextUrl)
|
||||
.prevUrl(prevUrl)
|
||||
.build();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// --- 新增:辅助方法,用于拼接查询参数 ---
|
||||
private String appendQueryString(String url, String queryString) {
|
||||
if (StringUtils.isBlank(queryString)) {
|
||||
return url;
|
||||
}
|
||||
if (url.contains("?")) {
|
||||
return url + "&" + queryString;
|
||||
} else {
|
||||
return url + "?" + queryString;
|
||||
}
|
||||
}
|
||||
|
||||
private int pageNumInPathVariable(ServerRequest request) {
|
||||
String page = request.pathVariables().get("page");
|
||||
|
||||
Reference in New Issue
Block a user