Search in sources :

Example 1 with StudylogsResponse

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();
    }
}
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 StudylogsResponse

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);
}
Also used : StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) MissionResponse(wooteco.prolog.studylog.application.dto.MissionResponse) LevelResponse(wooteco.prolog.studylog.application.dto.LevelResponse) ExtractableResponse(io.restassured.response.ExtractableResponse) Response(io.restassured.response.Response) StudylogsResponse(wooteco.prolog.studylog.application.dto.StudylogsResponse) StudylogsResponse(wooteco.prolog.studylog.application.dto.StudylogsResponse) Test(org.junit.jupiter.api.Test)

Example 3 with StudylogsResponse

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;
}
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 4 with 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();
    }
}
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 StudylogsResponse

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);
}
Also used : StudylogsResponse(wooteco.prolog.studylog.application.dto.StudylogsResponse) StudylogsSearchRequest(wooteco.prolog.studylog.application.dto.search.StudylogsSearchRequest) ArrayList(java.util.ArrayList) DisplayName(org.junit.jupiter.api.DisplayName) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

StudylogsResponse (wooteco.prolog.studylog.application.dto.StudylogsResponse)23 StudylogResponse (wooteco.prolog.studylog.application.dto.StudylogResponse)17 Test (org.junit.jupiter.api.Test)12 DisplayName (org.junit.jupiter.api.DisplayName)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 IntegrationTest (wooteco.support.utils.IntegrationTest)8 CalendarStudylogResponse (wooteco.prolog.studylog.application.dto.CalendarStudylogResponse)7 PageRequest (org.springframework.data.domain.PageRequest)6 Then (io.cucumber.java.en.Then)5 ArrayList (java.util.ArrayList)5 MissionResponse (wooteco.prolog.session.application.dto.MissionResponse)5 SessionResponse (wooteco.prolog.session.application.dto.SessionResponse)5 ExtractableResponse (io.restassured.response.ExtractableResponse)4 Response (io.restassured.response.Response)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 StudylogsSearchRequest (wooteco.prolog.studylog.application.dto.search.StudylogsSearchRequest)4 LocalDate (java.time.LocalDate)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyList (java.util.Collections.emptyList)2