Skip to content

Commit 62c7bf2

Browse files
claude[bot]github-actions[bot]claude
authored
Maintenance: Notification Service - Improve performance and code consistency (#102)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude <[email protected]>
1 parent d424e73 commit 62c7bf2

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/main/java/spring/memewikibe/application/notification/MemeNotificationService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import lombok.extern.slf4j.Slf4j;
55
import org.springframework.stereotype.Service;
66
import spring.memewikibe.domain.meme.Meme;
7-
import spring.memewikibe.domain.notification.NotificationToken;
87
import spring.memewikibe.infrastructure.MemeRepository;
98
import spring.memewikibe.infrastructure.NotificationTokenRepository;
109
import spring.memewikibe.support.error.ErrorType;
@@ -26,10 +25,7 @@ public void sendMemeNotification(Long memeId, String title, String body) {
2625
Meme meme = memeRepository.findById(memeId)
2726
.orElseThrow(() -> new MemeWikiApplicationException(ErrorType.MEME_NOT_FOUND));
2827

29-
List<String> tokens = tokenRepository.findAll()
30-
.stream()
31-
.map(NotificationToken::getToken)
32-
.toList();
28+
List<String> tokens = tokenRepository.findAllTokens();
3329

3430
if (tokens.isEmpty()) {
3531
log.info("No active tokens found for meme notification: memeId={}", memeId);

src/main/java/spring/memewikibe/application/notification/NotificationTokenRegister.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package spring.memewikibe.application.notification;
22

3+
import lombok.RequiredArgsConstructor;
34
import org.springframework.lang.NonNull;
45
import org.springframework.stereotype.Component;
56
import org.springframework.transaction.annotation.Transactional;
67
import spring.memewikibe.domain.notification.NotificationToken;
78
import spring.memewikibe.infrastructure.NotificationTokenRepository;
89

910
@Component
11+
@RequiredArgsConstructor
1012
public class NotificationTokenRegister {
11-
private final NotificationTokenRepository notificationTokenRepository;
1213

13-
public NotificationTokenRegister(NotificationTokenRepository notificationTokenRepository) {
14-
this.notificationTokenRepository = notificationTokenRepository;
15-
}
14+
private final NotificationTokenRepository notificationTokenRepository;
1615

1716
@Transactional
1817
public void registerToken(@NonNull final String token) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package spring.memewikibe.infrastructure;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Query;
45
import spring.memewikibe.domain.notification.NotificationToken;
56

7+
import java.util.List;
8+
69
public interface NotificationTokenRepository extends JpaRepository<NotificationToken, String> {
10+
11+
@Query("SELECT n.token FROM NotificationToken n")
12+
List<String> findAllTokens();
713
}

src/test/java/spring/memewikibe/infrastructure/NotificationTokenRepositoryTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,20 @@ class NotificationTokenRepositoryTest {
2828
then(saved.getCreatedAt()).isNotNull();
2929
then(saved.getUpdatedAt()).isNotNull();
3030
}
31+
32+
@Test
33+
void 모든_토큰_문자열을_조회할_수_있다() {
34+
// given
35+
sut.save(NotificationToken.create("token1"));
36+
sut.save(NotificationToken.create("token2"));
37+
sut.save(NotificationToken.create("token3"));
38+
sut.flush();
39+
40+
// when
41+
var tokens = sut.findAllTokens();
42+
43+
// then
44+
then(tokens).containsExactlyInAnyOrder("token1", "token2", "token3");
45+
}
3146
}
3247

0 commit comments

Comments
 (0)