-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feat]#238 feature: 전체 푸시알림메시지 발송 #239
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/org/winey/server/controller/BroadCastController.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,35 @@ | ||
package org.winey.server.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.winey.server.common.dto.ApiResponse; | ||
import org.winey.server.controller.request.broadcast.BroadCastAllUserDto; | ||
import org.winey.server.exception.Success; | ||
import org.winey.server.service.BroadCastService; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.google.firebase.messaging.FirebaseMessagingException; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/broadcast") | ||
@Tag(name = "BroadCast", description = "위니 전체 푸시 API Document") | ||
public class BroadCastController { | ||
private final BroadCastService broadCastService; | ||
|
||
@PostMapping("/send-all") | ||
@ResponseStatus(HttpStatus.OK) | ||
@Operation(summary = "전체 유저에게 메시지 발송 API", description = "전체 유저에게 메시지를 발송합니다.") | ||
public ApiResponse sendMessageToEntireUser(@RequestBody BroadCastAllUserDto broadCastAllUserDto){ | ||
return ApiResponse.success(Success.SEND_ENTIRE_MESSAGE_SUCCESS, broadCastService.broadAllUser(broadCastAllUserDto)); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/winey/server/controller/request/broadcast/BroadCastAllUserDto.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,15 @@ | ||
package org.winey.server.controller.request.broadcast; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@AllArgsConstructor | ||
public class BroadCastAllUserDto { | ||
String title; | ||
|
||
String message; | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/main/java/org/winey/server/service/BroadCastService.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,54 @@ | ||
package org.winey.server.service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.winey.server.common.dto.ApiResponse; | ||
import org.winey.server.controller.request.broadcast.BroadCastAllUserDto; | ||
import org.winey.server.domain.user.User; | ||
import org.winey.server.exception.Error; | ||
import org.winey.server.exception.Success; | ||
import org.winey.server.exception.model.CustomException; | ||
import org.winey.server.infrastructure.UserRepository; | ||
import org.winey.server.service.message.SendAllFcmDto; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.google.firebase.messaging.FirebaseMessagingException; | ||
import com.sun.net.httpserver.Authenticator; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BroadCastService { | ||
|
||
private final FcmService fcmService; | ||
|
||
private final UserRepository userRepository; | ||
|
||
public ApiResponse broadAllUser(BroadCastAllUserDto broadCastAllUserDto){ | ||
List<User> allUser = userRepository.findByFcmTokenNotNull(); | ||
List<String> tokenList; | ||
if (!allUser.isEmpty()){ | ||
try { | ||
tokenList = allUser.stream().map( | ||
User::getFcmToken).collect(Collectors.toList()); | ||
System.out.println(tokenList); | ||
fcmService.sendAllByTokenList( | ||
SendAllFcmDto.of(tokenList, broadCastAllUserDto.getTitle(), broadCastAllUserDto.getMessage())); | ||
return ApiResponse.success(Success.SEND_ENTIRE_MESSAGE_SUCCESS, | ||
Success.SEND_ENTIRE_MESSAGE_SUCCESS.getMessage()); | ||
}catch (FirebaseMessagingException | JsonProcessingException e){ | ||
return ApiResponse.error(Error.UNPROCESSABLE_SEND_TO_FIREBASE, Error.UNPROCESSABLE_SEND_TO_FIREBASE.getMessage()); | ||
} | ||
} | ||
return ApiResponse.error(Error.UNPROCESSABLE_FIND_USERS, Error.UNPROCESSABLE_FIND_USERS.getMessage()); | ||
} | ||
|
||
|
||
|
||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/org/winey/server/service/message/SendAllFcmDto.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,23 @@ | ||
package org.winey.server.service.message; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.winey.server.domain.notification.NotiType; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class SendAllFcmDto { | ||
private List<String> tokenList; | ||
|
||
private String title; | ||
|
||
private String message; | ||
|
||
public static SendAllFcmDto of(List<String> tokenList, String title, String message){ | ||
return new SendAllFcmDto(tokenList, title, message); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 CompletableFuture를 처음 봐서 검색해봤는데 반환된 Future를 기반으로 외부에서 작업을 완료하거나 추가하거나 그러는 것 같더라구요.. 여기서는 어떻게 사용하는 건가용..??!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일단 결론부터 말씀드리면 비동기식으로 구현해야할지 동기식으로 그냥 구현해도 될지에 대해서 고민을 하는 과정이 있었는데요. 다음과 같은 코드는 비동기식으로 구현을 한다고 가정을 했을 때의 오류를 컨트롤하고싶어서 만들어놨다가 뇌정지가 온 모습입니다.. ㅜ
저의 얕은 지식으로 알기로는 비동기식으로 구현을 하게되면 그냥 보통의 return값을 선언했을 때 이후의 예외처리를 할 수 없다고? 알고있었습니다.(다른 방식이 있을 수도 있을 것 같습니다..ㅜ) timeOut으로 종료되는 것이 아니면 외부에서 종료시킬 수도 없어서 저것을 사용하면 비동기작업인데도 불구하고 어떤 에러가 발생했을 때 그 에러를 서비스단으로 반환시켜서 그랬을 때의 에러를 서비스단에서 핸들링하던가 하고싶었는데 저희가 기획에서 요청을 받으면 그 때만 보내는 것이기에 비동기로 하는 것이 맞을지에 대해서도 의문이라서 저도 다른 의견들이 궁금합니다. (동기식으로 그냥 구현해도 상관없을 것 같다면 그냥 빼도 될 것 같습니다!) 저도 비동기와 관련된 내용들은 CS지식이 많이 부족하기 때문에 이참에 더 공부해보도록 할게요 ㅜ