Search in sources :

Example 1 with Mission

use of wooteco.prolog.session.domain.Mission 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 Mission

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

the class StudylogService method insertStudylogTemp.

@Transactional
public StudylogTempResponse insertStudylogTemp(Long memberId, StudylogRequest studylogRequest) {
    Member member = memberService.findById(memberId);
    Tags tags = tagService.findOrCreate(studylogRequest.getTags());
    Mission mission = missionService.findById(studylogRequest.getMissionId());
    StudylogTemp requestedStudylogTemp = new StudylogTemp(member, studylogRequest.getTitle(), studylogRequest.getContent(), mission, tags.getList());
    deleteStudylogTemp(memberId);
    StudylogTemp createdStudylogTemp = studylogTempRepository.save(requestedStudylogTemp);
    return StudylogTempResponse.from(createdStudylogTemp);
}
Also used : Mission(wooteco.prolog.session.domain.Mission) LoginMember(wooteco.prolog.login.ui.LoginMember) Member(wooteco.prolog.member.domain.Member) Tags(wooteco.prolog.studylog.domain.Tags) StudylogTemp(wooteco.prolog.studylog.domain.StudylogTemp) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Mission

use of wooteco.prolog.session.domain.Mission 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 4 with Mission

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

the class MissionServiceTest method findByIdTest.

@DisplayName("ID를 통해서 Mission을 조회한다.")
@Test
void findByIdTest() {
    // given
    MissionRequest request = new MissionRequest("세션1 - 자동차 경주 미션", session1.getId());
    MissionResponse savedMission = missionService.create(request);
    // when
    Mission foundMission = missionService.findById(savedMission.getId());
    // then
    assertThat(foundMission).usingRecursiveComparison().isEqualTo(savedMission);
}
Also used : MissionRequest(wooteco.prolog.session.application.dto.MissionRequest) MissionResponse(wooteco.prolog.session.application.dto.MissionResponse) Mission(wooteco.prolog.session.domain.Mission) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Mission

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

the class MissionRepositoryTest method findByName.

@DisplayName("name으로 Mission 검색 - 성공")
@Test
void findByName() {
    // given
    String name = "[BE] 자동차 미션";
    Mission mission = missionRepository.save(new Mission(name, session));
    // when
    Optional<Mission> foundMission = missionRepository.findByName(name);
    // then
    assertThat(foundMission).isPresent();
    assertThat(foundMission.get()).usingRecursiveComparison().isEqualTo(mission);
}
Also used : Mission(wooteco.prolog.session.domain.Mission) Test(org.junit.jupiter.api.Test) RepositoryTest(wooteco.support.utils.RepositoryTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

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