Skip to content

Commit 7a3f806

Browse files
committed
세모피드 응답 계약 정리
1 parent c74d49a commit 7a3f806

3 files changed

Lines changed: 49 additions & 8 deletions

File tree

src/main/java/com/semosan/api/domain/semofeed/dto/SemoFeedResponse.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.semosan.api.domain.semofeed.entity.SemoFeed;
44
import com.semosan.api.domain.semofeed.enums.SemoFeedEmojiType;
55

6+
import java.util.EnumMap;
67
import java.util.Map;
78

89
public record SemoFeedResponse(
@@ -19,9 +20,9 @@ public record SemoFeedResponse(
1920
public static SemoFeedResponse from(SemoFeed semoFeed) {
2021
return of(
2122
semoFeed,
22-
Map.of(),
23-
Map.of(),
24-
false
23+
defaultEmojiCounts(),
24+
defaultReactedByMe(),
25+
true
2526
);
2627
}
2728

@@ -43,4 +44,20 @@ public static SemoFeedResponse of(
4344
mine
4445
);
4546
}
47+
48+
private static Map<SemoFeedEmojiType, Long> defaultEmojiCounts() {
49+
Map<SemoFeedEmojiType, Long> emojiCounts = new EnumMap<>(SemoFeedEmojiType.class);
50+
for (SemoFeedEmojiType emojiType : SemoFeedEmojiType.values()) {
51+
emojiCounts.put(emojiType, 0L);
52+
}
53+
return emojiCounts;
54+
}
55+
56+
private static Map<SemoFeedEmojiType, Boolean> defaultReactedByMe() {
57+
Map<SemoFeedEmojiType, Boolean> reactedByMe = new EnumMap<>(SemoFeedEmojiType.class);
58+
for (SemoFeedEmojiType emojiType : SemoFeedEmojiType.values()) {
59+
reactedByMe.put(emojiType, false);
60+
}
61+
return reactedByMe;
62+
}
4663
}

src/main/java/com/semosan/api/domain/semofeed/service/SemoFeedService.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public SemoFeedResponse create(Long userId, String imageUrl) {
3838
return SemoFeedResponse.from(semoFeedRepository.save(semoFeed));
3939
}
4040

41-
public Page<SemoFeedResponse> listPublic(Pageable pageable) {
42-
Page<SemoFeed> semoFeeds = semoFeedRepository.findPublic(pageable);
43-
return toResponsePage(semoFeeds, null);
44-
}
45-
4641
public List<SemoFeedResponse> listMine(Long userId) {
4742
List<SemoFeed> semoFeeds = semoFeedRepository.findByUserId(userId);
4843
SemoFeedResponseAssembler assembler = createResponseAssembler(semoFeeds, userId);

src/test/java/com/semosan/api/domain/semofeed/service/SemoFeedServiceTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import org.springframework.test.util.ReflectionTestUtils;
2020

2121
import java.util.List;
22+
import java.util.Optional;
2223

2324
import static org.assertj.core.api.Assertions.assertThat;
25+
import static org.mockito.ArgumentMatchers.any;
2426
import static org.mockito.Mockito.verify;
2527
import static org.mockito.Mockito.when;
2628

@@ -39,6 +41,33 @@ class SemoFeedServiceTest {
3941
@InjectMocks
4042
private SemoFeedService semoFeedService;
4143

44+
@Test
45+
void createReturnsDefaultEmojiFields() {
46+
User user = user(1L, "author", "https://example.com/profile.png");
47+
48+
when(userRepository.findById(1L)).thenReturn(Optional.of(user));
49+
when(semoFeedRepository.save(any(SemoFeed.class))).thenAnswer(invocation -> {
50+
SemoFeed semoFeed = invocation.getArgument(0);
51+
ReflectionTestUtils.setField(semoFeed, "id", 10L);
52+
return semoFeed;
53+
});
54+
55+
SemoFeedResponse result = semoFeedService.create(1L, "https://example.com/semofeed.png");
56+
57+
assertThat(result.userId()).isEqualTo(1L);
58+
assertThat(result.mine()).isTrue();
59+
assertThat(result.emojiCounts())
60+
.containsEntry(SemoFeedEmojiType.FIRE, 0L)
61+
.containsEntry(SemoFeedEmojiType.HEART, 0L)
62+
.containsEntry(SemoFeedEmojiType.CONGRATS, 0L)
63+
.containsEntry(SemoFeedEmojiType.LAUGH, 0L);
64+
assertThat(result.reactedByMe())
65+
.containsEntry(SemoFeedEmojiType.FIRE, false)
66+
.containsEntry(SemoFeedEmojiType.HEART, false)
67+
.containsEntry(SemoFeedEmojiType.CONGRATS, false)
68+
.containsEntry(SemoFeedEmojiType.LAUGH, false);
69+
}
70+
4271
@Test
4372
void listPublicBuildsAuthorEmojiCountsAndReactedByMe() {
4473
User author = user(1L, "author", "https://example.com/profile.png");

0 commit comments

Comments
 (0)