Skip to content

Commit 425ddef

Browse files
Merge pull request #257 from prgrms-web-devcourse-final-project/revert-250-refactor/share-refactoring(WR9-127)
Revert "Refactor/share refactoring(wr9 127)"
2 parents 3d3fa0a + 0403549 commit 425ddef

File tree

2 files changed

+3
-38
lines changed

2 files changed

+3
-38
lines changed

src/main/java/io/crops/warmletter/domain/share/service/SharePostLikeService.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ public SharePostLikeResponse getLikeCountAndStatus(Long sharePostId) {
2727
if (sharePostId == null)
2828
throw new ShareInvalidInputValue();
2929

30-
boolean isLikedInRedis = postLikeRedisManager.isLiked(sharePostId,memberId);
31-
32-
SharePostLikeResponse response = sharePostLikeRepository.getLikeCountAndStatus(sharePostId,memberId);
33-
34-
if (isLikedInRedis != response.isLiked()) {
35-
return new SharePostLikeResponse(response.getLikeCount(), isLikedInRedis);
36-
}
37-
38-
return response;
30+
return sharePostLikeRepository.getLikeCountAndStatus(sharePostId,memberId);
3931
}
4032
}

src/test/java/io/crops/warmletter/domain/share/service/SharePostLikeServiceTest.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package io.crops.warmletter.domain.share.service;
2+
23
import io.crops.warmletter.domain.auth.facade.AuthFacade;
34
import io.crops.warmletter.domain.share.cache.PostLikeRedisManager;
45
import io.crops.warmletter.domain.share.dto.response.SharePostLikeResponse;
@@ -10,6 +11,7 @@
1011
import org.mockito.InjectMocks;
1112
import org.mockito.Mock;
1213
import org.mockito.junit.jupiter.MockitoExtension;
14+
1315
import static org.junit.jupiter.api.Assertions.*;
1416
import static org.mockito.Mockito.*;
1517

@@ -54,7 +56,6 @@ void getLikeCountAndStatus_Success() {
5456
SharePostLikeResponse mockResponse = new SharePostLikeResponse(5L, true);
5557

5658
when(authFacade.getCurrentUserId()).thenReturn(memberId);
57-
when(redisManager.isLiked(sharePostId, memberId)).thenReturn(true);
5859
when(sharePostLikeRepository.getLikeCountAndStatus(sharePostId, memberId))
5960
.thenReturn(mockResponse);
6061

@@ -66,7 +67,6 @@ void getLikeCountAndStatus_Success() {
6667
assertEquals(5L, result.getLikeCount());
6768
assertTrue(result.isLiked());
6869
verify(authFacade).getCurrentUserId();
69-
verify(redisManager).isLiked(sharePostId, memberId);
7070
verify(sharePostLikeRepository).getLikeCountAndStatus(sharePostId, memberId);
7171
}
7272

@@ -79,7 +79,6 @@ void getLikeCountAndStatus_NotLiked() {
7979
SharePostLikeResponse mockResponse = new SharePostLikeResponse(10L, false);
8080

8181
when(authFacade.getCurrentUserId()).thenReturn(memberId);
82-
when(redisManager.isLiked(sharePostId, memberId)).thenReturn(false);
8382
when(sharePostLikeRepository.getLikeCountAndStatus(sharePostId, memberId))
8483
.thenReturn(mockResponse);
8584

@@ -91,7 +90,6 @@ void getLikeCountAndStatus_NotLiked() {
9190
assertEquals(10L, result.getLikeCount());
9291
assertFalse(result.isLiked());
9392
verify(authFacade).getCurrentUserId();
94-
verify(redisManager).isLiked(sharePostId, memberId);
9593
verify(sharePostLikeRepository).getLikeCountAndStatus(sharePostId, memberId);
9694
}
9795

@@ -108,31 +106,6 @@ void getLikeCountAndStatus_NullPostId() {
108106
});
109107

110108
verify(authFacade).getCurrentUserId();
111-
verify(redisManager, never()).isLiked(any(), any());
112109
verify(sharePostLikeRepository, never()).getLikeCountAndStatus(any(), any());
113110
}
114-
@Test
115-
@DisplayName("좋아요 개수와 상태 조회 - Redis는 false, DB는 true일 때 redis 우선 ")
116-
void getLikeCountAndStatus_RedisNotLikedDbLiked() {
117-
// given
118-
Long sharePostId = 1L;
119-
Long memberId = 1L;
120-
SharePostLikeResponse mockResponse = new SharePostLikeResponse(10L, true);
121-
122-
when(authFacade.getCurrentUserId()).thenReturn(memberId);
123-
when(redisManager.isLiked(sharePostId, memberId)).thenReturn(false);
124-
when(sharePostLikeRepository.getLikeCountAndStatus(sharePostId, memberId))
125-
.thenReturn(mockResponse);
126-
127-
// when
128-
SharePostLikeResponse result = sharePostLikeService.getLikeCountAndStatus(sharePostId);
129-
130-
// then
131-
assertNotNull(result);
132-
assertEquals(10L, result.getLikeCount());
133-
assertFalse(result.isLiked());
134-
verify(authFacade).getCurrentUserId();
135-
verify(redisManager).isLiked(sharePostId, memberId);
136-
verify(sharePostLikeRepository).getLikeCountAndStatus(sharePostId, memberId);
137-
}
138111
}

0 commit comments

Comments
 (0)