Skip to content

Commit

Permalink
feat: scoreDesc endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao committed Dec 10, 2024
1 parent 694a615 commit e70cc16
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class FindSubjectCondition {
* default is false.
*/
private Boolean updateTimeDesc;
/**
* default is null.
*/
private Boolean scoreDesc;

/**
* init default if field value is null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public RouterFunction<ServerResponse> endpoint() {
.name("updateTimeDesc")
.implementation(Boolean.class)
.description("是否根据更新时间倒序,默认为 true."))
.parameter(parameterBuilder()
.name("scoreDesc")
.implementation(Boolean.class)
.description("是否根据评分倒序,默认为空."))
.response(responseBuilder().implementation(PagingWrap.class))
)

Expand Down Expand Up @@ -188,12 +192,20 @@ private Mono<ServerResponse> listByCondition(ServerRequest request) {
boolean updateTimeDesc =
Boolean.parseBoolean(request.queryParam("updateTimeDesc")
.orElse(Boolean.FALSE.toString()));
Optional<String> scoreDescOp = request.queryParam("scoreDesc");
Boolean scoreDesc = null;

Check warning on line 196 in server/src/main/java/run/ikaros/server/core/subject/endpoint/SubjectEndpoint.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/run/ikaros/server/core/subject/endpoint/SubjectEndpoint.java#L195-L196

Added lines #L195 - L196 were not covered by tests
if (scoreDescOp.isPresent() && !scoreDescOp.get().isEmpty()) {
scoreDesc =
Boolean.parseBoolean(scoreDescOp.get());

Check warning on line 199 in server/src/main/java/run/ikaros/server/core/subject/endpoint/SubjectEndpoint.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/run/ikaros/server/core/subject/endpoint/SubjectEndpoint.java#L198-L199

Added lines #L198 - L199 were not covered by tests
}

FindSubjectCondition findSubjectCondition = FindSubjectCondition.builder()
.page(page).size(size).name(name).nameCn(nameCn)
.nsfw(nsfw).type(type).time(time)
.airTimeDesc(airTimeDesc)
.updateTimeDesc(updateTimeDesc).build();
.updateTimeDesc(updateTimeDesc)
.scoreDesc(scoreDesc)
.build();

Check warning on line 208 in server/src/main/java/run/ikaros/server/core/subject/endpoint/SubjectEndpoint.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/run/ikaros/server/core/subject/endpoint/SubjectEndpoint.java#L206-L208

Added lines #L206 - L208 were not covered by tests
return subjectService.listEntitiesByCondition(findSubjectCondition)
.flatMap(pagingWrap -> ServerResponse.ok().bodyValue(pagingWrap));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public Mono<PagingWrap<Subject>> listEntitiesByCondition(FindSubjectCondition co
final String time = condition.getTime();
final Boolean airTimeDesc = condition.getAirTimeDesc();
final Boolean updateTimeDesc = condition.getUpdateTimeDesc();
final Boolean scoreDesc = condition.getScoreDesc();

Check warning on line 294 in server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/run/ikaros/server/core/subject/service/impl/SubjectServiceImpl.java#L294

Added line #L294 was not covered by tests

final PageRequest pageRequest = PageRequest.of(page - 1, size);

Expand Down Expand Up @@ -359,6 +360,14 @@ public Mono<PagingWrap<Subject>> listEntitiesByCondition(FindSubjectCondition co
query = query.sort(Sort.by(Sort.Order.desc("update_time").nullsLast()));
}

// todo 目前无这个字段,评分需要根据所有用户的条目收藏进行综合计算
// if (Objects.nonNull(scoreDesc)) {
// query = query.sort(
// scoreDesc ? Sort.by(Sort.Order.desc("score").nullsLast())
// : Sort.by(Sort.Order.asc("score").nullsLast())
// );
// }

query = query
.sort(Sort.by(airTimeDesc ? Sort.Order.desc("air_time").nullsLast()
: Sort.Order.asc("air_time").nullsLast()))
Expand Down

0 comments on commit e70cc16

Please sign in to comment.