Skip to content

Commit

Permalink
Hotfix-push token delete 변경 (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
yummygyudon authored Nov 16, 2023
2 parents c492924 + 6425716 commit 5af82eb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public class PushTokenService {
private String apiKey;


@Transactional(readOnly = true)
public boolean isExistDeviceToken(Long userId, String token) {
return pushTokenRepository.existsByUserIdAndToken(userId, token);
}

@Transactional(readOnly = true)
public PushToken getDeviceToken(Long userId, String token) {
return pushTokenRepository.findByUserIdAndToken(userId, token)
Expand Down Expand Up @@ -97,22 +102,20 @@ public PushTokenResponse.StatusResponse deleteDeviceToken(PushToken pushToken) {
.message(e.getResponseMessage())
.build();
}

}

@Transactional
public Integer deleteAllDeviceTokenOf(User user) {
public void deleteAllDeviceTokenOf(User user) {
// 기존에 저장되어 있던 Tokens -> 알림 서버에 삭제 요청
List<PushToken> userTokens = pushTokenRepository.findAllByUserId(user.getId());
int failedCount = 0;
for (PushToken token : userTokens) {
PushTokenResponse.StatusResponse statusResponse = deleteDeviceToken(token);
if (!statusResponse.getSuccess()) {
failedCount += 1;
if (!userTokens.isEmpty()) {
for (PushToken token : userTokens) {
deleteDeviceToken(token);
}
// 우선 서비스 DB에 있는 모든 토큰 지워버리기
pushTokenRepository.deleteAll(userTokens);
}
// 우선 서비스 DB에 있는 모든 토큰 지워버리기
pushTokenRepository.deleteAll(userTokens);
return failedCount;
}

private HttpHeaders createHeadersFor(String action, String platform) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ public ResponseEntity<PushTokenResponse.StatusResponse> deletePushToken(
@AuthenticationPrincipal User user,
@Valid @RequestBody PushTokenRequest.DeleteRequest deletePushTokenRequest
) {
PushToken targetPushToken = pushTokenService.getDeviceToken(
user.getId(), deletePushTokenRequest.getPushToken()
);
val result = pushTokenService.deleteDeviceToken(targetPushToken);
val response = pushTokenResponseMapper.ofStatus(result);
return ResponseEntity.status(HttpStatus.OK).body(response);
if (pushTokenService.isExistDeviceToken(user.getId(), deletePushTokenRequest.getPushToken())) {
PushToken targetPushToken = pushTokenService.getDeviceToken(
user.getId(), deletePushTokenRequest.getPushToken()
);
pushTokenService.deleteDeviceToken(targetPushToken);
}
return ResponseEntity.status(HttpStatus.OK).body(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public ResponseEntity<PushTokenResponse.StatusResponse> logout(
@AuthenticationPrincipal User user,
@Valid @RequestBody PushTokenRequest.DeleteRequest deleteRequest
) {
PushToken targetPushToken = pushTokenService.getDeviceToken(
user.getId(), deleteRequest.getPushToken()
);
// val result =
pushTokenService.deleteDeviceToken(targetPushToken);
// val response = pushTokenResponseMapper.ofStatus(result);
if (pushTokenService.isExistDeviceToken(user.getId(), deleteRequest.getPushToken())) {
PushToken targetPushToken = pushTokenService.getDeviceToken(
user.getId(), deleteRequest.getPushToken()
);
pushTokenService.deleteDeviceToken(targetPushToken);
}
return ResponseEntity.status(HttpStatus.OK).body(null);
}

Expand Down

0 comments on commit 5af82eb

Please sign in to comment.