Skip to content

Commit

Permalink
Merge pull request #54 from CSID-DGU/feature/#52/agreement
Browse files Browse the repository at this point in the history
[feat] : 서비스 약관 동의 여부 등록 API 구현 (POST)
  • Loading branch information
bbbang105 authored Jun 7, 2024
2 parents 6c50682 + 7cdcdc7 commit 7f90166
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", "포트폴리오 상세 조회에 성공했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ public ResponseEntity<ApiResponse<Object>> addUserUpbitKeys(
userService.addUserUpbitKeys(authorizationHeader, userUpbitKeyRequest);
return ApiResponse.onSuccess(SuccessStatus.SUCCESS_ADD_UPBIT_KEYS);
}

// 서비스 약관 동의 여부 등록 API
@PostMapping("/agreement")
public ResponseEntity<ApiResponse<Object>> addUserAgreement(
@RequestHeader("Authorization") String authorizationHeader) {

userService.addUserAgreement(authorizationHeader);
return ApiResponse.onSuccess(SuccessStatus.SUCCESS_ADD_AGREEMENT);
}
}
8 changes: 8 additions & 0 deletions backend/src/main/java/org/dgu/backend/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Portfolio> portfolios;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

public interface UserService {
void addUserUpbitKeys(String authorizationHeader, UserDto.UserUpbitKeyRequest userUpbitKeyRequest);
void addUserAgreement(String authorizationHeader);
}
13 changes: 13 additions & 0 deletions backend/src/main/java/org/dgu/backend/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions backend/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 7f90166

Please sign in to comment.