Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: 좋아요/싫어요 취소 시, 싫어요 취소해도 좋아요 통계 줄어드는 오류 수정 #473

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.now.naaga.like.application.dto.CancelLikeCommand;
import com.now.naaga.like.domain.PlaceLike;
import com.now.naaga.like.domain.PlaceLikeType;
import com.now.naaga.like.exception.PlaceLikeException;
import com.now.naaga.like.exception.PlaceLikeExceptionType;
import com.now.naaga.like.repository.PlaceLikeRepository;
Expand Down Expand Up @@ -40,7 +41,13 @@ public void cancelLike(final CancelLikeCommand cancelLikeCommand) {
final PlaceLike placeLike = maybePlaceLike.get();
placeLikeRepository.delete(placeLike);

final SubtractLikeCommand subtractLikeCommand = new SubtractLikeCommand(placeId);
placeStatisticsService.subtractLike(subtractLikeCommand);
subtractPlaceLikeCount(placeId, placeLike);
}

private void subtractPlaceLikeCount(final Long placeId, final PlaceLike placeLike) {
if(placeLike.getType() == PlaceLikeType.LIKE) {
final SubtractLikeCommand subtractLikeCommand = new SubtractLikeCommand(placeId);
placeStatisticsService.subtractLike(subtractLikeCommand);
}
Comment on lines +47 to +51
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 enum앞에 클래스명을 붙이지 않는것이 컨밴션이였던것으로 기억합니다!

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.now.naaga.common.exception.BaseExceptionType;
import com.now.naaga.like.application.dto.CancelLikeCommand;
import com.now.naaga.like.domain.PlaceLike;
import com.now.naaga.like.domain.PlaceLikeType;
import com.now.naaga.like.exception.PlaceLikeException;
import com.now.naaga.like.repository.PlaceLikeRepository;
import com.now.naaga.place.domain.Place;
Expand Down Expand Up @@ -76,6 +77,7 @@ public PlaceLikeServiceTest(final PlaceLikeService placeLikeService,
final PlaceLike placeLike = placeLikeBuilder.init()
.place(place)
.player(player)
.placeLikeType(PlaceLikeType.LIKE)
.build();
final long beforeLikeCount = 10L;
placeStatisticsBuilder.init()
Expand All @@ -96,6 +98,37 @@ public PlaceLikeServiceTest(final PlaceLikeService placeLikeService,
});
}

@Test
void 싫어요를_삭제하면_통계가_줄어들지_않는다() {
// given
final Place place = placeBuilder.init()
.build();
final Player player = playerBuilder.init()
.build();
final PlaceLike placeLike = placeLikeBuilder.init()
.place(place)
.player(player)
.placeLikeType(PlaceLikeType.DISLIKE)
.build();
final long beforeLikeCount = 10L;
placeStatisticsBuilder.init()
.place(place)
.likeCount(beforeLikeCount)
.build();
final CancelLikeCommand cancelLikeCommand = new CancelLikeCommand(player.getId(), place.getId());

// when
placeLikeService.cancelLike(cancelLikeCommand);

// then
final Optional<PlaceLike> findPlaceLike = placeLikeRepository.findById(placeLike.getId());
final PlaceStatistics findPlaceStatistics = placeStatisticsRepository.findByPlaceId(place.getId()).get();
assertSoftly(softAssertions -> {
assertThat(findPlaceStatistics.getLikeCount()).isEqualTo(beforeLikeCount);
assertThat(findPlaceLike).isEmpty();
});
Comment on lines +124 to +129
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

검증 굿

}

@Test
void 좋아요가_0개일_때_좋아요를_삭제하면_통계에서_좋아요를_0개로_유지한다() {
// given
Expand All @@ -106,6 +139,7 @@ public PlaceLikeServiceTest(final PlaceLikeService placeLikeService,
final PlaceLike placeLike = placeLikeBuilder.init()
.place(place)
.player(player)
.placeLikeType(PlaceLikeType.LIKE)
.build();
final long beforeLikeCount = 0L;
placeStatisticsBuilder.init()
Expand Down
Loading