-
Notifications
You must be signed in to change notification settings - Fork 29
Feature/zzambas step1 #22
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
Conversation
|
opixxx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다.~
| @@ -0,0 +1,4 @@ | |||
| package org.c4marathon.assignment.domain.dto.request; | |||
|
|
|||
| public record TransferRequest(String senderAccountNumber, String receiverAccountNumber, long money) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AccountNumber에 공백이 포함되면 어떻게 되나요?
| @@ -0,0 +1,4 @@ | |||
| package org.c4marathon.assignment.domain.dto.request; | |||
|
|
|||
| public record WithdrawRequest(String accountNumber, long money) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
money가 음수일 경우 동작이 반대로 될 것 같습니다. 전반적인 입력값 유효성 검증이 필요할 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프로그래밍 요구사항만 생각하다보니 기본 유효성 검사와 에러 처리 등을 하지 않은 것 같아요. 시간 날 때 말씀하신대로 처리해 보겠습니다!
| import lombok.NoArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log를 사용안해서 굳이 필요하지 않아보입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추후에 지우겠습니다
| public interface AccountRepository extends JpaRepository<Account, Long> { | ||
| @Modifying | ||
| @Query("UPDATE Account a SET a.balance = a.balance + :money WHERE a.accountNumber = :accountNumber AND a.balance + :money >= 0") | ||
| int addBalance(@Param("money") long money, @Param("accountNumber") String accountNumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다른 곳에선 @param을 사용안해서 통일하면 좋아보여요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스프링 데이터 JPA에서 @param을 안쓰면 에러가 나기도 한다는 것 같아서 통일하겠습니다!
| */ | ||
| @Transactional(isolation = Isolation.READ_COMMITTED) | ||
| public CreatedAccountInfo create(long userId, AccountType accountType) { | ||
| userRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
나중에 예외처리도 의미 있게 처리하면 좋을 것 같아요
hellozo0
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일일 한도를 User에 넣어서 부하를 줄이는 방법은 미처 생각해보지 못했는데 좋은 아이디어 중에 하나 인것 같습니다! 현재 step1에 조건 사항에는 맞는 방법이라 생각이 드네요
구현 방식 또한 다른 접근 방식에서 생각해볼 수 있어서 좋았습니다. 저는 최신 데이터보다는 정합성이 중요하다고 생각해서 읽기 부터 XLOCK으로 데이터를 잠그고 가져오는 방식을 생각했는데 다음 스텝때는 참고해서 개선할 수 있는것은 개선해보겠습니다! 수고하셨습니다 :)


아직 테스트 코드 작성을 하지 못했습니다.
전체적 구성
User,Account테이블을 생성했고 각각은 사용자, 계좌 정보를 뜻합니다. 사용자 정보는 간단히 구현했고 따로 인증을 하지는 않습니다.Account테이블에는 적금 계좌, 입출금 계좌 전부 들어갈 수 있고account_type컬럼으로 이를 판별합니다. (CHECKING: 입출금, INSTALLATION: 적금). 계좌번호에 unique 인덱스를 설정했습니다.User테이블에서 관리합니다. 관련 컬럼은day_withdraw_limit입니다. 이에 따라 해당 사용자의 일일 출전 금액과 마지막 출전 일시를 저장할 필요가 있다 생각해서day_withdraw컬럼과last_withdraw_date컬럼을 추가했습니다.구현사항
각 구현 사항에 대해 제 구현은 다음과 같습니다.
User테이블에서 관리하며 거래(출금, 송금) 시, 그 출금이 한도를 초과하는지 먼저 검사한 후, 처리가 됩니다.프로그래밍 요구사항
User테이블 내last_withdraw_date를 참고하고 거래 일시와 비교해 하루가 지났으면 해당 테이블 내day_withdraw를 0으로 초기화합니다. 그렇지 않으면 그대로 둡니다.문제점
아직 다음 문제가 존재합니다.