Search in sources :

Example 1 with StudylogDocument

use of wooteco.prolog.studylog.domain.StudylogDocument in project prolog by woowacourse.

the class StudylogDocumentService method findBySearchKeyword.

@Override
public StudylogDocumentResponse findBySearchKeyword(String keyword, List<Long> tags, List<Long> missions, List<Long> levels, List<String> usernames, LocalDate start, LocalDate end, Pageable pageable) {
    final Query query = StudylogDocumentQueryBuilder.makeQuery(preprocess(keyword), tags, missions, levels, usernames, start, end, pageable);
    // Query 결과를 ES에서 조회한다.
    final SearchHits<StudylogDocument> searchHits = elasticsearchRestTemplate.search(query, StudylogDocument.class, IndexCoordinates.of("studylog-document"));
    // 조회된 SearchHits를 페이징할 수 있는 SearchPage로 변경한다.
    final SearchPage<StudylogDocument> searchPages = SearchHitSupport.searchPageFor(searchHits, query.getPageable());
    final List<Long> studylogIds = searchPages.stream().map(searchPage -> searchPage.getContent().getId()).collect(toList());
    return StudylogDocumentResponse.of(studylogIds, searchPages.getTotalElements(), searchPages.getTotalPages(), searchPages.getNumber());
}
Also used : IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates) SearchHits(org.springframework.data.elasticsearch.core.SearchHits) Query(org.springframework.data.elasticsearch.core.query.Query) SearchPage(org.springframework.data.elasticsearch.core.SearchPage) Profile(org.springframework.context.annotation.Profile) StudylogDocumentRepository(wooteco.prolog.studylog.domain.repository.StudylogDocumentRepository) StudylogDocumentResponse(wooteco.prolog.studylog.application.dto.StudylogDocumentResponse) ElasticsearchRestTemplate(org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate) SearchHitSupport(org.springframework.data.elasticsearch.core.SearchHitSupport) StudylogDocumentQueryBuilder(wooteco.prolog.studylog.domain.StudylogDocumentQueryBuilder) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) StudylogDocument(wooteco.prolog.studylog.domain.StudylogDocument) Pageable(org.springframework.data.domain.Pageable) StudylogRepository(wooteco.prolog.studylog.domain.repository.StudylogRepository) Query(org.springframework.data.elasticsearch.core.query.Query) StudylogDocument(wooteco.prolog.studylog.domain.StudylogDocument)

Example 2 with StudylogDocument

use of wooteco.prolog.studylog.domain.StudylogDocument in project prolog by woowacourse.

the class FakeStudylogDocumentRepository method saveAll.

@Override
public <S extends StudylogDocument> Iterable<S> saveAll(Iterable<S> inputStudylogDocuments) {
    List<StudylogDocument> studylogDocumentsWithId = new ArrayList<>();
    for (StudylogDocument studylogDocument : inputStudylogDocuments) {
        STUDYLOG_DOCUMENTS.add(studylogDocument);
        STUDYLOG_DOCUMENTS.add(studylogDocument);
    }
    return (Iterable<S>) studylogDocumentsWithId;
}
Also used : ArrayList(java.util.ArrayList) StudylogDocument(wooteco.prolog.studylog.domain.StudylogDocument)

Example 3 with StudylogDocument

use of wooteco.prolog.studylog.domain.StudylogDocument 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)

Example 4 with StudylogDocument

use of wooteco.prolog.studylog.domain.StudylogDocument in project prolog by woowacourse.

the class StudylogServiceTest method update.

@DisplayName("스터디로그를 수정한다 - 수정 시 studylogDocument도 수정된다.")
@Test
void update() {
    // given
    List<StudylogResponse> studylogResponses = insertStudylogs(member1, studylog1);
    Long id = studylogResponses.get(0).getId();
    StudylogRequest updateStudylogRequest = new StudylogRequest("updateTitle", "updateContent", 2L, toTagRequests(tags));
    studylogService.updateStudylog(member1.getId(), id, updateStudylogRequest);
    // when
    StudylogDocument studylogDocument = studylogDocumentService.findById(id);
    // then
    assertAll(() -> assertThat(studylogDocument.getId()).isEqualTo(id), () -> assertThat(studylogDocument.getTitle()).isEqualTo(updateStudylogRequest.getTitle()), () -> assertThat(studylogDocument.getContent()).isEqualTo(updateStudylogRequest.getContent()));
}
Also used : StudylogResponse(wooteco.prolog.studylog.application.dto.StudylogResponse) CalendarStudylogResponse(wooteco.prolog.studylog.application.dto.CalendarStudylogResponse) StudylogDocument(wooteco.prolog.studylog.domain.StudylogDocument) StudylogRequest(wooteco.prolog.studylog.application.dto.StudylogRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

StudylogDocument (wooteco.prolog.studylog.domain.StudylogDocument)4 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 CalendarStudylogResponse (wooteco.prolog.studylog.application.dto.CalendarStudylogResponse)2 StudylogResponse (wooteco.prolog.studylog.application.dto.StudylogResponse)2 IntegrationTest (wooteco.support.utils.IntegrationTest)2 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 Profile (org.springframework.context.annotation.Profile)1 Pageable (org.springframework.data.domain.Pageable)1 ElasticsearchRestTemplate (org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate)1 SearchHitSupport (org.springframework.data.elasticsearch.core.SearchHitSupport)1 SearchHits (org.springframework.data.elasticsearch.core.SearchHits)1 SearchPage (org.springframework.data.elasticsearch.core.SearchPage)1 IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)1 Query (org.springframework.data.elasticsearch.core.query.Query)1 Service (org.springframework.stereotype.Service)1