Skip to content
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 @@ -116,5 +116,14 @@ public ResponseEntity<?> findUserClub(@AuthenticationPrincipal CustomUserDetails
return Response.ok(new FindUserClubResponse(clubId));
}

@PutMapping("/allow/personal-information")
@Operation(summary = "개인정보 활용 동의", description = "개인정보 활용 동의를 합니다.")
@PreAuthorize("isAuthenticated()")
Comment on lines +119 to +121
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인증도 잘 챙겨서 해줬네요
Swagger도 👍👍

@SecurityRequirement(name = "BearerAuth")
public ResponseEntity<?> allowPersonalInformation(@CurrentUser CustomUserDetails user) {
userCommandService.allowPersonalInformation(user.getUserId());
return Response.ok("success allow personal information");
}


}
8 changes: 8 additions & 0 deletions backend/src/main/java/moadong/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public class User implements UserDetails {
@NotNull
private UserStatus status = UserStatus.ACTIVE;

@Builder.Default
@NotNull
private Boolean allowedPersonalInformation = false;

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return null;
Expand Down Expand Up @@ -131,4 +135,8 @@ public void removeAllRefreshTokens() {
}
this.refreshTokens.clear();
}

public void allowPersonalInformation() {
this.allowedPersonalInformation = true;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package moadong.user.payload.response;

public record LoginResponse(String accessToken,String clubId) {
public record LoginResponse(String accessToken, String clubId, Boolean allowedPersonalInformation) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public LoginResponse loginUser(UserLoginRequest userLoginRequest,

user.addRefreshToken(refreshToken);
userRepository.save(user);
return new LoginResponse(accessToken, club.getId());
return new LoginResponse(accessToken, club.getId(), user.getAllowedPersonalInformation());
} catch (MongoWriteException e) {
throw new RestApiException(ErrorCode.USER_ALREADY_EXIST);
}
Expand Down Expand Up @@ -178,6 +178,14 @@ public String findClubIdByUserId(String userID) {
return club.getId();
}

@Transactional
public void allowPersonalInformation(String userId) {
User user = userRepository.findUserByUserId(userId)
.orElseThrow(() -> new RestApiException(ErrorCode.USER_NOT_EXIST));
user.allowPersonalInformation();
userRepository.save(user);
}
Comment on lines 180 to +187
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 보면서 AI와 함께 리뷰해봤는데, 트랜잭션 내에서 조회한 영속 엔티티라면 save 없이도 변경 사항이 반영될 수 있다고 하네요
한 번 확인해보시면 좋을 것 같아요.
크게 문제 되는 부분은 아닌 것 같습니다1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

명시적으로 save를 두는게 좋아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞워요 더티 체킹 되긴하지만 명시적으로 표시하는게 햇갈리지도않구요~


private User createUser(UserRegisterRequest request, String userId, String clubId) {
User user = request.toUserEntity(passwordEncoder);
user.updateId(userId);
Expand Down
Loading