diff --git a/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java b/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java index c6ce9e1..5d22f5c 100644 --- a/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java +++ b/backend/src/main/java/org/dgu/backend/common/constant/SuccessStatus.java @@ -23,6 +23,7 @@ public enum SuccessStatus implements BaseCode { SUCCESS_GET_RECENT_BACKTESTING_RESULT(HttpStatus.OK, "200", "백테스팅 최근 결과 조회에 성공했습니다."), // User SUCCESS_LOGOUT(HttpStatus.OK, "200", "유저 로그아웃에 성공했습니다."), + SUCCESS_ADD_AGREEMENT(HttpStatus.CREATED, "201", "서비스 약관 동의 여부 등록에 성공했습니다."), // Portfolio SUCCESS_GET_PORTFOLIOS(HttpStatus.OK, "200", "포트폴리오 조회에 성공했습니다."), SUCCESS_GET_PORTFOLIO_DETAILS(HttpStatus.OK, "200", "포트폴리오 상세 조회에 성공했습니다."), diff --git a/backend/src/main/java/org/dgu/backend/controller/UserController.java b/backend/src/main/java/org/dgu/backend/controller/UserController.java index 73c268d..730d9ce 100644 --- a/backend/src/main/java/org/dgu/backend/controller/UserController.java +++ b/backend/src/main/java/org/dgu/backend/controller/UserController.java @@ -23,4 +23,13 @@ public ResponseEntity> addUserUpbitKeys( userService.addUserUpbitKeys(authorizationHeader, userUpbitKeyRequest); return ApiResponse.onSuccess(SuccessStatus.SUCCESS_ADD_UPBIT_KEYS); } + + // 서비스 약관 동의 여부 등록 API + @PostMapping("/agreement") + public ResponseEntity> addUserAgreement( + @RequestHeader("Authorization") String authorizationHeader) { + + userService.addUserAgreement(authorizationHeader); + return ApiResponse.onSuccess(SuccessStatus.SUCCESS_ADD_AGREEMENT); + } } \ No newline at end of file diff --git a/backend/src/main/java/org/dgu/backend/domain/User.java b/backend/src/main/java/org/dgu/backend/domain/User.java index 096044c..7b54a0f 100644 --- a/backend/src/main/java/org/dgu/backend/domain/User.java +++ b/backend/src/main/java/org/dgu/backend/domain/User.java @@ -32,6 +32,9 @@ public class User extends BaseEntity { @Column(name = "current_portfolios_uuid", columnDefinition = "BINARY(16)") private UUID currentPortfolioId; + @Column(name = "is_agree", nullable = false) + private Boolean isAgree; + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) private List portfolios; @@ -47,5 +50,10 @@ public User(UUID userId, String name, String provider, String providerId) { this.name = name; this.provider = provider; this.providerId = providerId; + this.isAgree = false; + } + + public void updateAgreement() { + this.isAgree = true; } } \ No newline at end of file diff --git a/backend/src/main/java/org/dgu/backend/exception/UserErrorResult.java b/backend/src/main/java/org/dgu/backend/exception/UserErrorResult.java index a749e6b..4abdf7e 100644 --- a/backend/src/main/java/org/dgu/backend/exception/UserErrorResult.java +++ b/backend/src/main/java/org/dgu/backend/exception/UserErrorResult.java @@ -9,7 +9,8 @@ @Getter @RequiredArgsConstructor public enum UserErrorResult implements BaseErrorCode { - NOT_FOUND_USER(HttpStatus.NOT_FOUND, "404", "존재하지 않는 유저입니다."); + NOT_FOUND_USER(HttpStatus.NOT_FOUND, "404", "존재하지 않는 유저입니다."), + ALREADY_AGREED(HttpStatus.CONFLICT, "409", "이미 서비스 약관 동의를 한 유저입니다."); private final HttpStatus httpStatus; private final String code; diff --git a/backend/src/main/java/org/dgu/backend/service/UserService.java b/backend/src/main/java/org/dgu/backend/service/UserService.java index 205d02d..6ca9dde 100644 --- a/backend/src/main/java/org/dgu/backend/service/UserService.java +++ b/backend/src/main/java/org/dgu/backend/service/UserService.java @@ -4,4 +4,5 @@ public interface UserService { void addUserUpbitKeys(String authorizationHeader, UserDto.UserUpbitKeyRequest userUpbitKeyRequest); + void addUserAgreement(String authorizationHeader); } \ No newline at end of file diff --git a/backend/src/main/java/org/dgu/backend/service/UserServiceImpl.java b/backend/src/main/java/org/dgu/backend/service/UserServiceImpl.java index ffdd4ae..93016f5 100644 --- a/backend/src/main/java/org/dgu/backend/service/UserServiceImpl.java +++ b/backend/src/main/java/org/dgu/backend/service/UserServiceImpl.java @@ -5,6 +5,8 @@ import org.dgu.backend.domain.UpbitKey; import org.dgu.backend.domain.User; import org.dgu.backend.dto.UserDto; +import org.dgu.backend.exception.UserErrorResult; +import org.dgu.backend.exception.UserException; import org.dgu.backend.repository.UpbitKeyRepository; import org.dgu.backend.util.AESUtil; import org.dgu.backend.util.EncryptionUtil; @@ -37,6 +39,17 @@ public void addUserUpbitKeys(String authorizationHeader, UserDto.UserUpbitKeyReq saveUpbitKey(user, encodedAccessKey, encodedSecretKey, encryptedPrivateKey, existUpbitKey); } + // 서비스 약관 동의 여부를 등록하는 메서드 + @Override + public void addUserAgreement(String authorizationHeader) { + User user = jwtUtil.getUserFromHeader(authorizationHeader); + // 이미 등록한 경우 + if (user.getIsAgree()) { + throw new UserException(UserErrorResult.ALREADY_AGREED); + } + user.updateAgreement(); + } + // 암호화 및 인코딩 메서드 private String encryptAndEncode(String data, KeyPair keyPair) { byte[] encryptedData = encryptionUtil.encrypt(data.getBytes(), keyPair.getPublic()); diff --git a/backend/src/main/resources/data.sql b/backend/src/main/resources/data.sql index 394b0de..5c2936f 100644 --- a/backend/src/main/resources/data.sql +++ b/backend/src/main/resources/data.sql @@ -15,8 +15,8 @@ INSERT INTO candles (candles_id, candles_name, korean_name) VALUES ON DUPLICATE KEY UPDATE candles_id = candles_id; -- 테스트 유저 삽입 -INSERT INTO users (users_id, name, provider, provider_id, users_uuid, created_at, updated_at) -VALUES (1, '테스트1', 'kakao', '3471511962', UNHEX(REPLACE('159f4542-ebff-4acd-a603-a4fb4c94526c', '-', '')), LOCALTIMESTAMP, LOCALTIMESTAMP), - (2, '테스트2', 'kakao', '3471511963', UNHEX(REPLACE('159f4542-ebff-4acd-a603-a4fb4c94526d', '-', '')), LOCALTIMESTAMP, LOCALTIMESTAMP), - (3, '테스트3', 'kakao', '3471511964', UNHEX(REPLACE('159f4542-ebff-4acd-a603-a4fb4c94526e', '-', '')), LOCALTIMESTAMP, LOCALTIMESTAMP) +INSERT INTO users (users_id, name, provider, provider_id, users_uuid, is_agree, created_at, updated_at) +VALUES (1, '테스트1', 'kakao', '3471511962', UNHEX(REPLACE('159f4542-ebff-4acd-a603-a4fb4c94526c', '-', '')), false, LOCALTIMESTAMP, LOCALTIMESTAMP), + (2, '테스트2', 'kakao', '3471511963', UNHEX(REPLACE('159f4542-ebff-4acd-a603-a4fb4c94526d', '-', '')), false, LOCALTIMESTAMP, LOCALTIMESTAMP), + (3, '테스트3', 'kakao', '3471511964', UNHEX(REPLACE('159f4542-ebff-4acd-a603-a4fb4c94526e', '-', '')), false, LOCALTIMESTAMP, LOCALTIMESTAMP) ON DUPLICATE KEY UPDATE name = VALUES(name); \ No newline at end of file