Search in sources :

Example 1 with Session

use of wooteco.prolog.session.domain.Session in project prolog by woowacourse.

the class StudylogService method updateStudylog.

@Transactional
public void updateStudylog(Long memberId, Long studylogId, StudylogRequest studylogRequest) {
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    studylog.validateBelongTo(memberId);
    Session session = sessionService.findSessionById(studylogRequest.getSessionId()).orElse(null);
    Mission mission = missionService.findMissionById(studylogRequest.getMissionId()).orElse(null);
    final Member foundMember = memberService.findById(memberId);
    final Tags originalTags = tagService.findByStudylogsAndMember(studylog, foundMember);
    Tags newTags = tagService.findOrCreate(studylogRequest.getTags());
    studylog.update(studylogRequest.getTitle(), studylogRequest.getContent(), session, mission, newTags);
    memberTagService.updateMemberTag(originalTags, newTags, foundMember);
    studylogDocumentService.update(studylog.toStudylogDocument());
}
Also used : StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Mission(wooteco.prolog.session.domain.Mission) LoginMember(wooteco.prolog.login.ui.LoginMember) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Tags(wooteco.prolog.studylog.domain.Tags) Session(wooteco.prolog.session.domain.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Session

use of wooteco.prolog.session.domain.Session in project prolog by woowacourse.

the class StudylogTest method getPopularScore.

@DisplayName("좋아요와 조회를 기준으로 인기점수를 반환한다.")
@Test
void getPopularScore() {
    // given
    Member member = new Member("최현구", "현구막", Role.CREW, 1L, "image");
    Session session = new Session("세션 1");
    Mission mission = new Mission("자동차 미션", session);
    Tag tag1 = new Tag("Java");
    Tag tag2 = new Tag("Spring");
    Studylog studylog = new Studylog(member, "제목", "내용", mission, Arrays.asList(tag1, tag2));
    // when, then
    assertThat(studylog.getPopularScore()).isEqualTo(0);
    studylog.increaseViewCount();
    assertThat(studylog.getPopularScore()).isEqualTo(1);
    studylog.like(1L);
    assertThat(studylog.getPopularScore()).isEqualTo(3 + 1);
}
Also used : Mission(wooteco.prolog.session.domain.Mission) Member(wooteco.prolog.member.domain.Member) Session(wooteco.prolog.session.domain.Session) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Session

use of wooteco.prolog.session.domain.Session in project prolog by woowacourse.

the class StudylogScrapRepositoryTest method setUp.

@BeforeEach
void setUp() {
    member = memberRepository.save(웨지);
    Session session = sessionRepository.save(new Session("세션1"));
    Mission mission = missionRepository.save(new Mission("미션", session));
    studylog = studylogRepository.save(new Studylog(member, "제목", "내용", mission, Lists.emptyList()));
}
Also used : Mission(wooteco.prolog.session.domain.Mission) Studylog(wooteco.prolog.studylog.domain.Studylog) Session(wooteco.prolog.session.domain.Session) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Session

use of wooteco.prolog.session.domain.Session in project prolog by woowacourse.

the class StudylogTagRepositoryTest method findByTagIn.

@DisplayName("Tag 리스트와 매칭되는 StudylogTag 리스트 조회")
@Test
void findByTagIn() {
    // given
    Member member = memberRepository.save(웨지);
    Session session = sessionRepository.save(new Session("세션1"));
    Mission mission = missionRepository.save(new Mission("미션", session));
    Studylog studylog1 = studylogRepository.save(new Studylog(member, "제목1", "내용1", mission, Lists.emptyList()));
    Studylog studylog2 = studylogRepository.save(new Studylog(member, "제목2", "내용2", mission, Lists.emptyList()));
    Tag tag1 = tagRepository.save(new Tag("태그1"));
    Tag tag2 = tagRepository.save(new Tag("태그2"));
    StudylogTag studylogTag1 = studylogTagRepository.save(new StudylogTag(studylog1, tag1));
    StudylogTag studylogTag2 = studylogTagRepository.save(new StudylogTag(studylog1, tag2));
    StudylogTag studylogTag3 = studylogTagRepository.save(new StudylogTag(studylog2, tag2));
    // when
    List<StudylogTag> studylogTags = studylogTagRepository.findByTagIn(Arrays.asList(tag1, tag2));
    // then
    assertThat(studylogTags).usingFieldByFieldElementComparator().containsExactlyInAnyOrder(studylogTag1, studylogTag2, studylogTag3);
}
Also used : Mission(wooteco.prolog.session.domain.Mission) Tag(wooteco.prolog.studylog.domain.Tag) StudylogTag(wooteco.prolog.studylog.domain.StudylogTag) StudylogTag(wooteco.prolog.studylog.domain.StudylogTag) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Session(wooteco.prolog.session.domain.Session) Test(org.junit.jupiter.api.Test) RepositoryTest(wooteco.support.utils.RepositoryTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Session

use of wooteco.prolog.session.domain.Session in project prolog by woowacourse.

the class StudylogService method updateStudylogSession.

@Transactional
public void updateStudylogSession(Long memberId, Long studylogId, StudylogSessionRequest studylogSessionRequest) {
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    studylog.validateBelongTo(memberId);
    Session session = sessionService.findSessionById(studylogSessionRequest.getSessionId()).orElse(null);
    studylog.updateSession(session);
}
Also used : StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Studylog(wooteco.prolog.studylog.domain.Studylog) Session(wooteco.prolog.session.domain.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Session (wooteco.prolog.session.domain.Session)15 Mission (wooteco.prolog.session.domain.Mission)12 Studylog (wooteco.prolog.studylog.domain.Studylog)11 Member (wooteco.prolog.member.domain.Member)7 BeforeEach (org.junit.jupiter.api.BeforeEach)5 DisplayName (org.junit.jupiter.api.DisplayName)5 Test (org.junit.jupiter.api.Test)5 Transactional (org.springframework.transaction.annotation.Transactional)5 LoginMember (wooteco.prolog.login.ui.LoginMember)4 StudylogTag (wooteco.prolog.studylog.domain.StudylogTag)4 Tag (wooteco.prolog.studylog.domain.Tag)4 RepositoryTest (wooteco.support.utils.RepositoryTest)4 SessionRequest (wooteco.prolog.session.application.dto.SessionRequest)3 SessionResponse (wooteco.prolog.session.application.dto.SessionResponse)3 GithubProfileResponse (wooteco.prolog.login.application.dto.GithubProfileResponse)2 MissionRequest (wooteco.prolog.session.application.dto.MissionRequest)2 MissionResponse (wooteco.prolog.session.application.dto.MissionResponse)2 Tags (wooteco.prolog.studylog.domain.Tags)2 StudylogNotFoundException (wooteco.prolog.studylog.exception.StudylogNotFoundException)2