-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathPointFacade.java
More file actions
32 lines (26 loc) · 1.27 KB
/
PointFacade.java
File metadata and controls
32 lines (26 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.loopers.application.point;
import com.loopers.domain.point.PointService;
import com.loopers.domain.user.User;
import com.loopers.domain.user.UserService;
import com.loopers.support.error.CoreException;
import com.loopers.support.error.ErrorType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
@Component
public class PointFacade {
private final PointService pointService;
private final UserService userService;
@Transactional(readOnly = true)
public Long getCurrentPoint(String userId) {
User user = userService.findByUserId(userId).orElseThrow(() -> new CoreException(ErrorType.NOT_FOUND, "사용자를 찾을 수 없습니다."));
return pointService.getCurrentPoint(user.getId())
.orElseThrow(() -> new CoreException(ErrorType.NOT_FOUND, "사용자를 찾을 수 없습니다."));
}
@Transactional
public Long chargePoint(String userId, int amount) {
User user = userService.findByUserIdForUpdate(userId).orElseThrow(() -> new CoreException(ErrorType.NOT_FOUND, "사용자를 찾을 수 없습니다."));
return pointService.chargePoint(user.getId(), amount);
}
}