Skip to content

Commit

Permalink
Merge pull request #159 from YogitTeam/feat/user-profile
Browse files Browse the repository at this point in the history
#98 feat : 모임 참여 취소시, 호스트에게 알림
  • Loading branch information
shinhn authored Mar 24, 2023
2 parents 478786c + c902dc8 commit 051a61d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum PushType {
JOINAPPLY,
DELAPPLY,
CREATE_CLIPBOARD
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,6 +12,7 @@ public interface APNService {
ApplicationResponse<String> createApplePushNotification() throws ExecutionException, InterruptedException;

ApplicationResponse<String> createBoardUserJoinAPN(CreateBoardUserJoinAPNReq createBoardUserJoinAPNReq) throws ExecutionException, InterruptedException;
ApplicationResponse<String> delBoardUserJoinAPN(DelBoardUserJoinAPNReq delBoardUserJoinAPNReq) throws ExecutionException, InterruptedException;

ApplicationResponse<String> createClipBoardAPN(CreateClipBoardAPNReq createClipBoardAPNReq) throws ExecutionException, InterruptedException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +80,7 @@ public ApplicationResponse<String> 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();
Expand Down Expand Up @@ -114,6 +115,34 @@ public ApplicationResponse<String> createBoardUserJoinAPN(CreateBoardUserJoinAPN
return ApplicationResponse.ok("애플 푸쉬 알람 성공");
}

@Override
@Transactional
public ApplicationResponse<String> 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<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
public class DeleteUserReq {
Long userId;
String refreshToken;

//String identityToken;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -82,8 +83,7 @@ public ApplicationResponse<BoardUserRes> 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) {
Expand Down Expand Up @@ -155,6 +155,15 @@ public ApplicationResponse<Void> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ public void deleteUser(){
this.reportedCnt = null;
this.deviceToken = null;

userStatus = UserStatus.DELETE;
this.userStatus = UserStatus.DELETE;
}
}

0 comments on commit 051a61d

Please sign in to comment.