Skip to content

Commit

Permalink
hotfix: add updatePushAllow
Browse files Browse the repository at this point in the history
  • Loading branch information
mushroom1324 committed Aug 16, 2024
1 parent bd6abdf commit e78b3bf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class UserFcmTokenInfo {
private Long userId;
private String fcmToken;
private Boolean pushAllow = false;

@DynamoDBHashKey
public Long getUserId() {
Expand All @@ -22,10 +23,19 @@ public String getFcmToken() {
return fcmToken;
}

public void update(String fcmToken) {
@DynamoDBAttribute
public Boolean getPushAllow() {
return pushAllow;
}

public void updateFcmToken(String fcmToken) {
this.fcmToken = fcmToken == null ? this.fcmToken : fcmToken;
}

public void updatePushAllow(Boolean pushAllow) {
this.pushAllow = pushAllow;
}

public void setUserId(Long userId) {
this.userId = userId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,27 @@ public UserFcmTokenInfo getFcmToken(Long userId) {
}

public void save(Long userId, String fcmToken) {
userFcmTokenInfoRepository.save(new UserFcmTokenInfo(userId, fcmToken));
userFcmTokenInfoRepository.save(new UserFcmTokenInfo(userId, fcmToken, false));
}

public void saveOrUpdate(Long userId, String fcmToken) {

UserFcmTokenInfo userFcmTokenInfo = userFcmTokenInfoRepository.findById(userId)
.orElse(new UserFcmTokenInfo(userId, fcmToken));
.orElse(new UserFcmTokenInfo(userId, fcmToken, false));

userFcmTokenInfo.update(fcmToken);
userFcmTokenInfo.updateFcmToken(fcmToken);

userFcmTokenInfoRepository.save(userFcmTokenInfo);

}

public void updatePushAllow(Long userId, Boolean pushAllow) {
UserFcmTokenInfo userFcmTokenInfo = userFcmTokenInfoRepository.findById(userId)
.orElseThrow(() -> new CustomException(USER_FCM_TOKEN_NOT_FOUND));
userFcmTokenInfo.updatePushAllow(pushAllow);
userFcmTokenInfoRepository.save(userFcmTokenInfo);
}

public void delete(Long userId) {
try {
userFcmTokenInfoRepository.deleteById(userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.repick.domain.user.api;

import com.example.repick.domain.fcmtoken.service.UserFcmTokenInfoService;
import com.example.repick.domain.user.dto.*;
import com.example.repick.domain.user.service.UserService;
import com.example.repick.global.jwt.TokenResponse;
Expand Down Expand Up @@ -34,6 +35,7 @@ public class UserController {
private final AppleUserService appleUserService;
private final NaverUserService naverUserService;
private final GoogleUserService googleUserService;
private final UserFcmTokenInfoService userFcmTokenInfoService;

@Operation(summary = "๊ตฌ๊ธ€ ์—‘์„ธ์Šค ํ† ํฐ์œผ๋กœ ๋‚ด๋ถ€ ํ† ํฐ ๋ฐœ๊ธ‰ํ•˜๊ธฐ",
description = """
Expand Down Expand Up @@ -264,4 +266,17 @@ public SuccessResponse<GetMyPage> getMyPage() {
return SuccessResponse.success(userService.getMyPage());
}

@Operation(summary = "ํ‘ธ์‹œ ์•Œ๋ฆผ ํ—ˆ์šฉ ์—ฌ๋ถ€ ์ˆ˜์ •ํ•˜๊ธฐ",
description = """
ํ‘ธ์‹œ ์•Œ๋ฆผ ํ—ˆ์šฉ ์—ฌ๋ถ€๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.
์š”์ฒญ๊ฐ’:
- (Query Parameter) pushAllow: ํ‘ธ์‹œ ์•Œ๋ฆผ ํ—ˆ์šฉ ์—ฌ๋ถ€
""")
@PatchMapping("/pushAllow")
public SuccessResponse<Boolean> patchPushAllow(@Parameter(name = "pushAllow", description = "ํ‘ธ์‹œ ์•Œ๋ฆผ ํ—ˆ์šฉ ์—ฌ๋ถ€", required = true)
@RequestParam boolean pushAllow) {
return SuccessResponse.success(userService.updatePushAllow(pushAllow));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,13 @@ public GetMyPage getMyPage() {
// ๋‹‰๋„ค์ž„, ํฌ์ธํŠธ, ๋ฐฐ์†ก ์ •๋ณด
return GetMyPage.of(user.getNickname(), user.getSettlement(), preparing, shipping, delivered, confirmed);
}

public Boolean updatePushAllow(boolean pushAllow) {
User user = userRepository.findByProviderId(SecurityContextHolder.getContext().getAuthentication().getName())
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));

userFcmTokenInfoService.updatePushAllow(user.getId(), pushAllow);

return true;
}
}

0 comments on commit e78b3bf

Please sign in to comment.