Skip to content

Commit

Permalink
YEL-163 [feat] service 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
user 이름 committed Sep 21, 2023
1 parent 6b724b5 commit 4956b0a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public BaseResponse<AdminUserResponse> 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);
Expand Down Expand Up @@ -92,7 +92,7 @@ public BaseResponse deleteUser(@AccessTokenUser User user, @RequestParam Long us
public BaseResponse<AdminCooldownResponse> 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);
Expand Down Expand Up @@ -136,11 +136,10 @@ public BaseResponse deleteQuestion(@AccessTokenUser User user, @RequestParam Lon
}

@PostMapping("/notification")
public BaseResponse postCustomNotificationSendAdmin(@AccessTokenUser User user,
public BaseResponse<EmptyObject> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public AdminUserResponse findUserContaining(Long adminId, Pageable page, String
Long totalCount = 0L;
List<AdminUserContentVO> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,4 +17,6 @@ public interface NotificationService {
void sendVoteAvailableNotification(Long receiverId);

void sendCustomNotification(NotificationCustomMessage request);

EmptyObject adminSendCustomNotification(Long adminId, NotificationCustomMessage request);
}

0 comments on commit 4956b0a

Please sign in to comment.