-
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.
* [#42] refactor: post like 패키지 구조 수정 * [#42] fix: 포스트 삭제 시 좋아요가 있으면 오류가 발생하는 문제 해결 * [#42] feat: 이벤트 처리 로그 AOP 구현 * [#42] chore: jacoco, sonarcloud에서 AOP 제거
- Loading branch information
1 parent
98b50d3
commit bae06f3
Showing
15 changed files
with
155 additions
and
29 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
9 changes: 8 additions & 1 deletion
9
src/main/java/com/mallang/category/domain/event/CategoryDeletedEvent.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 |
---|---|---|
@@ -1,6 +1,13 @@ | ||
package com.mallang.category.domain.event; | ||
|
||
import com.mallang.common.domain.DomainEvent; | ||
|
||
public record CategoryDeletedEvent( | ||
Long categoryId | ||
) { | ||
) implements DomainEvent { | ||
|
||
@Override | ||
public Long id() { | ||
return categoryId(); | ||
} | ||
} |
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,6 @@ | ||
package com.mallang.common.domain; | ||
|
||
public interface DomainEvent { | ||
|
||
Long id(); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/mallang/common/log/event/EventHandleLogAop.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,45 @@ | ||
package com.mallang.common.log.event; | ||
|
||
import com.mallang.common.domain.DomainEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Before; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Aspect | ||
@Component | ||
public class EventHandleLogAop { | ||
|
||
@Pointcut("@annotation(org.springframework.context.event.EventListener)") | ||
public void eventListeners() { | ||
} | ||
|
||
@Pointcut("@annotation(org.springframework.transaction.event.TransactionalEventListener)") | ||
public void transactionalEventListeners() { | ||
} | ||
|
||
@Before("(eventListeners() || transactionalEventListeners()) && args(event)") | ||
public void handleEventLog(JoinPoint joinPoint, DomainEvent event) { | ||
String className = getClassSimpleName(joinPoint); | ||
String methodName = getMethodName(joinPoint); | ||
log.info("Handle [{}(Domain Id: {})] by [{}.{}()]", | ||
event.getClass().getSimpleName(), | ||
event.id(), | ||
className, | ||
methodName); | ||
} | ||
|
||
private String getClassSimpleName(JoinPoint joinPoint) { | ||
Class<?> clazz = joinPoint.getTarget().getClass(); | ||
return clazz.getSimpleName(); | ||
} | ||
|
||
private String getMethodName(JoinPoint joinPoint) { | ||
return joinPoint.getSignature().getName(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/mallang/post/application/PostLikeEventHandler.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,23 @@ | ||
package com.mallang.post.application; | ||
|
||
import com.mallang.post.domain.PostDeleteEvent; | ||
import com.mallang.post.domain.like.PostLikeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class PostLikeEventHandler { | ||
|
||
private final PostLikeRepository postLikeRepository; | ||
|
||
@EventListener(PostDeleteEvent.class) | ||
void deletePostLike(PostDeleteEvent event) { | ||
postLikeRepository.deleteAllByPostId(event.postId()); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package com.mallang.post.domain; | ||
|
||
import com.mallang.common.domain.DomainEvent; | ||
import java.time.LocalDateTime; | ||
|
||
public record PostDeleteEvent( | ||
Long postId, | ||
LocalDateTime deletedDate | ||
) { | ||
) implements DomainEvent { | ||
|
||
public PostDeleteEvent(Long postId) { | ||
this(postId, LocalDateTime.now()); | ||
} | ||
|
||
@Override | ||
public Long id() { | ||
return postId(); | ||
} | ||
} |
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
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
3 changes: 2 additions & 1 deletion
3
...allang/post/domain/PostLikeValidator.java → ...g/post/domain/like/PostLikeValidator.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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/mallang/post/query/dao/support/PostLikeQuerySupport.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
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
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
Oops, something went wrong.