-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Praise, Reliability 반영 이벤트 컨슘 User 경계가 하도록 변경
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/com/gloddy/server/user/event/consumer/UserEventConsumer.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,54 @@ | ||
package com.gloddy.server.user.event.consumer; | ||
|
||
import com.gloddy.server.auth.domain.User; | ||
import com.gloddy.server.group.event.GroupCreateEvent; | ||
import com.gloddy.server.group_member.event.GroupMemberEstimateCompleteEvent; | ||
import com.gloddy.server.group_member.event.GroupMemberLeaveEvent; | ||
import com.gloddy.server.group_member.event.GroupMemberReceivePraiseEvent; | ||
import com.gloddy.server.mate.event.MateCreateEvent; | ||
import com.gloddy.server.reliability.domain.vo.ScoreMinusType; | ||
import com.gloddy.server.reliability.domain.vo.ScorePlusType; | ||
import com.gloddy.server.reliability.domain.vo.ScoreType; | ||
import com.gloddy.server.user.domain.handler.UserQueryHandler; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.event.TransactionPhase; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UserEventConsumer { | ||
|
||
private final UserQueryHandler userQueryHandler; | ||
|
||
@EventListener | ||
public void consume(GroupMemberReceivePraiseEvent event) { | ||
User user = userQueryHandler.findById(event.getUserId()); | ||
user.receivePraise(event.getPraiseValue()); | ||
} | ||
|
||
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) | ||
public void consume(GroupCreateEvent event) { | ||
User user = userQueryHandler.findById(event.getUserId()); | ||
user.reflectReliability(ScorePlusType.Created_Group); | ||
} | ||
|
||
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) | ||
public void consume(GroupMemberEstimateCompleteEvent event) { | ||
User user = userQueryHandler.findById(event.getUserId()); | ||
user.reflectReliability(ScorePlusType.Estimated); | ||
} | ||
|
||
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) | ||
public void consume(MateCreateEvent event) { | ||
User user = userQueryHandler.findById(event.getMatedUserId()); | ||
user.reflectReliability(ScorePlusType.Mated); | ||
} | ||
|
||
@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) | ||
public void consume(GroupMemberLeaveEvent event) { | ||
User user = userQueryHandler.findById(event.getUserId()); | ||
user.reflectReliability(ScoreMinusType.Leaved_Group); | ||
} | ||
} |