Search in sources :

Example 1 with StudylogResponse

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();
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) StudylogsResponse(wooteco.prolog.studylog.application.dto.StudylogsResponse) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) CalendarStudylogResponse(wooteco.prolog.studylog.application.dto.CalendarStudylogResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with StudylogResponse

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;
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) StudylogsResponse(wooteco.prolog.studylog.application.dto.StudylogsResponse) CalendarStudylogResponse(wooteco.prolog.studylog.application.dto.CalendarStudylogResponse) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse)

Example 3 with StudylogResponse

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);
}
Also used : List(java.util.List) ReportStudylog(wooteco.prolog.report.domain.ReportStudylog) Getter(lombok.Getter) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) Studylog(wooteco.prolog.studylog.domain.Studylog) AllArgsConstructor(lombok.AllArgsConstructor) Collectors(java.util.stream.Collectors) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse)

Example 4 with StudylogResponse

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();
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) StudylogsResponse(wooteco.prolog.studylog.application.dto.StudylogsResponse) StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with StudylogResponse

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()));
}
Also used : StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) CalendarStudylogResponse(wooteco.prolog.studylog.application.dto.CalendarStudylogResponse) StudylogDocument(wooteco.prolog.studylog.domain.StudylogDocument) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

StudylogResponse (wooteco.prolog.studylog.application.dto.StudylogResponse)39 DisplayName (org.junit.jupiter.api.DisplayName)14 Test (org.junit.jupiter.api.Test)14 StudylogsResponse (wooteco.prolog.studylog.application.dto.StudylogsResponse)14 Then (io.cucumber.java.en.Then)13 CalendarStudylogResponse (wooteco.prolog.studylog.application.dto.CalendarStudylogResponse)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 IntegrationTest (wooteco.support.utils.IntegrationTest)12 PageRequest (org.springframework.data.domain.PageRequest)5 Studylog (wooteco.prolog.studylog.domain.Studylog)5 When (io.cucumber.java.en.When)4 StudylogRequest (wooteco.prolog.studylog.application.dto.StudylogRequest)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MissionResponse (wooteco.prolog.session.application.dto.MissionResponse)3 SessionResponse (wooteco.prolog.session.application.dto.SessionResponse)3 StudylogDocument (wooteco.prolog.studylog.domain.StudylogDocument)3 ExtractableResponse (io.restassured.response.ExtractableResponse)2 Response (io.restassured.response.Response)2 Collectors (java.util.stream.Collectors)2