Skip to content

Commit

Permalink
Refactor: User restCash Type : int -> Long
Browse files Browse the repository at this point in the history
  • Loading branch information
Taekgil99 committed Dec 1, 2022
1 parent 0afc908 commit d0bf8c8
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ResponseEntity charge(@CurrentUser CustomUserDetails authUser, @RequestBo
User user = userRepository.findById(userId).orElseThrow(MemberNotFound::new);
Payment payment = paymentMapper.paymentRequestToPayment(paymentRequest);
int price = payment.getAmount();
int newRestCash = pointService.addCash(user, price, PointType.AddPoint);
Long newRestCash = pointService.addCash(user, price, PointType.AddPoint);
// JsonNode jsonNode = paymentService.create(payment);

return new ResponseEntity(HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public class PointController {
private final OrderRepository orderRepository;

@PostMapping
public ResponseEntity<Integer> charge(@CurrentUser CustomUserDetails authUser, @RequestBody PointChargeDto pointChargeDto) {
public ResponseEntity<Long> charge(@CurrentUser CustomUserDetails authUser, @RequestBody PointChargeDto pointChargeDto) {
Long userId = authUser.getUser().getUserId();
User user = userRepository.findById(userId).orElseThrow(MemberNotFound::new);
int price = pointChargeDto.getPrice();
PointType pointType = pointChargeDto.getPointType();
int newRestCash = pointService.addCash(user, price, pointType);
return new ResponseEntity<Integer>(newRestCash, HttpStatus.OK);
Long newRestCash = pointService.addCash(user, price, pointType);
return new ResponseEntity<>(newRestCash, HttpStatus.OK);
}

@GetMapping
public ResponseEntity find(@CurrentUser CustomUserDetails authUser) {
User user = userRepository.findById(authUser.getUser().getUserId()).orElseThrow(MemberNotFound::new);
int restCash = pointService.getRestCash(user);
Long restCash = pointService.getRestCash(user);

return new ResponseEntity<>(restCash, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class PointService {
private final PointMapper mapper;

@Transactional
public Integer addCash(User user, int price, PointType pointType) {
public Long addCash(User user, int price, PointType pointType) {
PointHistory pointHistory = addPointHistory(user, price, pointType);
log.info("service / ํฌ์ธํŠธ ์‚ฌ์šฉ ๋ฐ ์ถฉ์ „ ์‹œ์ž‘");
int newRestCash = user.getRestCash() + price;
Long newRestCash = user.getRestCash() + price;
user.setRestCash(newRestCash);
userRepository.save(user);

Expand All @@ -61,15 +61,15 @@ public PointHistory addPointHistory(User user, int price, PointType pointType) {
return pointHistory;
}

public int getRestCash(User user) {
public Long getRestCash(User user) {
return user.getRestCash();
}

@Transactional
public void pay(Order order, Long userId) {
log.info("service / ํฌ์ธํŠธ๋กœ ์ƒํ’ˆ๊ฒฐ์ œ ์‹œ์ž‘");
User user = userRepository.findById(userId).orElseThrow(() -> new BusinessLogicException(ExceptionCode.USER_NOT_FOUND));
int restCash = user.getRestCash();
Long restCash = user.getRestCash();
int payPrice = order.getOrderTotalPrice();
if (payPrice > restCash) {
throw new BusinessLogicException(ExceptionCode.NOT_ENOUGH_POINT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PointHistory {
@Column(nullable = false)
private LocalDateTime createdAt;

private int restCash;
private Long restCash;


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PointResponseDto {
long pointHistoryId;
int cash;
private PointType pointType;
int restCash;
Long restCash;
private String createdAt;

public PointResponseDto(PointHistory pointHistory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class User extends Auditable {
// @Column(nullable = false)
// private String about;

@Column(nullable = true)
@Column
private String userRole;

@Column(nullable = false)
Expand All @@ -65,8 +65,7 @@ public class User extends Auditable {
private String username;

@Column
@ColumnDefault("-1")
private int restCash;
private Long restCash;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Order> orders = new ArrayList<>();
Expand All @@ -88,7 +87,7 @@ public User(String email,
String socialLogin,
String zipCode,
String address,
int restCash) {
Long restCash) {
this.email = email;
this.password = password;
this.nickname = nickname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public class UserResponseDto {
private String zipCode;
private String phone;
private String username;
private int restCash;
private Long restCash;

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public User saveOrUpdate(OAuthAttributes attributes) {
user.setPassword(passwordEncoder.encode(user.getNickname()));
}

if (user.getRestCash() == -1) {
user.setRestCash(0);
if (user.getRestCash() == null) {
user.setRestCash(0L);
pointService.addCash(user, 1000000, PointType.SignUpPoint);
log.info("ํšŒ์›๊ฐ€์ž… ํฌ์ธํŠธ ์ง€๊ธ‰");
}
Expand Down

0 comments on commit d0bf8c8

Please sign in to comment.