Skip to content

Commit

Permalink
YEL-163 [deploy] v1.198 hotfix!!!
Browse files Browse the repository at this point in the history
YEL-163 [deploy] v1.198 hotfix!!!
  • Loading branch information
euije authored Sep 21, 2023
2 parents 64977b8 + 4956b0a commit ee92854
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.yello.server.global.common.annotation.AccessTokenUser;
import com.yello.server.global.common.dto.BaseResponse;
import com.yello.server.global.common.dto.EmptyObject;
import com.yello.server.infrastructure.firebase.dto.request.NotificationCustomMessage;
import com.yello.server.infrastructure.firebase.service.NotificationService;
import javax.annotation.Nullable;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -56,7 +57,8 @@ public BaseResponse<AdminLoginResponse> postAdminLogin(@RequestBody AdminLoginRe
}

@GetMapping("/user")
public BaseResponse<AdminUserResponse> getUserAdmin(@AccessTokenUser User user, @RequestParam Integer page,
public BaseResponse<AdminUserResponse> getUserAdmin(@AccessTokenUser User user,
@RequestParam Integer page,
@Nullable @RequestParam String field,
@Nullable @RequestParam String value) {
val data = (field == null && value == null)
Expand All @@ -67,7 +69,8 @@ public BaseResponse<AdminUserResponse> getUserAdmin(@AccessTokenUser User user,
}

@GetMapping("/user/{id}")
public BaseResponse<AdminUserDetailResponse> getUserDetailAdmin(@AccessTokenUser User user, @PathVariable Long id) {
public BaseResponse<AdminUserDetailResponse> getUserDetailAdmin(@AccessTokenUser User user,
@PathVariable Long id) {
val data = adminService.findUserDetail(user.getId(), id);
return BaseResponse.success(READ_USER_DETAIL_ADMIN_SUCCESS, data);
}
Expand All @@ -86,7 +89,8 @@ public BaseResponse deleteUser(@AccessTokenUser User user, @RequestParam Long us
}

@GetMapping("/cooldown")
public BaseResponse<AdminCooldownResponse> getCooldownAdmin(@AccessTokenUser User user, @RequestParam Integer page,
public BaseResponse<AdminCooldownResponse> getCooldownAdmin(@AccessTokenUser User user,
@RequestParam Integer page,
@Nullable @RequestParam String yelloId) {
val data = yelloId == null
? adminService.findCooldown(user.getId(), createPageableLimitTen(page))
Expand All @@ -109,7 +113,8 @@ public BaseResponse<AdminQuestionResponse> getQuestionAdmin(@AccessTokenUser Use
}

@GetMapping("/question/{id}")
public BaseResponse<AdminQuestionDetailResponse> getQuestionDetailAdmin(@AccessTokenUser User user,
public BaseResponse<AdminQuestionDetailResponse> getQuestionDetailAdmin(
@AccessTokenUser User user,
@PathVariable Long id) {
val data = adminService.findQuestionDetail(user.getId(), id);
return BaseResponse.success(READ_QUESTION_DETAIL_ADMIN_SUCCESS, data);
Expand All @@ -129,4 +134,12 @@ public BaseResponse deleteQuestion(@AccessTokenUser User user, @RequestParam Lon
adminService.deleteQuestion(user.getId(), questionId);
return BaseResponse.success(DELETE_QUESTION_ADMIN_SUCCESS);
}

@PostMapping("/notification")
public BaseResponse<EmptyObject> postCustomNotificationSendAdmin(@AccessTokenUser User user,
@RequestBody NotificationCustomMessage request) {
val data = notificationService.adminSendCustomNotification(user.getId(), request);

return BaseResponse.success(CREATE_VOTE_SUCCESS, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public AdminUserResponse findUser(Long adminId, Pageable page) {
return AdminUserResponse.of(totalCount, list);
}

public AdminUserResponse findUserContaining(Long adminId, Pageable page, String field, String value) {
public AdminUserResponse findUserContaining(Long adminId, Pageable page, String field,
String value) {
// exception
final User admin = userRepository.getById(adminId);
userAdminRepository.getByUser(admin);
Expand Down Expand Up @@ -185,16 +186,18 @@ public AdminCooldownResponse findCooldown(Long adminId, Pageable page) {
return AdminCooldownResponse.of(totalCount, list);
}

public AdminCooldownResponse findCooldownContaining(Long adminId, Pageable page, String yelloId) {
public AdminCooldownResponse findCooldownContaining(Long adminId, Pageable page,
String yelloId) {
// exception
final User admin = userRepository.getById(adminId);
userAdminRepository.getByUser(admin);

// logic
final Long totalCount = cooldownRepository.countAllByYelloIdContaining(yelloId);
final List<AdminCooldownContentVO> list = cooldownRepository.findAllContaining(page, yelloId).stream()
.map(AdminCooldownContentVO::of)
.toList();
final List<AdminCooldownContentVO> list =
cooldownRepository.findAllContaining(page, yelloId).stream()
.map(AdminCooldownContentVO::of)
.toList();

return AdminCooldownResponse.of(totalCount, list);
}
Expand Down Expand Up @@ -245,8 +248,10 @@ public List<Vote> createVote(Long adminId, Long questionId, AdminQuestionVoteReq
// logic
final List<Vote> result = new ArrayList<>();
request.voteContentList().forEach((voteContent -> {
final Optional<User> sender = userRepository.findByIdNotFiltered(voteContent.senderId());
final Optional<User> receiver = userRepository.findByIdNotFiltered(voteContent.receiverId());
final Optional<User> sender =
userRepository.findByIdNotFiltered(voteContent.senderId());
final Optional<User> receiver =
userRepository.findByIdNotFiltered(voteContent.receiverId());

if (sender.isPresent() && receiver.isPresent()) {
final Vote vote = Vote.createVote(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public List<QuestionForVoteResponse> findVoteQuestionList(Long userId) {
}
return true;
})
.filter(question -> !question.getId().equals(102L))
.toList();
return voteManager.generateVoteQuestion(user, questions);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.yello.server.infrastructure.firebase.dto.request;

import java.util.List;

public record NotificationCustomMessage(
List<Long> userIdList,
String title,
String message

) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public record NotificationMessage(
public static NotificationMessage toRecommendNotificationContent(User user) {
return NotificationMessage.builder()
.title("40분 대기 초기화 + 100포인트 적립")
.message(MessageFormat.format("{0}님이 나를 추천인으로 가입해 옐로하기 대기 초기화 + 100포인트가 적립되었어요!", user.getName()))
.message(MessageFormat.format("{0}님이 나를 추천인으로 가입해 옐로하기 대기 초기화 + 100포인트가 적립되었어요!",
user.getName()))
.type(NotificationType.RECOMMEND)
.build();
}
Expand All @@ -42,14 +43,25 @@ public static NotificationMessage toFriendNotificationContent(User user) {
public static NotificationMessage toYelloNotificationContent(Vote vote) {
final User sender = vote.getSender();

final String target = Gender.MALE.getIntial().equals(sender.getGender().getIntial()) ? "남학생" : "여학생";
final String target =
Gender.MALE.getIntial().equals(sender.getGender().getIntial()) ? "남학생" : "여학생";
return NotificationMessage.builder()
.title(MessageFormat.format("{0}이 쪽지를 보냈어요!", target))
.message(vote.getQuestion().toNotificationSentence())
.type(NotificationType.NEW_VOTE)
.build();
}

public static NotificationMessage toYelloNotificationCustomContent(
NotificationCustomMessage message) {

return NotificationMessage.builder()
.title(message.title())
.message(message.message())
.type(NotificationType.NEW_VOTE)
.build();
}

public Notification toNotification() {
return Notification.builder()
.setTitle(title)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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;
import com.yello.server.infrastructure.redis.repository.TokenRepository;
Expand All @@ -23,13 +26,16 @@ 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);
NotificationMessage notificationMessage =
NotificationMessage.toRecommendNotificationContent(user);

if (target.getDeviceToken() != null && !Objects.equals(target.getDeviceToken(), "")) {
final Message message = fcmManager.createMessage(target.getDeviceToken(), notificationMessage);
final Message message =
fcmManager.createMessage(target.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
}
Expand All @@ -38,12 +44,14 @@ public void sendRecommendNotification(User user, User target) {
public void sendYelloNotification(Vote vote) {
final User receiver = vote.getReceiver();

NotificationMessage notificationMessage = NotificationMessage.toYelloNotificationContent(vote);
NotificationMessage notificationMessage =
NotificationMessage.toYelloNotificationContent(vote);

final String path = "/api/v1/vote/" + vote.getId().toString();

if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(), "")) {
final Message message = fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage, path);
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage, path);
fcmManager.send(message);
}
}
Expand All @@ -53,10 +61,12 @@ public void sendFriendNotification(Friend friend) {
final User receiver = friend.getTarget();
final User sender = friend.getUser();

NotificationMessage notificationMessage = NotificationMessage.toFriendNotificationContent(sender);
NotificationMessage notificationMessage =
NotificationMessage.toFriendNotificationContent(sender);

if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(), "")) {
final Message message = fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
}
Expand All @@ -65,12 +75,47 @@ public void sendFriendNotification(Friend friend) {
public void sendVoteAvailableNotification(Long receiverId) {
final User receiveUser = userRepository.getById(receiverId);

NotificationMessage notificationMessage = NotificationMessage.toVoteAvailableNotificationContent();
NotificationMessage notificationMessage =
NotificationMessage.toVoteAvailableNotificationContent();

if (receiveUser.getDeviceToken() != null && !Objects.equals(receiveUser.getDeviceToken(), "")) {
final Message message = fcmManager.createMessage(receiveUser.getDeviceToken(), notificationMessage);
if (receiveUser.getDeviceToken() != null && !Objects.equals(receiveUser.getDeviceToken(),
"")) {
final Message message =
fcmManager.createMessage(receiveUser.getDeviceToken(), notificationMessage);
fcmManager.send(message);
log.info("[rabbitmq] successfully send notification!");
}
}

@Override
public void sendCustomNotification(NotificationCustomMessage request) {

request.userIdList().stream()
.forEach(userId -> {
final User receiver = userRepository.getById(userId);

NotificationMessage notificationMessage =
NotificationMessage.toYelloNotificationCustomContent(request);

if (receiver.getDeviceToken() != null && !Objects.equals(receiver.getDeviceToken(),
"")) {
final Message message =
fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage);
fcmManager.send(message);
}
});

}

@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,8 @@
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 @@ -13,4 +15,8 @@ public interface NotificationService {
void sendFriendNotification(Friend friend);

void sendVoteAvailableNotification(Long receiverId);

void sendCustomNotification(NotificationCustomMessage request);

EmptyObject adminSendCustomNotification(Long adminId, NotificationCustomMessage request);
}

0 comments on commit ee92854

Please sign in to comment.