-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
책을 등록하면 포인트를 얻을 수 있다.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
api/src/main/java/com/dnd/sbooky/api/point/AccumulatePointUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.dnd.sbooky.api.point; | ||
|
||
import com.dnd.sbooky.core.member.MemberEntity; | ||
import com.dnd.sbooky.core.point.PointEntity; | ||
import com.dnd.sbooky.core.point.PointPolicy; | ||
import com.dnd.sbooky.core.point.PointRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class AccumulatePointUseCase { | ||
|
||
private final PointRepository pointRepository; | ||
|
||
public void accumulate(MemberEntity member, PointPolicy pointPolicy) { | ||
int currentPoint = getCurrentPointByMemberId(member); | ||
|
||
PointEntity pointEntity = PointEntity.newInstance(member, currentPoint, pointPolicy); | ||
pointRepository.save(pointEntity); | ||
} | ||
|
||
/** | ||
* 회원 ID로 현재 포인트를 조회한다. | ||
* | ||
* @param member 회원 엔티티 | ||
* @return 회원의 현재 포인트 | ||
*/ | ||
private int getCurrentPointByMemberId(MemberEntity member) { | ||
return pointRepository.findCurrentPointByMemberId(member.getId()); | ||
} | ||
} |