Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main Merge #147

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading