diff --git a/src/main/java/com/yello/server/domain/admin/controller/AdminController.java b/src/main/java/com/yello/server/domain/admin/controller/AdminController.java index 2c75ee71..e6ba2ccb 100644 --- a/src/main/java/com/yello/server/domain/admin/controller/AdminController.java +++ b/src/main/java/com/yello/server/domain/admin/controller/AdminController.java @@ -61,7 +61,7 @@ public BaseResponse getUserAdmin(@AccessTokenUser User user, @RequestParam Integer page, @Nullable @RequestParam String field, @Nullable @RequestParam String value) { - val data = (field==null && value==null) + val data = (field == null && value == null) ? adminService.findUser(user.getId(), createPageableLimitTen(page)) : adminService.findUserContaining(user.getId(), createPageableLimitTen(page), field, value); @@ -92,7 +92,7 @@ public BaseResponse deleteUser(@AccessTokenUser User user, @RequestParam Long us public BaseResponse getCooldownAdmin(@AccessTokenUser User user, @RequestParam Integer page, @Nullable @RequestParam String yelloId) { - val data = yelloId==null + val data = yelloId == null ? adminService.findCooldown(user.getId(), createPageableLimitTen(page)) : adminService.findCooldownContaining(user.getId(), createPageableLimitTen(page), yelloId); @@ -136,11 +136,10 @@ public BaseResponse deleteQuestion(@AccessTokenUser User user, @RequestParam Lon } @PostMapping("/notification") - public BaseResponse postCustomNotificationSendAdmin(@AccessTokenUser User user, + public BaseResponse postCustomNotificationSendAdmin(@AccessTokenUser User user, @RequestBody NotificationCustomMessage request) { + val data = notificationService.adminSendCustomNotification(user.getId(), request); - notificationService.sendCustomNotification(request); - - return BaseResponse.success(CREATE_VOTE_SUCCESS); + return BaseResponse.success(CREATE_VOTE_SUCCESS, data); } } diff --git a/src/main/java/com/yello/server/domain/admin/service/AdminService.java b/src/main/java/com/yello/server/domain/admin/service/AdminService.java index 8b04c535..5f07c431 100644 --- a/src/main/java/com/yello/server/domain/admin/service/AdminService.java +++ b/src/main/java/com/yello/server/domain/admin/service/AdminService.java @@ -98,7 +98,7 @@ public AdminUserResponse findUserContaining(Long adminId, Pageable page, String Long totalCount = 0L; List list = new ArrayList<>(); - if (field==null || value==null) { + if (field == null || value == null) { throw new UserAdminBadRequestException(USER_ADMIN_BAD_REQUEST_EXCEPTION); } else if (field.equals("yelloId")) { totalCount = userRepository.countAllByYelloIdContaining(value); diff --git a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java index d7c87dbd..c92a36f6 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java @@ -1,10 +1,12 @@ package com.yello.server.infrastructure.firebase.service; import com.google.firebase.messaging.Message; +import com.yello.server.domain.admin.repository.UserAdminRepository; import com.yello.server.domain.friend.entity.Friend; import com.yello.server.domain.user.entity.User; import com.yello.server.domain.user.repository.UserRepository; import com.yello.server.domain.vote.entity.Vote; +import com.yello.server.global.common.dto.EmptyObject; import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage; import com.yello.server.infrastructure.firebase.dto.request.NotificationMessage; import com.yello.server.infrastructure.firebase.manager.FCMManager; @@ -24,13 +26,14 @@ public class NotificationFcmService implements NotificationService { private final UserRepository userRepository; private final TokenRepository tokenRepository; private final FCMManager fcmManager; + private final UserAdminRepository userAdminRepository; @Override public void sendRecommendNotification(User user, User target) { NotificationMessage notificationMessage = NotificationMessage.toRecommendNotificationContent(user); - if (target.getDeviceToken()!=null && !Objects.equals(target.getDeviceToken(), "")) { + if (target.getDeviceToken() != null && !Objects.equals(target.getDeviceToken(), "")) { final Message message = fcmManager.createMessage(target.getDeviceToken(), notificationMessage); fcmManager.send(message); @@ -46,7 +49,7 @@ public void sendYelloNotification(Vote vote) { final String path = "/api/v1/vote/" + vote.getId().toString(); - if (receiver.getDeviceToken()!=null && !Objects.equals(receiver.getDeviceToken(), "")) { + if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(), "")) { final Message message = fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage, path); fcmManager.send(message); @@ -61,7 +64,7 @@ public void sendFriendNotification(Friend friend) { NotificationMessage notificationMessage = NotificationMessage.toFriendNotificationContent(sender); - if (receiver.getDeviceToken()!=null && !Objects.equals(receiver.getDeviceToken(), "")) { + if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(), "")) { final Message message = fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage); fcmManager.send(message); @@ -75,7 +78,7 @@ public void sendVoteAvailableNotification(Long receiverId) { NotificationMessage notificationMessage = NotificationMessage.toVoteAvailableNotificationContent(); - if (receiveUser.getDeviceToken()!=null && !Objects.equals(receiveUser.getDeviceToken(), + if (receiveUser.getDeviceToken() != null && !Objects.equals(receiveUser.getDeviceToken(), "")) { final Message message = fcmManager.createMessage(receiveUser.getDeviceToken(), notificationMessage); @@ -94,7 +97,7 @@ public void sendCustomNotification(NotificationCustomMessage request) { NotificationMessage notificationMessage = NotificationMessage.toYelloNotificationCustomContent(request); - if (receiver.getDeviceToken()!=null && !Objects.equals(receiver.getDeviceToken(), + if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(), "")) { final Message message = fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage); @@ -103,4 +106,16 @@ public void sendCustomNotification(NotificationCustomMessage request) { }); } + + @Override + public EmptyObject adminSendCustomNotification(Long adminId, NotificationCustomMessage request) { + // exception + final User admin = userRepository.getById(adminId); + userAdminRepository.getByUser(admin); + + // logic + this.sendCustomNotification(request); + + return EmptyObject.builder().build(); + } } diff --git a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java index 36687671..b0d8f687 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationService.java @@ -3,6 +3,7 @@ import com.yello.server.domain.friend.entity.Friend; import com.yello.server.domain.user.entity.User; import com.yello.server.domain.vote.entity.Vote; +import com.yello.server.global.common.dto.EmptyObject; import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage; public interface NotificationService { @@ -16,4 +17,6 @@ public interface NotificationService { void sendVoteAvailableNotification(Long receiverId); void sendCustomNotification(NotificationCustomMessage request); + + EmptyObject adminSendCustomNotification(Long adminId, NotificationCustomMessage request); }