-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: #39 push notification test api 개방
- Loading branch information
1 parent
1b07fc9
commit 32e088b
Showing
6 changed files
with
109 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,7 @@ bin/ | |
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
.DS_Store | ||
|
||
## TEST API ## | ||
## **/test |
25 changes: 25 additions & 0 deletions
25
...pp-external-api/src/main/java/kr/co/fitapet/api/apis/test/NotificationTestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package kr.co.fitapet.api.apis.test; | ||
|
||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import kr.co.fitapet.api.common.security.authentication.CustomUserDetails; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "푸시 테스트 API", description = "push notification을 위한 개발자용 임시 API 입니다. 테스트 후 삭제 예정") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@RequestMapping("/api/v2/test/members") | ||
public class NotificationTestController { | ||
private final NotificationTestService notificationTestService; | ||
|
||
@RequestMapping("/push") | ||
@PreAuthorize("isAuthenticated()") | ||
public void push(@AuthenticationPrincipal CustomUserDetails user) { | ||
notificationTestService.push(user.getUserId()); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...t-app-external-api/src/main/java/kr/co/fitapet/api/apis/test/NotificationTestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package kr.co.fitapet.api.apis.test; | ||
|
||
import kr.co.fitapet.domain.domains.device.domain.DeviceToken; | ||
import kr.co.fitapet.domain.domains.device.service.DeviceTokenSearchService; | ||
import kr.co.fitapet.infra.client.fcm.NotificationDataKey; | ||
import kr.co.fitapet.infra.client.fcm.NotificationService; | ||
import kr.co.fitapet.infra.client.fcm.request.NotificationRequest; | ||
import kr.co.fitapet.infra.client.fcm.request.NotificationSingleRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class NotificationTestService { | ||
private final DeviceTokenSearchService deviceTokenSearchService; | ||
private final NotificationService notificationService; | ||
|
||
public void push(Long userId) { | ||
log.info("push to {}", userId); | ||
|
||
List<DeviceToken> deviceTokens = deviceTokenSearchService.findDeviceTokensByMemberId(userId); | ||
log.info("deviceTokens: {}", deviceTokens); | ||
|
||
log.info("send push message"); | ||
deviceTokens.forEach(deviceToken -> { | ||
NotificationSingleRequest request = NotificationSingleRequest.builder() | ||
.token(deviceToken.getDeviceToken()) | ||
.title("푸시 테스트") | ||
.content("푸시 테스트 메시지") | ||
.build(); | ||
|
||
notificationService.sendMessage(request); | ||
}); | ||
|
||
log.info("send push message with image"); | ||
deviceTokens.forEach(deviceToken -> { | ||
NotificationSingleRequest request = NotificationSingleRequest.builder() | ||
.title("이미지 테스트") | ||
.content("푸시 이미지 테스트 메시지") | ||
.imageUrl("https://pkcy.kr.object.ncloudstorage.com/profile/0bb25dde9020.jpeg") | ||
.build(); | ||
|
||
notificationService.sendMessage(request); | ||
}); | ||
|
||
log.info("send push message with data"); | ||
deviceTokens.forEach(deviceToken -> { | ||
NotificationSingleRequest request = NotificationSingleRequest.builder() | ||
.title("데이터 테스트") | ||
.content("푸시 데이터 테스트 메시지") | ||
.data( | ||
Map.of( | ||
NotificationDataKey.NOTICE_TYPE.getField(), "TEST_TYPE", | ||
NotificationDataKey.TO_ID.getField(), userId.toString() | ||
) | ||
) | ||
.build(); | ||
|
||
notificationService.sendMessage(request); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters