diff --git a/server/src/main/java/com/yogit/server/apns/dto/req/DelBoardUserJoinAPNReq.java b/server/src/main/java/com/yogit/server/apns/dto/req/DelBoardUserJoinAPNReq.java new file mode 100644 index 0000000..6d7ea80 --- /dev/null +++ b/server/src/main/java/com/yogit/server/apns/dto/req/DelBoardUserJoinAPNReq.java @@ -0,0 +1,28 @@ +package com.yogit.server.apns.dto.req; + +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class DelBoardUserJoinAPNReq { + + @ApiModelProperty(example = "예제 추가 예정", value = "디바이스 토큰") + @ApiParam(required = true) + private String destinationDeviceToken; + + private String delUserName; + private Long boardId; + private String boardName; + + @Builder + public DelBoardUserJoinAPNReq(String destinationDeviceToken, String delUserName, Long boardId, String boardName) { + this.destinationDeviceToken = destinationDeviceToken; + this.delUserName = delUserName; + this.boardId = boardId; + this.boardName = boardName; + } +} diff --git a/server/src/main/java/com/yogit/server/apns/entity/PushType.java b/server/src/main/java/com/yogit/server/apns/entity/PushType.java index 87c2ba7..2510128 100644 --- a/server/src/main/java/com/yogit/server/apns/entity/PushType.java +++ b/server/src/main/java/com/yogit/server/apns/entity/PushType.java @@ -2,5 +2,6 @@ public enum PushType { JOINAPPLY, + DELAPPLY, CREATE_CLIPBOARD } diff --git a/server/src/main/java/com/yogit/server/apns/service/APNService.java b/server/src/main/java/com/yogit/server/apns/service/APNService.java index 23349ae..1b4055a 100644 --- a/server/src/main/java/com/yogit/server/apns/service/APNService.java +++ b/server/src/main/java/com/yogit/server/apns/service/APNService.java @@ -2,6 +2,7 @@ import com.yogit.server.apns.dto.req.CreateBoardUserJoinAPNReq; import com.yogit.server.apns.dto.req.CreateClipBoardAPNReq; +import com.yogit.server.apns.dto.req.DelBoardUserJoinAPNReq; import com.yogit.server.global.dto.ApplicationResponse; import java.util.concurrent.ExecutionException; @@ -11,6 +12,7 @@ public interface APNService { ApplicationResponse createApplePushNotification() throws ExecutionException, InterruptedException; ApplicationResponse createBoardUserJoinAPN(CreateBoardUserJoinAPNReq createBoardUserJoinAPNReq) throws ExecutionException, InterruptedException; + ApplicationResponse delBoardUserJoinAPN(DelBoardUserJoinAPNReq delBoardUserJoinAPNReq) throws ExecutionException, InterruptedException; ApplicationResponse createClipBoardAPN(CreateClipBoardAPNReq createClipBoardAPNReq) throws ExecutionException, InterruptedException; } diff --git a/server/src/main/java/com/yogit/server/apns/service/APNServiceImpl.java b/server/src/main/java/com/yogit/server/apns/service/APNServiceImpl.java index 3c15265..2b2d8a5 100644 --- a/server/src/main/java/com/yogit/server/apns/service/APNServiceImpl.java +++ b/server/src/main/java/com/yogit/server/apns/service/APNServiceImpl.java @@ -8,6 +8,7 @@ import com.turo.pushy.apns.util.concurrent.PushNotificationFuture; import com.yogit.server.apns.dto.req.CreateBoardUserJoinAPNReq; import com.yogit.server.apns.dto.req.CreateClipBoardAPNReq; +import com.yogit.server.apns.dto.req.DelBoardUserJoinAPNReq; import com.yogit.server.apns.entity.PushType; import com.yogit.server.global.dto.ApplicationResponse; import lombok.RequiredArgsConstructor; @@ -79,7 +80,7 @@ public ApplicationResponse createBoardUserJoinAPN(CreateBoardUserJoinAPN ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder(); payloadBuilder.setAlertTitle("모임 참여 알림"); - payloadBuilder.setAlertBody(dto.getJoinUserName()+"님이 "+dto.getBoardName()+"을 신청하였습니다."); + payloadBuilder.setAlertBody(dto.getJoinUserName()+"님이 "+dto.getBoardName()+" 모임을 신청하였습니다."); payloadBuilder.addCustomProperty("boardId", dto.getBoardId()); payloadBuilder.addCustomProperty("pushType", PushType.JOINAPPLY.toString()); val payload = payloadBuilder.buildWithDefaultMaximumLength(); @@ -114,6 +115,34 @@ public ApplicationResponse createBoardUserJoinAPN(CreateBoardUserJoinAPN return ApplicationResponse.ok("애플 푸쉬 알람 성공"); } + @Override + @Transactional + public ApplicationResponse delBoardUserJoinAPN(DelBoardUserJoinAPNReq dto) throws ExecutionException, InterruptedException { + + ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder(); + payloadBuilder.setAlertTitle("모임 취소 알림"); + payloadBuilder.setAlertBody(dto.getDelUserName()+"님이 "+dto.getBoardName()+" 모임을 취소하였습니다."); + payloadBuilder.addCustomProperty("boardId", dto.getBoardId()); + payloadBuilder.addCustomProperty("pushType", PushType.DELAPPLY.toString()); + val payload = payloadBuilder.buildWithDefaultMaximumLength(); + + val token = TokenUtil.sanitizeTokenString(dto.getDestinationDeviceToken()); + val pushNotification = new SimpleApnsPushNotification(token, APP_BUNDLE_ID, payload); + PushNotificationFuture> sendNotificationFuture = apnsClient.sendNotification(pushNotification); + + // 메시지를 동기로 전송 + val response = sendNotificationFuture.get(); + + // 메시지를 비동기로 전송 + // sendNotificationFuture.addListener { future -> + // val response = future.now + // println(response); + // } + sendNotificationFuture.addListener(future -> + System.out.println("getNow는 == "+future.getNow())); + + return ApplicationResponse.ok("애플 푸쉬 알람 성공"); + } @Override @Transactional(readOnly = false) diff --git a/server/src/main/java/com/yogit/server/applelogin/model/DeleteUserReq.java b/server/src/main/java/com/yogit/server/applelogin/model/DeleteUserReq.java index 2ae5ead..3a1ed11 100644 --- a/server/src/main/java/com/yogit/server/applelogin/model/DeleteUserReq.java +++ b/server/src/main/java/com/yogit/server/applelogin/model/DeleteUserReq.java @@ -10,6 +10,4 @@ public class DeleteUserReq { Long userId; String refreshToken; - - //String identityToken; } diff --git a/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java index fc0b1d5..163496f 100644 --- a/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/boarduser/BoardUserServiceImpl.java @@ -1,6 +1,7 @@ package com.yogit.server.board.service.boarduser; import com.yogit.server.apns.dto.req.CreateBoardUserJoinAPNReq; +import com.yogit.server.apns.dto.req.DelBoardUserJoinAPNReq; import com.yogit.server.apns.service.APNService; import com.yogit.server.board.dto.request.boarduser.CreateBoardUserReq; import com.yogit.server.board.dto.response.boarduser.BoardUserRes; @@ -82,8 +83,7 @@ public ApplicationResponse joinBoardUser(CreateBoardUserReq dto) { .map(bu -> bu.getUser().getProfileImg()) .collect(Collectors.toList()); - // 호스트에게 참여 APN 푸쉬 알림 - + // 호스트에게 멤버 참여 APN 푸쉬 알림 try { if(user.getUserStatus().equals(UserStatus.LOGIN)) apnService.createBoardUserJoinAPN(new CreateBoardUserJoinAPNReq(board.getHost().getDeviceToken(), user.getName(), board.getId(), board.getTitle())); } catch (ExecutionException e) { @@ -155,6 +155,15 @@ public ApplicationResponse delBoardUser(CreateBoardUserReq dto){ boardUserRepository.deleteById(boardUser.get().getId()); + // 호스트에게 멤버 참여 취소 APN 푸쉬 알림 + try { + if(user.getUserStatus().equals(UserStatus.LOGIN)) apnService.delBoardUserJoinAPN(new DelBoardUserJoinAPNReq(board.getHost().getDeviceToken(), user.getName(), board.getId(), board.getTitle())); + } catch (ExecutionException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return ApplicationResponse.ok(); } } diff --git a/server/src/main/java/com/yogit/server/user/entity/User.java b/server/src/main/java/com/yogit/server/user/entity/User.java index f9434f3..f993080 100644 --- a/server/src/main/java/com/yogit/server/user/entity/User.java +++ b/server/src/main/java/com/yogit/server/user/entity/User.java @@ -188,6 +188,6 @@ public void deleteUser(){ this.reportedCnt = null; this.deviceToken = null; - userStatus = UserStatus.DELETE; + this.userStatus = UserStatus.DELETE; } }