-
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.
Browse files
Browse the repository at this point in the history
[Feat]#238 feature: ์ ์ฒด ํธ์์๋ฆผ๋ฉ์์ง ๋ฐ์ก
- Loading branch information
Showing
8 changed files
with
198 additions
and
7 deletions.
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); | ||
} | ||
} |