diff --git a/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java b/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java index 6b057d97..4cdf5e97 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java @@ -3,6 +3,7 @@ import static com.jeju.nanaland.global.exception.SuccessCode.POST_LIKE_TOGGLE_SUCCESS; import com.jeju.nanaland.domain.experience.service.ExperienceService; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.global.BaseResponse; import com.jeju.nanaland.global.jwt.AuthMember; @@ -34,9 +35,12 @@ public class ExperienceController { @ApiResponse(responseCode = "500", description = "서버측 에러", content = @Content) }) @PostMapping("/like/{id}") - public BaseResponse toggleLikeStatus(@AuthMember MemberInfoDto memberInfoDto, + public BaseResponse toggleLikeStatus( + @AuthMember MemberInfoDto memberInfoDto, @PathVariable Long id) { - String result = experienceService.toggleLikeStatus(memberInfoDto.getMember(), id); - return BaseResponse.success(POST_LIKE_TOGGLE_SUCCESS, result); + + return BaseResponse.success( + POST_LIKE_TOGGLE_SUCCESS, + experienceService.toggleLikeStatus(memberInfoDto.getMember(), id)); } } diff --git a/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java b/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java index fe8d3091..8cba7710 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java @@ -2,6 +2,7 @@ import com.jeju.nanaland.domain.common.data.CategoryContent; import com.jeju.nanaland.domain.experience.repository.ExperienceRepository; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.service.FavoriteService; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.global.exception.BadRequestException; @@ -19,10 +20,13 @@ public class ExperienceService { private final FavoriteService favoriteService; @Transactional - public String toggleLikeStatus(Member member, Long postId) { + public FavoriteResponse.StatusDto toggleLikeStatus(Member member, Long postId) { experienceRepository.findById(postId) .orElseThrow(() -> new BadRequestException("해당 id의 이색체험 게시물이 존재하지 않습니다.")); - return favoriteService.toggleLikeStatus(member, CategoryContent.EXPERIENCE, postId); + Boolean status = favoriteService.toggleLikeStatus(member, CategoryContent.EXPERIENCE, postId); + return FavoriteResponse.StatusDto.builder() + .isFavorite(status) + .build(); } } diff --git a/src/main/java/com/jeju/nanaland/domain/favorite/dto/FavoriteResponse.java b/src/main/java/com/jeju/nanaland/domain/favorite/dto/FavoriteResponse.java new file mode 100644 index 00000000..15303658 --- /dev/null +++ b/src/main/java/com/jeju/nanaland/domain/favorite/dto/FavoriteResponse.java @@ -0,0 +1,16 @@ +package com.jeju.nanaland.domain.favorite.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Data; + +public class FavoriteResponse { + + @Data + @Builder + public static class StatusDto { + + @Schema(description = "좋아요 상태") + private boolean isFavorite; + } +} diff --git a/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java b/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java index a74864b6..b929dc35 100644 --- a/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java +++ b/src/main/java/com/jeju/nanaland/domain/favorite/service/FavoriteService.java @@ -42,7 +42,7 @@ public List getMemberFavoritePostIds(Member member, CategoryContent catego } @Transactional - public String toggleLikeStatus(Member member, CategoryContent categoryContent, Long postId) { + public Boolean toggleLikeStatus(Member member, CategoryContent categoryContent, Long postId) { Category category = getCategoryFromCategoryContent(categoryContent); @@ -55,7 +55,7 @@ public String toggleLikeStatus(Member member, CategoryContent categoryContent, L // 좋아요 삭제 favoriteRepository.delete(favorite); - return "좋아요 삭제"; + return false; } // 좋아요 상태가 아닐 때 else { @@ -67,7 +67,7 @@ public String toggleLikeStatus(Member member, CategoryContent categoryContent, L // 좋아요 추가 favoriteRepository.save(favorite); - return "좋아요 추가"; + return true; } } diff --git a/src/main/java/com/jeju/nanaland/domain/festival/controller/FestivalController.java b/src/main/java/com/jeju/nanaland/domain/festival/controller/FestivalController.java index 0ad9f4a9..0827fe9e 100644 --- a/src/main/java/com/jeju/nanaland/domain/festival/controller/FestivalController.java +++ b/src/main/java/com/jeju/nanaland/domain/festival/controller/FestivalController.java @@ -2,6 +2,7 @@ import static com.jeju.nanaland.global.exception.SuccessCode.POST_LIKE_TOGGLE_SUCCESS; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.festival.service.FestivalService; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.global.BaseResponse; @@ -34,9 +35,12 @@ public class FestivalController { @ApiResponse(responseCode = "500", description = "서버측 에러", content = @Content) }) @PostMapping("/like/{id}") - public BaseResponse toggleLikeStatus(@AuthMember MemberInfoDto memberInfoDto, + public BaseResponse toggleLikeStatus( + @AuthMember MemberInfoDto memberInfoDto, @PathVariable Long id) { - String result = festivalService.toggleLikeStatus(memberInfoDto.getMember(), id); - return BaseResponse.success(POST_LIKE_TOGGLE_SUCCESS, result); + + return BaseResponse.success( + POST_LIKE_TOGGLE_SUCCESS, + festivalService.toggleLikeStatus(memberInfoDto.getMember(), id)); } } diff --git a/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java b/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java index 4cbea582..e3a67776 100644 --- a/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java +++ b/src/main/java/com/jeju/nanaland/domain/festival/service/FestivalService.java @@ -1,6 +1,7 @@ package com.jeju.nanaland.domain.festival.service; import com.jeju.nanaland.domain.common.data.CategoryContent; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.service.FavoriteService; import com.jeju.nanaland.domain.festival.repository.FestivalRepository; import com.jeju.nanaland.domain.member.entity.Member; @@ -19,10 +20,13 @@ public class FestivalService { private final FavoriteService favoriteService; @Transactional - public String toggleLikeStatus(Member member, Long postId) { + public FavoriteResponse.StatusDto toggleLikeStatus(Member member, Long postId) { festivalRepository.findById(postId) .orElseThrow(() -> new BadRequestException("해당 id의 축제 게시물이 존재하지 않습니다.")); - return favoriteService.toggleLikeStatus(member, CategoryContent.FESTIVAL, postId); + Boolean status = favoriteService.toggleLikeStatus(member, CategoryContent.FESTIVAL, postId); + return FavoriteResponse.StatusDto.builder() + .isFavorite(status) + .build(); } } diff --git a/src/main/java/com/jeju/nanaland/domain/market/controller/MarketController.java b/src/main/java/com/jeju/nanaland/domain/market/controller/MarketController.java index a35c9367..6e6dacd8 100644 --- a/src/main/java/com/jeju/nanaland/domain/market/controller/MarketController.java +++ b/src/main/java/com/jeju/nanaland/domain/market/controller/MarketController.java @@ -2,6 +2,7 @@ import static com.jeju.nanaland.global.exception.SuccessCode.POST_LIKE_TOGGLE_SUCCESS; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.market.service.MarketService; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.global.BaseResponse; @@ -34,9 +35,12 @@ public class MarketController { @ApiResponse(responseCode = "500", description = "서버측 에러", content = @Content) }) @PostMapping("/like/{id}") - public BaseResponse toggleLikeStatus(@AuthMember MemberInfoDto memberInfoDto, + public BaseResponse toggleLikeStatus( + @AuthMember MemberInfoDto memberInfoDto, @PathVariable Long id) { - String result = marketService.toggleLikeStatus(memberInfoDto.getMember(), id); - return BaseResponse.success(POST_LIKE_TOGGLE_SUCCESS, result); + + return BaseResponse.success( + POST_LIKE_TOGGLE_SUCCESS, + marketService.toggleLikeStatus(memberInfoDto.getMember(), id)); } } diff --git a/src/main/java/com/jeju/nanaland/domain/market/service/MarketService.java b/src/main/java/com/jeju/nanaland/domain/market/service/MarketService.java index 0ced0781..b6973502 100644 --- a/src/main/java/com/jeju/nanaland/domain/market/service/MarketService.java +++ b/src/main/java/com/jeju/nanaland/domain/market/service/MarketService.java @@ -1,6 +1,8 @@ package com.jeju.nanaland.domain.market.service; import com.jeju.nanaland.domain.common.data.CategoryContent; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse.StatusDto; import com.jeju.nanaland.domain.favorite.service.FavoriteService; import com.jeju.nanaland.domain.market.repository.MarketRepository; import com.jeju.nanaland.domain.member.entity.Member; @@ -19,10 +21,13 @@ public class MarketService { private final FavoriteService favoriteService; @Transactional - public String toggleLikeStatus(Member member, Long postId) { + public StatusDto toggleLikeStatus(Member member, Long postId) { marketRepository.findById(postId) .orElseThrow(() -> new BadRequestException("해당 id의 전통시장 게시물이 존재하지 않습니다.")); - return favoriteService.toggleLikeStatus(member, CategoryContent.MARKET, postId); + Boolean status = favoriteService.toggleLikeStatus(member, CategoryContent.MARKET, postId); + return FavoriteResponse.StatusDto.builder() + .isFavorite(status) + .build(); } } diff --git a/src/main/java/com/jeju/nanaland/domain/nana/controller/NanaController.java b/src/main/java/com/jeju/nanaland/domain/nana/controller/NanaController.java index eea386e5..60b4688b 100644 --- a/src/main/java/com/jeju/nanaland/domain/nana/controller/NanaController.java +++ b/src/main/java/com/jeju/nanaland/domain/nana/controller/NanaController.java @@ -2,6 +2,7 @@ import static com.jeju.nanaland.global.exception.SuccessCode.POST_LIKE_TOGGLE_SUCCESS; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.domain.nana.dto.NanaResponse; import com.jeju.nanaland.domain.nana.dto.NanaResponse.NanaDetailDto; @@ -77,9 +78,12 @@ public BaseResponse nanaDetail(@PathVariable(name = "id") Long id @ApiResponse(responseCode = "500", description = "서버측 에러", content = @Content) }) @PostMapping("/like/{id}") - public BaseResponse toggleLikeStatus(@AuthMember MemberInfoDto memberInfoDto, + public BaseResponse toggleLikeStatus( + @AuthMember MemberInfoDto memberInfoDto, @PathVariable Long id) { - String result = nanaService.toggleLikeStatus(memberInfoDto.getMember(), id); - return BaseResponse.success(POST_LIKE_TOGGLE_SUCCESS, result); + + return BaseResponse.success( + POST_LIKE_TOGGLE_SUCCESS, + nanaService.toggleLikeStatus(memberInfoDto.getMember(), id)); } } diff --git a/src/main/java/com/jeju/nanaland/domain/nana/service/NanaService.java b/src/main/java/com/jeju/nanaland/domain/nana/service/NanaService.java index 878a883d..b377a45e 100644 --- a/src/main/java/com/jeju/nanaland/domain/nana/service/NanaService.java +++ b/src/main/java/com/jeju/nanaland/domain/nana/service/NanaService.java @@ -2,6 +2,8 @@ import com.jeju.nanaland.domain.common.data.CategoryContent; import com.jeju.nanaland.domain.common.entity.Locale; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse.StatusDto; import com.jeju.nanaland.domain.favorite.service.FavoriteService; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.nana.dto.NanaResponse; @@ -99,11 +101,14 @@ public NanaResponse.NanaDetailDto getNanaDetail(Long id) { } @Transactional - public String toggleLikeStatus(Member member, Long postId) { + public StatusDto toggleLikeStatus(Member member, Long postId) { nanaRepository.findById(postId) .orElseThrow(() -> new BadRequestException("해당 id의 나나스픽 게시물이 존재하지 않습니다.")); - return favoriteService.toggleLikeStatus(member, CategoryContent.NANA, postId); + Boolean status = favoriteService.toggleLikeStatus(member, CategoryContent.NANA, postId); + return FavoriteResponse.StatusDto.builder() + .isFavorite(status) + .build(); } // nanaContent의 AdditionalInfo dto로 바꾸기 diff --git a/src/main/java/com/jeju/nanaland/domain/nature/controller/NatureController.java b/src/main/java/com/jeju/nanaland/domain/nature/controller/NatureController.java index 9252bedb..cd695ea7 100644 --- a/src/main/java/com/jeju/nanaland/domain/nature/controller/NatureController.java +++ b/src/main/java/com/jeju/nanaland/domain/nature/controller/NatureController.java @@ -3,6 +3,7 @@ import static com.jeju.nanaland.global.exception.SuccessCode.POST_LIKE_TOGGLE_SUCCESS; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.domain.nature.service.NatureService; import com.jeju.nanaland.global.BaseResponse; @@ -35,9 +36,12 @@ public class NatureController { @ApiResponse(responseCode = "500", description = "서버측 에러", content = @Content) }) @PostMapping("/like/{id}") - public BaseResponse toggleLikeStatus(@AuthMember MemberInfoDto memberInfoDto, + public BaseResponse toggleLikeStatus( + @AuthMember MemberInfoDto memberInfoDto, @PathVariable Long id) { - String result = natureService.toggleLikeStatus(memberInfoDto.getMember(), id); - return BaseResponse.success(POST_LIKE_TOGGLE_SUCCESS, result); + + return BaseResponse.success( + POST_LIKE_TOGGLE_SUCCESS, + natureService.toggleLikeStatus(memberInfoDto.getMember(), id)); } } diff --git a/src/main/java/com/jeju/nanaland/domain/nature/service/NatureService.java b/src/main/java/com/jeju/nanaland/domain/nature/service/NatureService.java index d254369e..290f00d9 100644 --- a/src/main/java/com/jeju/nanaland/domain/nature/service/NatureService.java +++ b/src/main/java/com/jeju/nanaland/domain/nature/service/NatureService.java @@ -1,6 +1,7 @@ package com.jeju.nanaland.domain.nature.service; import com.jeju.nanaland.domain.common.data.CategoryContent; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.service.FavoriteService; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.nature.repository.NatureRepository; @@ -19,10 +20,13 @@ public class NatureService { private final FavoriteService favoriteService; @Transactional - public String toggleLikeStatus(Member member, Long postId) { + public FavoriteResponse.StatusDto toggleLikeStatus(Member member, Long postId) { natureRepository.findById(postId) .orElseThrow(() -> new BadRequestException("해당 id의 7대자연 게시물이 존재하지 않습니다.")); - return favoriteService.toggleLikeStatus(member, CategoryContent.NATURE, postId); + Boolean status = favoriteService.toggleLikeStatus(member, CategoryContent.NATURE, postId); + return FavoriteResponse.StatusDto.builder() + .isFavorite(status) + .build(); } } diff --git a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java index 50f589c7..9515ea9a 100644 --- a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java @@ -8,13 +8,12 @@ import com.jeju.nanaland.domain.common.entity.Language; import com.jeju.nanaland.domain.common.entity.Locale; import com.jeju.nanaland.domain.experience.entity.Experience; -import com.jeju.nanaland.domain.favorite.entity.Favorite; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.repository.FavoriteRepository; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.member.entity.Provider; import com.jeju.nanaland.global.exception.BadRequestException; import jakarta.persistence.EntityManager; -import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -98,22 +97,19 @@ void toggleLikeStatusTest() { * member2 : toggleLikeStatus 1번 적용 */ experienceService.toggleLikeStatus(member1, experience.getId()); - experienceService.toggleLikeStatus(member1, experience.getId()); - - experienceService.toggleLikeStatus(member2, experience.getId()); + FavoriteResponse.StatusDto result1 = experienceService.toggleLikeStatus(member1, + experience.getId()); - Optional favoriteOptional1 = - favoriteRepository.findByMemberAndCategoryAndPostId(member1, category, experience.getId()); - Optional favoriteOptional2 = - favoriteRepository.findByMemberAndCategoryAndPostId(member2, category, experience.getId()); + FavoriteResponse.StatusDto result2 = experienceService.toggleLikeStatus(member2, + experience.getId()); /** * THEN * * member1 = 좋아요 X, member2 = 좋아요 */ - assertThat(favoriteOptional1.isPresent()).isFalse(); - assertThat(favoriteOptional2.isPresent()).isTrue(); + assertThat(result1.isFavorite()).isFalse(); + assertThat(result2.isFavorite()).isTrue(); } @Test diff --git a/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java b/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java index 10277eea..6116ebba 100644 --- a/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/festival/service/FestivalServiceTest.java @@ -7,14 +7,13 @@ import com.jeju.nanaland.domain.common.entity.ImageFile; import com.jeju.nanaland.domain.common.entity.Language; import com.jeju.nanaland.domain.common.entity.Locale; -import com.jeju.nanaland.domain.favorite.entity.Favorite; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.repository.FavoriteRepository; import com.jeju.nanaland.domain.festival.entity.Festival; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.member.entity.Provider; import com.jeju.nanaland.global.exception.BadRequestException; import jakarta.persistence.EntityManager; -import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -98,22 +97,19 @@ void toggleLikeStatusTest() { * member2 : toggleLikeStatus 1번 적용 */ festivalService.toggleLikeStatus(member1, festival.getId()); - festivalService.toggleLikeStatus(member1, festival.getId()); - - festivalService.toggleLikeStatus(member2, festival.getId()); + FavoriteResponse.StatusDto result1 = festivalService.toggleLikeStatus(member1, + festival.getId()); - Optional favoriteOptional1 = - favoriteRepository.findByMemberAndCategoryAndPostId(member1, category, festival.getId()); - Optional favoriteOptional2 = - favoriteRepository.findByMemberAndCategoryAndPostId(member2, category, festival.getId()); + FavoriteResponse.StatusDto result2 = festivalService.toggleLikeStatus(member2, + festival.getId()); /** * THEN * * member1 = 좋아요 X, member2 = 좋아요 */ - assertThat(favoriteOptional1.isPresent()).isFalse(); - assertThat(favoriteOptional2.isPresent()).isTrue(); + assertThat(result1.isFavorite()).isFalse(); + assertThat(result2.isFavorite()).isTrue(); } @Test diff --git a/src/test/java/com/jeju/nanaland/domain/market/service/MarketServiceTest.java b/src/test/java/com/jeju/nanaland/domain/market/service/MarketServiceTest.java index 2ced1a34..3ce39389 100644 --- a/src/test/java/com/jeju/nanaland/domain/market/service/MarketServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/market/service/MarketServiceTest.java @@ -7,14 +7,13 @@ import com.jeju.nanaland.domain.common.entity.ImageFile; import com.jeju.nanaland.domain.common.entity.Language; import com.jeju.nanaland.domain.common.entity.Locale; -import com.jeju.nanaland.domain.favorite.entity.Favorite; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.repository.FavoriteRepository; import com.jeju.nanaland.domain.market.entity.Market; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.member.entity.Provider; import com.jeju.nanaland.global.exception.BadRequestException; import jakarta.persistence.EntityManager; -import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -98,22 +97,19 @@ void toggleLikeStatusTest() { * member2 : toggleLikeStatus 1번 적용 */ marketService.toggleLikeStatus(member1, market.getId()); - marketService.toggleLikeStatus(member1, market.getId()); - - marketService.toggleLikeStatus(member2, market.getId()); + FavoriteResponse.StatusDto result1 = marketService.toggleLikeStatus(member1, + market.getId()); - Optional favoriteOptional1 = - favoriteRepository.findByMemberAndCategoryAndPostId(member1, category, market.getId()); - Optional favoriteOptional2 = - favoriteRepository.findByMemberAndCategoryAndPostId(member2, category, market.getId()); + FavoriteResponse.StatusDto result2 = marketService.toggleLikeStatus(member2, + market.getId()); /** * THEN * * member1 = 좋아요 X, member2 = 좋아요 */ - assertThat(favoriteOptional1.isPresent()).isFalse(); - assertThat(favoriteOptional2.isPresent()).isTrue(); + assertThat(result1.isFavorite()).isFalse(); + assertThat(result2.isFavorite()).isTrue(); } @Test diff --git a/src/test/java/com/jeju/nanaland/domain/nana/service/NanaServiceTest.java b/src/test/java/com/jeju/nanaland/domain/nana/service/NanaServiceTest.java index 0f0620c4..b230f9ab 100644 --- a/src/test/java/com/jeju/nanaland/domain/nana/service/NanaServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/nana/service/NanaServiceTest.java @@ -7,14 +7,13 @@ import com.jeju.nanaland.domain.common.entity.ImageFile; import com.jeju.nanaland.domain.common.entity.Language; import com.jeju.nanaland.domain.common.entity.Locale; -import com.jeju.nanaland.domain.favorite.entity.Favorite; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.repository.FavoriteRepository; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.member.entity.Provider; import com.jeju.nanaland.domain.nana.entity.Nana; import com.jeju.nanaland.global.exception.BadRequestException; import jakarta.persistence.EntityManager; -import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -98,22 +97,19 @@ void toggleLikeStatusTest() { * member2 : toggleLikeStatus 1번 적용 */ nanaService.toggleLikeStatus(member1, nana.getId()); - nanaService.toggleLikeStatus(member1, nana.getId()); - - nanaService.toggleLikeStatus(member2, nana.getId()); + FavoriteResponse.StatusDto result1 = nanaService.toggleLikeStatus(member1, + nana.getId()); - Optional favoriteOptional1 = - favoriteRepository.findByMemberAndCategoryAndPostId(member1, category, nana.getId()); - Optional favoriteOptional2 = - favoriteRepository.findByMemberAndCategoryAndPostId(member2, category, nana.getId()); + FavoriteResponse.StatusDto result2 = nanaService.toggleLikeStatus(member2, + nana.getId()); /** * THEN * * member1 = 좋아요 X, member2 = 좋아요 */ - assertThat(favoriteOptional1.isPresent()).isFalse(); - assertThat(favoriteOptional2.isPresent()).isTrue(); + assertThat(result1.isFavorite()).isFalse(); + assertThat(result2.isFavorite()).isTrue(); } @Test diff --git a/src/test/java/com/jeju/nanaland/domain/nature/service/NatureServiceTest.java b/src/test/java/com/jeju/nanaland/domain/nature/service/NatureServiceTest.java index c8de4672..579b72d6 100644 --- a/src/test/java/com/jeju/nanaland/domain/nature/service/NatureServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/nature/service/NatureServiceTest.java @@ -7,14 +7,13 @@ import com.jeju.nanaland.domain.common.entity.ImageFile; import com.jeju.nanaland.domain.common.entity.Language; import com.jeju.nanaland.domain.common.entity.Locale; -import com.jeju.nanaland.domain.favorite.entity.Favorite; +import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse; import com.jeju.nanaland.domain.favorite.repository.FavoriteRepository; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.member.entity.Provider; import com.jeju.nanaland.domain.nature.entity.Nature; import com.jeju.nanaland.global.exception.BadRequestException; import jakarta.persistence.EntityManager; -import java.util.Optional; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -98,22 +97,19 @@ void toggleLikeStatusTest() { * member2 : toggleLikeStatus 1번 적용 */ natureService.toggleLikeStatus(member1, nature.getId()); - natureService.toggleLikeStatus(member1, nature.getId()); - - natureService.toggleLikeStatus(member2, nature.getId()); + FavoriteResponse.StatusDto result1 = natureService.toggleLikeStatus(member1, + nature.getId()); - Optional favoriteOptional1 = - favoriteRepository.findByMemberAndCategoryAndPostId(member1, category, nature.getId()); - Optional favoriteOptional2 = - favoriteRepository.findByMemberAndCategoryAndPostId(member2, category, nature.getId()); + FavoriteResponse.StatusDto result2 = natureService.toggleLikeStatus(member2, + nature.getId()); /** * THEN * * member1 = 좋아요 X, member2 = 좋아요 */ - assertThat(favoriteOptional1.isPresent()).isFalse(); - assertThat(favoriteOptional2.isPresent()).isTrue(); + assertThat(result1.isFavorite()).isFalse(); + assertThat(result2.isFavorite()).isTrue(); } @Test