use of wooteco.prolog.studylog.application.dto.StudylogResponse 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.StudylogResponse 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.StudylogResponse in project prolog by woowacourse.
the class ReportStudylogResponse method of.
public static ReportStudylogResponse of(Studylog studylog, List<ReportStudylog> reportStudylogs) {
StudylogResponse studylogResponse = StudylogResponse.of(studylog);
List<ReportAbilityResponse> abilityResponses = reportStudylogs.stream().map(it -> ReportAbilityResponse.of(it.getReportAbility())).collect(Collectors.toList());
List<ReportStudylogAbilityResponse> studylogAbilityResponses = reportStudylogs.stream().map(it -> ReportStudylogAbilityResponse.of(it.getStudylogAbility())).collect(Collectors.toList());
return new ReportStudylogResponse(studylogResponse, abilityResponses, studylogAbilityResponses);
}
use of wooteco.prolog.studylog.application.dto.StudylogResponse 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.StudylogResponse in project prolog by woowacourse.
the class StudylogServiceTest method insert.
@DisplayName("스터디로그를 삽입한다. - 삽입 시 studylogDocument도 삽입된다.")
@Test
void insert() {
// given
List<StudylogResponse> studylogResponses = insertStudylogs(member1, studylog1);
Long id = studylogResponses.get(0).getId();
// when
StudylogDocument studylogDocument = studylogDocumentService.findById(id);
// then
assertAll(() -> assertThat(studylogDocument.getId()).isEqualTo(id), () -> assertThat(studylogDocument.getTitle()).isEqualTo(studylog1.getTitle()), () -> assertThat(studylogDocument.getContent()).isEqualTo(studylog1.getContent()));
}
Aggregations