-
Notifications
You must be signed in to change notification settings - Fork 4
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
[feat/CK-242] 로드맵 관련 부분 의존성 리팩토링을 한다 #206
Changes from 1 commit
d72b469
2ea6239
91f128b
7085619
3c0ba17
354f9b6
c8fc8f4
a307525
7ce0184
b63f1b7
a0f588b
3d6cd17
df672b0
7a1b1f3
3c5fc04
9cf3c2a
bdccbbc
5cf8113
a0472bc
732673f
fc761d5
ac71f6e
3a7e610
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package co.kirikiri.roadmap.service; | ||
|
||
import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; | ||
import co.kirikiri.roadmap.service.event.RoadmapDeleteEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RoadmapReviewDeleteEventListener { | ||
|
||
private final RoadmapReviewRepository roadmapReviewRepository; | ||
private final ApplicationEventPublisher applicationEventPublisher; | ||
|
||
@EventListener(condition = "#roadmapDeleteEvent.target == 'Review'") | ||
public void handleRoadmapReviewDelete(final RoadmapDeleteEvent roadmapDeleteEvent) { | ||
deleteRoadmapReviews(roadmapDeleteEvent.roadmapId()); | ||
} | ||
|
||
private void deleteRoadmapReviews(final Long roadmapId) { | ||
roadmapReviewRepository.deleteAllByRoadmapId(roadmapId); | ||
applicationEventPublisher.publishEvent(new RoadmapDeleteEvent(roadmapId, "Roadmap")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 코드는 왜 있는건가요?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 원래 로드맵 리뷰 제거와 로드맵 제거 간의 트랜잭션을 분리해주려고 하려고 의도했어서 저렇게 했었습니다. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package co.kirikiri.roadmap.service.event; | ||
|
||
public record RoadmapDeleteEvent( | ||
Long roadmapId, | ||
String target | ||
) { | ||
} |
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.
리뷰 삭제하는 부분을 트랜잭션에서 제거하기 위해서
@EventListener
를 쓰신거죠?!리뷰가 로드맵을 외래키로 갖고 있어서 만약 이벤트 리스너에서 리뷰를 삭제하는 로직을 수행하지 못하고 에러가 났을때, 트랜잭션으로 묶여있지 않아서 로드맵 삭제하는 코드를 실행할 때 에러가 날 수도 있을 것 같아요.
썬샷이 말씀해주신 외래키 때문에 트랜잭션을 분리할 수 없다는게 맞군요..!
외래키 제약조건을 없애거나 soft delete를 하는 방식이 더 좋을수도 있겠네요! (이렇게 하자는건 아닙니다)
우선은 이대로도 좋고 썬샷이 조금 더 옳다고 판단되는 방식으로 해주시면 좋을 것 같아요 🙂