Skip to content

Commit

Permalink
Add notification agreement field in user-info-dto (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
inh2613 authored Oct 20, 2023
2 parents d515126 + 33c6d12 commit 73ec806
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
@Getter
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class UserInfoResponseDto {
private Long id;
private String username;
private String nickname;
private List<OAuthUserInfoDto> oauth;
public boolean allowNotifications;

@Builder
public UserInfoResponseDto(String username, String nickname, List<OAuthUserInfoDto> oauth) {
public UserInfoResponseDto(Long id, String username, String nickname, List<OAuthUserInfoDto> oauth, boolean allowNotifications) {
this.id = id;
this.username = username;
this.nickname = nickname;
this.oauth = oauth;
this.allowNotifications = allowNotifications;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface DeviceTokenRepository extends JpaRepository<DeviceToken, Long>
Optional<DeviceToken> findByUserAndToken(User user, String token);

List<DeviceToken> findAllByUser(User user);

Optional<DeviceToken> findByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -174,10 +176,19 @@ public List<OAuth> 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();
}
}

0 comments on commit 73ec806

Please sign in to comment.