feat(content): 列表卡片与后台返回收藏点赞评论数

This commit is contained in:
Zhou Weidong committed 2026-10-21 11:14:18 +08:00
1 parent f90336963b
commit 256821b824
13 files changed
+324 -50

No files matched your search

@@ -5,8 +5,10 @@ import com.fruitshorts.app.service.AppCatalogService;
import com.fruitshorts.app.support.ControllerContractSupport;
import com.fruitshorts.app.vo.AppBannerVO;
import com.fruitshorts.app.vo.AppCategoryVO;
import com.fruitshorts.app.vo.AppDramaCardVO;
import com.fruitshorts.app.vo.AppDramaDetailVO;
import com.fruitshorts.app.vo.AppFeedVO;
import com.fruitshorts.app.vo.AppSectionVO;
import com.fruitshorts.common.exception.ErrorCode;
import com.fruitshorts.common.exception.ServiceException;
import com.fruitshorts.playback.service.PlaybackService;
@@ -50,7 +52,15 @@ class AppCatalogControllerContractTest {
banner.setImageUrl("/files/banner/9.png");
banner.setLinkType("DRAMA");
banner.setLinkValue("12");
AppFeedVO feed = new AppFeedVO(List.of(banner), List.of());
AppDramaCardVO card = new AppDramaCardVO();
card.setId(12L);
card.setTitle("命运的相遇");
card.setViewCount(12400L);
card.setLikeCount(3200L);
card.setFavoriteCount(1800L);
card.setCommentCount(96L);
AppSectionVO section = new AppSectionVO("hot", "热门推荐", List.of(card));
AppFeedVO feed = new AppFeedVO(List.of(banner), List.of(section));
given(catalogService.homeFeed()).willReturn(feed);
catalogMvc.perform(get("/app/home/feed"))
@@ -58,7 +68,11 @@ class AppCatalogControllerContractTest {
.andExpect(jsonPath("$.code").value(0))
.andExpect(jsonPath("$.data.banners[0].id").value(9))
.andExpect(jsonPath("$.data.banners[0].imageUrl").value("/files/banner/9.png"))
.andExpect(jsonPath("$.data.banners[0].linkType").value("DRAMA"));
.andExpect(jsonPath("$.data.banners[0].linkType").value("DRAMA"))
.andExpect(jsonPath("$.data.sections[0].dramas[0].viewCount").value("12400"))
.andExpect(jsonPath("$.data.sections[0].dramas[0].likeCount").value("3200"))
.andExpect(jsonPath("$.data.sections[0].dramas[0].favoriteCount").value("1800"))
.andExpect(jsonPath("$.data.sections[0].dramas[0].commentCount").value("96"));
}
@Test
@@ -1,6 +1,7 @@
// Author: fruit.com.cn
package com.fruitshorts.app.service;
import com.fruitshorts.app.vo.AppDramaCardVO;
import com.fruitshorts.app.vo.AppDramaDetailVO;
import com.fruitshorts.content.dal.entity.Drama;
import com.fruitshorts.content.service.BannerService;
@@ -13,10 +14,13 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
@@ -63,4 +67,36 @@ class AppCatalogServiceTest {
assertThat(detail.getCommentCount()).isEqualTo(96L);
verify(commentService).countByDrama(42L);
}
@Test
void should_fill_card_counts_with_one_batch_comment_query() {
Drama first = new Drama();
first.setId(1L);
first.setTitle("第一部");
first.setViewCount(1200L);
first.setLikeCount(320L);
first.setFavoriteCount(180L);
Drama second = new Drama();
second.setId(2L);
second.setTitle("第二部");
second.setViewCount(800L);
second.setLikeCount(120L);
second.setFavoriteCount(80L);
given(episodeService.firstPlayableByDramas(List.of(1L, 2L))).willReturn(Map.of());
given(dramaCategoryService.listBasic()).willReturn(List.of());
given(commentService.countByDramas(List.of(1L, 2L)))
.willReturn(Map.of(1L, 9L));
List<AppDramaCardVO> cards = catalogService.toCards(List.of(first, second));
assertThat(cards).hasSize(2);
assertThat(cards.get(0).getLikeCount()).isEqualTo(320L);
assertThat(cards.get(0).getFavoriteCount()).isEqualTo(180L);
assertThat(cards.get(0).getCommentCount()).isEqualTo(9L);
assertThat(cards.get(1).getLikeCount()).isEqualTo(120L);
assertThat(cards.get(1).getFavoriteCount()).isEqualTo(80L);
assertThat(cards.get(1).getCommentCount()).isZero();
verify(commentService).countByDramas(List.of(1L, 2L));
verify(commentService, never()).countByDrama(any());
}
}
@@ -22,6 +22,10 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.apache.ibatis.builder.MapperBuilderAssistant;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
@@ -77,4 +81,32 @@ class CommentServiceCountTest {
assertThat(commentService.countByDrama(null)).isZero();
verify(commentMapper, never()).selectCount(any());
}
@Test
void should_return_empty_map_without_query_when_drama_ids_are_empty() {
assertThat(commentService.countByDramas(List.of())).isEmpty();
verify(commentMapper, never()).selectMaps(any());
}
@Test
void should_group_comment_counts_when_multiple_dramas_are_requested() {
ArgumentCaptor<Wrapper<ContentComment>> captor = ArgumentCaptor.forClass(Wrapper.class);
given(commentMapper.selectMaps(captor.capture())).willReturn(List.of(
Map.of("drama_id", 7L, "comment_count", 5L),
Map.of("drama_id", 8L, "comment_count", 2L)));
Map<Long, Long> counts = commentService.countByDramas(
Arrays.asList(7L, 8L, 8L, null));
assertThat(counts).containsEntry(7L, 5L).containsEntry(8L, 2L);
Wrapper<ContentComment> wrapper = captor.getValue();
assertThat(wrapper.getSqlSegment())
.contains("drama_id")
.contains("status")
.contains("deleted")
.contains("GROUP BY");
AbstractWrapper<ContentComment, ?, ?> lambda = (AbstractWrapper<ContentComment, ?, ?>) wrapper;
assertThat(lambda.getParamNameValuePairs().values())
.contains(7L, 8L, "deleted");
}
}