use of wooteco.prolog.studylog.application.dto.StudylogsResponse in project prolog by woowacourse.
the class StudylogServiceTest method findMostPopularStudylogsWithLogin.
@DisplayName("로그인한 상태에서 일주일을 기준으로 제시된 개수만큼 인기있는 스터디로그를 조회한다.")
@Test
void findMostPopularStudylogsWithLogin() {
// given
List<StudylogResponse> insertResponses = insertStudylogs(member1, studylog1, studylog2, studylog3);
StudylogResponse studylogResponse2 = insertResponses.get(1);
StudylogResponse studylogResponse3 = insertResponses.get(2);
// 2번째 멤버가 1번째 멤버의 게시글 2번, 3번을 조회
studylogService.findById(studylogResponse2.getId(), member2.getId(), false);
studylogService.findById(studylogResponse3.getId(), member2.getId(), false);
// 2번, 3번 글 스크랩
studylogScrapService.registerScrap(member2.getId(), studylogResponse2.getId());
studylogScrapService.registerScrap(member2.getId(), studylogResponse3.getId());
// 3번 글 좋아요
studylogLikeService.likeStudylog(member2.getId(), studylogResponse3.getId(), true);
// when
PageRequest pageRequest = PageRequest.of(0, 2);
StudylogsResponse popularStudylogs = studylogService.findMostPopularStudylogs(pageRequest, member2.getId(), member2.isAnonymous());
// then
assertThat(popularStudylogs.getTotalSize()).isEqualTo(2);
assertThat(popularStudylogs.getData().get(0).getId()).isEqualTo(studylogResponse3.getId());
assertThat(popularStudylogs.getData().get(1).getId()).isEqualTo(studylogResponse2.getId());
for (StudylogResponse studylogResponse : popularStudylogs.getData()) {
assertThat(studylogResponse.isScrap()).isTrue();
assertThat(studylogResponse.isRead()).isTrue();
}
}
use of wooteco.prolog.studylog.application.dto.StudylogsResponse in project prolog by woowacourse.
the class StudylogDocumentation method 인기있는_스터디로그_목록을_조회한다.
@Test
void 인기있는_스터디로그_목록을_조회한다() {
// given
String studylogLocation1 = 스터디로그_등록함(Collections.singletonList(createStudylogRequest1())).header("Location");
String studylogLocation2 = 스터디로그_등록함(Collections.singletonList(createStudylogRequest2())).header("Location");
Long studylogId1 = Long.parseLong(studylogLocation1.split("/studylogs/")[1]);
Long studylogId2 = Long.parseLong(studylogLocation2.split("/studylogs/")[1]);
스터디로그_단건_조회(studylogId1);
스터디로그_단건_조회(studylogId2);
스터디로그_단건_좋아요(studylogId2);
// when
ExtractableResponse<Response> response = given("studylogs/most-popular").header("Authorization", "Bearer " + 로그인_사용자.getAccessToken()).when().get("/studylogs/most-popular").then().log().all().extract();
// then
// given
StudylogsResponse mostPopularStudylogsResponse = response.as(StudylogsResponse.class);
assertThat(mostPopularStudylogsResponse.getData()).hasSize(2);
assertThat(mostPopularStudylogsResponse.getData().get(0).getId()).isEqualTo(studylogId2);
assertThat(mostPopularStudylogsResponse.getData().get(1).getId()).isEqualTo(studylogId1);
}
use of wooteco.prolog.studylog.application.dto.StudylogsResponse in project prolog by woowacourse.
the class StudylogService method findMostPopularStudylogs.
public StudylogsResponse findMostPopularStudylogs(Pageable pageable, Long memberId, boolean isAnonymousMember) {
List<Studylog> studylogs = findStudylogsByDays(pageable, LocalDateTime.now());
PageImpl<Studylog> page = new PageImpl<>(studylogs, pageable, studylogs.size());
StudylogsResponse studylogsResponse = StudylogsResponse.of(page, memberId);
if (isAnonymousMember) {
return studylogsResponse;
}
List<StudylogResponse> data = studylogsResponse.getData();
updateScrap(data, findScrapIds(memberId));
updateRead(data, findReadIds(memberId));
return studylogsResponse;
}
use of wooteco.prolog.studylog.application.dto.StudylogsResponse in project prolog by woowacourse.
the class PopularStudylogServiceTest method findPopularStudylogsWithLogin.
@DisplayName("로그인한 상태에서 제시된 개수만큼 인기있는 스터디로그를 조회한다.")
@Test
void findPopularStudylogsWithLogin() {
// given
List<StudylogResponse> insertResponses = insertStudylogs(member1, studylog1, studylog2, studylog3);
StudylogResponse studylogResponse2 = insertResponses.get(1);
StudylogResponse studylogResponse3 = insertResponses.get(2);
// 2번째 멤버가 1번째 멤버의 게시글 2번, 3번을 조회
studylogService.retrieveStudylogById(loginMember2, studylogResponse2.getId());
studylogService.retrieveStudylogById(loginMember2, studylogResponse3.getId());
// 2번, 3번 글 스크랩
studylogScrapService.registerScrap(member2.getId(), studylogResponse2.getId());
studylogScrapService.registerScrap(member2.getId(), studylogResponse3.getId());
// 3번 글 좋아요
studylogLikeService.likeStudylog(member2.getId(), studylogResponse3.getId(), true);
// when
PageRequest pageRequest = PageRequest.of(0, 2);
popularStudylogService.updatePopularStudylogs(pageRequest);
StudylogsResponse popularStudylogs = popularStudylogService.findPopularStudylogs(pageRequest, member2.getId(), member2.isAnonymous());
// then
assertThat(popularStudylogs.getTotalSize()).isEqualTo(2);
assertThat(popularStudylogs.getData().get(0).getId()).isEqualTo(studylogResponse3.getId());
assertThat(popularStudylogs.getData().get(1).getId()).isEqualTo(studylogResponse2.getId());
for (StudylogResponse studylogResponse : popularStudylogs.getData()) {
assertThat(studylogResponse.isScrap()).isTrue();
assertThat(studylogResponse.isRead()).isTrue();
}
}
use of wooteco.prolog.studylog.application.dto.StudylogsResponse in project prolog by woowacourse.
the class StudylogServiceTest method findWithFilter.
@DisplayName("검색 및 필터")
@ParameterizedTest
@MethodSource("findWithFilter")
void findWithFilter(String keyword, List<Long> sessionIds, List<Long> missionIds, List<Long> tagIds, List<String> usernames, List<String> expectedStudylogTitles) {
// given
insertStudylogs(member1, studylog1, studylog2);
insertStudylogs(member2, studylog3, studylog4);
// document 초기화 어떻게...
StudylogsResponse studylogsResponse = studylogService.findStudylogs(new StudylogsSearchRequest(keyword, sessionIds, missionIds, tagIds, usernames, new ArrayList<>(), LocalDate.parse("19990106", DateTimeFormatter.BASIC_ISO_DATE), LocalDate.parse("99991231", DateTimeFormatter.BASIC_ISO_DATE), null, PageRequest.of(0, 10)), null);
// then
List<String> titles = studylogsResponse.getData().stream().map(StudylogResponse::getTitle).collect(toList());
assertThat(titles).containsExactlyInAnyOrderElementsOf(expectedStudylogTitles);
}
Aggregations