refactor(app): 观看历史统一分页契约并移除 limit
This commit is contained in:
1 parent
7b694938c6
commit
c5468a669b
5 files changed
+19
-34
No files matched your search
+5
-10
@@ -44,19 +44,14 @@ public class AppWatchController {
|
||||
return Result.ok(progressService.ofDrama(SecurityUtils.getAppUserId(), dramaId));
|
||||
}
|
||||
|
||||
@Operation(summary = "最近观看列表")
|
||||
/** 最近观看分页,契约与 /app/favorites 一致:pageIndex/pageSize。 */
|
||||
@Operation(summary = "最近观看分页")
|
||||
@GetMapping("/recent")
|
||||
public Result<?> recent(
|
||||
@RequestParam(required = false) Integer limit,
|
||||
public Result<PageResult<ProgressRespVO>> recent(
|
||||
@RequestParam(defaultValue = "1") int pageIndex,
|
||||
@RequestParam(defaultValue = "20") int pageSize) {
|
||||
Long userId = SecurityUtils.getAppUserId();
|
||||
if (limit != null) {
|
||||
return Result.ok(progressService.recent(userId, limit));
|
||||
}
|
||||
PageResult<ProgressRespVO> page = progressService.recentPage(
|
||||
userId, pageIndex, pageSize);
|
||||
return Result.ok(page);
|
||||
return Result.ok(progressService.recentPage(
|
||||
SecurityUtils.getAppUserId(), pageIndex, pageSize));
|
||||
}
|
||||
|
||||
@Operation(summary = "删除某部剧的观看记录")
|
||||
|
||||
+9
-7
@@ -138,17 +138,19 @@ class AppLibraryPagingContractTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_legacy_list_when_recent_limit_is_present() throws Exception {
|
||||
given(progressService.recent(USER_ID, 5))
|
||||
.willReturn(List.of(progress(12L, 88L, 6, "剧名一", 68)));
|
||||
void should_ignore_removed_limit_and_still_return_page_result() throws Exception {
|
||||
// limit 已从契约移除:即使客户端误传,也应走分页并返回 PageResult。
|
||||
given(progressService.recentPage(USER_ID, 1, 20))
|
||||
.willReturn(new PageResult<>(3L, List.of(progress(12L, 88L, 6, "剧名一", 68))));
|
||||
|
||||
watchMvc.perform(get("/app/watch/recent").param("limit", "5"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").isArray())
|
||||
.andExpect(jsonPath("$.data[0].dramaTitle").value("剧名一"))
|
||||
.andExpect(jsonPath("$.data[0].episodeNumber").value(6));
|
||||
.andExpect(jsonPath("$.data.total").value("3"))
|
||||
.andExpect(jsonPath("$.data.list").isArray())
|
||||
.andExpect(jsonPath("$.data.list.length()").value(1))
|
||||
.andExpect(jsonPath("$.data.list[0].dramaTitle").value("剧名一"));
|
||||
|
||||
verify(progressService).recent(USER_ID, 5);
|
||||
verify(progressService).recentPage(USER_ID, 1, 20);
|
||||
}
|
||||
|
||||
private Drama drama(Long id, String title) {
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ class WatchProgressServiceTest {
|
||||
assertThat(pageCaptor.getValue().getSize()).isEqualTo(20);
|
||||
assertThat(wrapperCaptor.getValue().getSqlSegment())
|
||||
.contains("updated_at DESC")
|
||||
.contains("drama_id DESC");
|
||||
.contains("id DESC");
|
||||
verify(dramaService, times(1)).listByIds(List.of(12L, 13L));
|
||||
verify(episodeService, times(1)).listByIds(List.of(88L, 99L));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user