Search in sources :

Example 1 with StudylogLikeResponse

use of wooteco.prolog.studylog.application.dto.StudylogLikeResponse in project prolog by woowacourse.

the class StudylogLikeService method unlikeStudylog.

@Transactional
public StudylogLikeResponse unlikeStudylog(Long memberId, Long studylogId, boolean isMember) {
    validIfMember(isMember);
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    Member member = memberService.findById(memberId);
    studylog.unlike(member.getId());
    return new StudylogLikeResponse(false, studylog.getLikeCount());
}
Also used : StudylogLikeResponse(wooteco.prolog.studylog.application.dto.StudylogLikeResponse) StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with StudylogLikeResponse

use of wooteco.prolog.studylog.application.dto.StudylogLikeResponse in project prolog by woowacourse.

the class StudylogLikeService method likeStudylog.

@Transactional
public StudylogLikeResponse likeStudylog(Long memberId, Long studylogId, boolean isMember) {
    validIfMember(isMember);
    Studylog studylog = studylogRepository.findById(studylogId).orElseThrow(StudylogNotFoundException::new);
    Member member = memberService.findById(memberId);
    studylog.like(member.getId());
    return new StudylogLikeResponse(true, studylog.getLikeCount());
}
Also used : StudylogLikeResponse(wooteco.prolog.studylog.application.dto.StudylogLikeResponse) StudylogNotFoundException(wooteco.prolog.studylog.exception.StudylogNotFoundException) Member(wooteco.prolog.member.domain.Member) Studylog(wooteco.prolog.studylog.domain.Studylog) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with StudylogLikeResponse

use of wooteco.prolog.studylog.application.dto.StudylogLikeResponse in project prolog by woowacourse.

the class StudylogLikeServiceTest method unlike_loginMember_Success.

@DisplayName("로그인한 사용자가 스터디로그를 좋아요 취소 한다 - 성공")
@Test
void unlike_loginMember_Success() {
    // given
    Long memberId = member.getId();
    Long studylogId = this.studylog.getId();
    boolean isMember = true;
    studylogLikeService.likeStudylog(memberId, studylogId, isMember);
    // when
    StudylogLikeResponse studylogLikeResponse = studylogLikeService.unlikeStudylog(memberId, studylogId, isMember);
    // then
    assertThat(studylogLikeResponse.isLiked()).isFalse();
    assertThat(studylogLikeResponse.getLikesCount()).isZero();
}
Also used : StudylogLikeResponse(wooteco.prolog.studylog.application.dto.StudylogLikeResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with StudylogLikeResponse

use of wooteco.prolog.studylog.application.dto.StudylogLikeResponse in project prolog by woowacourse.

the class StudylogLikeServiceTest method like_loginMember_Success.

@DisplayName("로그인한 사용자가 스터디로그를 좋아요 한다 - 성공")
@Test
void like_loginMember_Success() {
    // given
    Long memberId = member.getId();
    Long studylogId = this.studylog.getId();
    boolean isMember = true;
    // when
    StudylogLikeResponse studylogLikeResponse = studylogLikeService.likeStudylog(memberId, studylogId, isMember);
    // then
    assertThat(studylogLikeResponse.isLiked()).isTrue();
    assertThat(studylogLikeResponse.getLikesCount()).isOne();
}
Also used : StudylogLikeResponse(wooteco.prolog.studylog.application.dto.StudylogLikeResponse) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

StudylogLikeResponse (wooteco.prolog.studylog.application.dto.StudylogLikeResponse)4 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Member (wooteco.prolog.member.domain.Member)2 Studylog (wooteco.prolog.studylog.domain.Studylog)2 StudylogNotFoundException (wooteco.prolog.studylog.exception.StudylogNotFoundException)2 IntegrationTest (wooteco.support.utils.IntegrationTest)2