From c85532d21e6e928a5e7ff59893bb570eee363ab1 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Fri, 20 Oct 2023 10:45:29 +0900 Subject: [PATCH 1/3] feat: add user-id field --- .../repl/gifthub/auth/dto/UserInfoResponseDto.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/dto/UserInfoResponseDto.java b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/UserInfoResponseDto.java index eb426c57..b89965e0 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/dto/UserInfoResponseDto.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/dto/UserInfoResponseDto.java @@ -11,14 +11,18 @@ @Getter @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) public class UserInfoResponseDto { + private Long id; private String username; private String nickname; private List oauth; + public boolean allowNotifications; @Builder - public UserInfoResponseDto(String username, String nickname, List oauth) { + public UserInfoResponseDto(Long id, String username, String nickname, List oauth, boolean allowNotifications) { + this.id = id; this.username = username; this.nickname = nickname; this.oauth = oauth; + this.allowNotifications = allowNotifications; } } From 148a271bfece4ec93e2fcaf6c13196f5f7f15c10 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Fri, 20 Oct 2023 10:48:12 +0900 Subject: [PATCH 2/3] feat: implement find-by-user method --- .../repl/gifthub/auth/repository/DeviceTokenRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java index d6302f64..732a206c 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/repository/DeviceTokenRepository.java @@ -13,4 +13,6 @@ public interface DeviceTokenRepository extends JpaRepository Optional findByUserAndToken(User user, String token); List findAllByUser(User user); + + Optional findByUser(User user); } From 33c6d1263d6295aea6e43b9bf34851648743f2c8 Mon Sep 17 00:00:00 2001 From: Jeong-In-Hee Date: Fri, 20 Oct 2023 10:48:41 +0900 Subject: [PATCH 3/3] feat: modify read-my-info method --- .../repl/gifthub/auth/service/UserService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java index 18a30dbf..c4e26cf2 100644 --- a/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java +++ b/src/main/java/org/swmaestro/repl/gifthub/auth/service/UserService.java @@ -21,6 +21,7 @@ import org.swmaestro.repl.gifthub.auth.dto.UserUpdateResponseDto; import org.swmaestro.repl.gifthub.auth.entity.OAuth; import org.swmaestro.repl.gifthub.auth.entity.User; +import org.swmaestro.repl.gifthub.auth.repository.DeviceTokenRepository; import org.swmaestro.repl.gifthub.auth.repository.UserRepository; import org.swmaestro.repl.gifthub.auth.type.OAuthPlatform; import org.swmaestro.repl.gifthub.exception.BusinessException; @@ -34,6 +35,7 @@ public class UserService implements UserDetailsService { private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; private final OAuthService oAuthService; + private final DeviceTokenRepository deviceTokenRepository; public User passwordEncryption(User user) { return User.builder() @@ -174,10 +176,19 @@ public List deleteOAuthInfo(User user) { public UserInfoResponseDto readInfo(String username) { User user = read(username); UserInfoResponseDto userInfoResponseDto = UserInfoResponseDto.builder() + .id(user.getId()) .username(username) .nickname(user.getNickname()) .oauth(oAuthService.list(user)) + .allowNotifications(isExistDeviceToken(user)) .build(); return userInfoResponseDto; } + + /** + * DeviceToken 조회 메서드 (user) + */ + public boolean isExistDeviceToken(User user) { + return deviceTokenRepository.findByUser(user).isPresent(); + } } \ No newline at end of file