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

[NB-248] 사용자 약관 동의 기능 구현 #65

Merged
merged 3 commits into from
Nov 4, 2024
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
5 changes: 5 additions & 0 deletions src/main/java/com/soyeon/nubim/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public class User extends BaseEntity {
@NotNull
private Provider provider;

@Builder.Default
private Boolean privacyAgreement = false;
@Builder.Default
private Boolean serviceAgreement = false;

@Builder.Default
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
private List<Album> albums = new ArrayList<>();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/soyeon/nubim/domain/user/UserControllerV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -16,6 +17,8 @@
import com.soyeon.nubim.domain.user.dto.ProfileImageUpdateResponse;
import com.soyeon.nubim.domain.user.dto.ProfileUpdateRequest;
import com.soyeon.nubim.domain.user.dto.ProfileUpdateResponse;
import com.soyeon.nubim.domain.user.dto.TermsAgreementUpdateRequest;
import com.soyeon.nubim.domain.user.dto.TermsAgreementUpdateResponse;
import com.soyeon.nubim.domain.user.dto.UserProfileResponseDto;
import com.soyeon.nubim.security.jwt.dto.JwtTokenResponseDto;
import com.soyeon.nubim.security.oauth.AppleOAuthLoginService;
Expand Down Expand Up @@ -93,4 +96,12 @@ public ResponseEntity<Void> checkNicknameDuplication(
userService.validateDuplicatedNickname(nickname);
return ResponseEntity.ok().build();
}

@Operation(description = "개인정보 처리 방침, 서비스 이용 약관 동의 업데이트")
@PatchMapping(value = "/agreement")
public ResponseEntity<TermsAgreementUpdateResponse> updateTermsAgreement(TermsAgreementUpdateRequest request) {
TermsAgreementUpdateResponse termsAgreementUpdateResponse = userService.updateTermsAgreement(request);

return ResponseEntity.ok().body(termsAgreementUpdateResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ int updateProfile(String username, String nickname, String profileIntroduction,
@Query("UPDATE User u SET u.username = 'deleted user', u.nickname = :anonymizedNickname, u.isDeleted = true "
+ "WHERE u.userId = :userId")
int deleteAccount(Long userId, String anonymizedNickname);

@Modifying
@Query("UPDATE User u SET u.privacyAgreement = :privacyAgreement, u.serviceAgreement = :serviceAgreement"
+ " WHERE u.userId = :userId")
int updateTermsAgreement(Long userId, boolean privacyAgreement, boolean serviceAgreement);
}
29 changes: 25 additions & 4 deletions src/main/java/com/soyeon/nubim/domain/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
import com.soyeon.nubim.domain.user.dto.ProfileImageUpdateResponse;
import com.soyeon.nubim.domain.user.dto.ProfileUpdateRequest;
import com.soyeon.nubim.domain.user.dto.ProfileUpdateResponse;
import com.soyeon.nubim.domain.user.dto.TermsAgreementUpdateRequest;
import com.soyeon.nubim.domain.user.dto.TermsAgreementUpdateResponse;
import com.soyeon.nubim.domain.user.dto.UserProfileResponseDto;
import com.soyeon.nubim.domain.user.exception.DeletedUserSignupAttemptException;
import com.soyeon.nubim.domain.user.exception.InvalidNicknameFormatException;
import com.soyeon.nubim.domain.user.exception.MultipleProfileUpdateException;
import com.soyeon.nubim.domain.user.exception.MultipleUserAgreementUpdateException;
import com.soyeon.nubim.domain.user.exception.NicknameAlreadyExistsException;
import com.soyeon.nubim.domain.user.exception.NicknameNullOrEmptyException;
import com.soyeon.nubim.domain.user.exception.UnsupportedProfileImageTypeException;
import com.soyeon.nubim.domain.user.exception.UserAgreementUpdateFailException;
import com.soyeon.nubim.domain.user.exception.UserNotFoundException;
import com.soyeon.nubim.domain.user.exception.UsernameNullOrEmptyException;
import com.soyeon.nubim.domain.userfollow.UserFollowRepository;
Expand All @@ -38,8 +42,8 @@
@Service
@RequiredArgsConstructor
public class UserService {
private static final int PROFILE_UPDATE_SUCCESS = 1;
private static final int PROFILE_UPDATE_FAIL = 0;
private static final int UPDATE_SUCCESS = 1;
private static final int UPDATE_FAIL = 0;
private final UserRepository userRepository;
private final RefreshTokenService refreshTokenService;
private final AccessTokenBlacklistService accessTokenBlacklistService;
Expand Down Expand Up @@ -145,15 +149,32 @@ public ProfileUpdateResponse updateProfile(ProfileUpdateRequest updateRequest) {
int updateResult = userRepository.updateProfile(username, nickname, profileIntroduction,
phoneNumber, birthDate, gender, currentUserId);

if (updateResult == PROFILE_UPDATE_SUCCESS) {
if (updateResult == UPDATE_SUCCESS) {
return new ProfileUpdateResponse("profile update success");
}
if (updateResult == PROFILE_UPDATE_FAIL) {
if (updateResult == UPDATE_FAIL) {
return new ProfileUpdateResponse("profile update fail");
}
throw new MultipleProfileUpdateException();
}

@Transactional
public TermsAgreementUpdateResponse updateTermsAgreement(TermsAgreementUpdateRequest request){
Long userId = loggedInUserService.getCurrentUserId();
boolean privacyAgreement = request.isPrivacyAgreement();
boolean serviceAgreement = request.isServiceAgreement();

int updateResult = userRepository.updateTermsAgreement(userId, privacyAgreement, serviceAgreement);

if (updateResult == UPDATE_SUCCESS) {
return new TermsAgreementUpdateResponse("terms agreement update success");
}
if (updateResult == UPDATE_FAIL) {
throw new UserAgreementUpdateFailException();
}
throw new MultipleUserAgreementUpdateException(updateResult);
}

public void checkIfUserIsDeleted(String email) {
if (userRepository.existsByEmailAndIsDeletedTrue(email)) {
throw new DeletedUserSignupAttemptException(email);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.soyeon.nubim.domain.user.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class TermsAgreementUpdateRequest {
private boolean privacyAgreement;
private boolean serviceAgreement;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.soyeon.nubim.domain.user.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class TermsAgreementUpdateResponse {
private String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.soyeon.nubim.domain.user.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

public class MultipleUserAgreementUpdateException extends ResponseStatusException {
public MultipleUserAgreementUpdateException(int updatedCount) {
super(HttpStatus.INTERNAL_SERVER_ERROR,
String.format("Multiple users' agreements were unexpectedly updated (%d users). Only one user's agreement should be modified at a time.", updatedCount));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.soyeon.nubim.domain.user.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

public class UserAgreementUpdateFailException extends ResponseStatusException {
public UserAgreementUpdateFailException() {
super(HttpStatus.INTERNAL_SERVER_ERROR, "terms agreement update fail");
}
}