Skip to content

Commit b19232f

Browse files
committed
feature: 사용자 액션 추적 이벤트 추가 및 좋아요 이벤트 확장
- `UserActionTrackEvent` 인터페이스 추가로 사용자 활동 추적 기반 도메인 설계 도입. - `LikeActionTrackEvent` 구현체 추가로 좋아요/취소 이벤트 데이터 추적 가능. - `LikeFacade`에 사용자 활동 이벤트 발행 로직 추가. - 이벤트 기반 아키텍처와 데이터 추적 연계 강화.
1 parent 60b3112 commit b19232f

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/event/DeadLetterQueueProcessor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import com.loopers.domain.event.DomainEvent;
55
import com.loopers.domain.event.FailedEvent;
66
import com.loopers.infrastructure.event.FailedEventRepository;
7-
import java.util.List;
87
import lombok.RequiredArgsConstructor;
8+
import lombok.extern.slf4j.Slf4j;
99
import org.springframework.context.ApplicationEventPublisher;
1010
import org.springframework.scheduling.annotation.Scheduled;
1111
import org.springframework.stereotype.Component;
1212
import org.springframework.transaction.annotation.Transactional;
1313

14+
import java.util.List;
15+
1416
@Component
1517
@RequiredArgsConstructor
1618
public class DeadLetterQueueProcessor {
@@ -22,7 +24,7 @@ public class DeadLetterQueueProcessor {
2224
private static final int MAX_RETRY_COUNT = 5;
2325

2426
@Scheduled(fixedRate = 300000)
25-
@Transactional
27+
@Transactional
2628
public void retryFailedEvents() {
2729

2830
List<FailedEvent> eventsToRetry = failedEventRepository.findByRetryCountLessThan(MAX_RETRY_COUNT);
@@ -39,7 +41,7 @@ public void retryFailedEvents() {
3941
failedEventRepository.delete(failedEvent);
4042

4143
} catch (Exception e) {
42-
failedEvent.incrementRetryCount();
44+
failedEvent.incrementRetryCount();
4345
failedEventRepository.save(failedEvent);
4446
}
4547
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.loopers.application.like;
2+
3+
import com.loopers.domain.event.UserActionTrackEvent;
4+
import java.time.ZonedDateTime;
5+
import java.util.Map;
6+
7+
public record LikeActionTrackEvent(
8+
Long userId,
9+
Long productId,
10+
String action,
11+
12+
ZonedDateTime eventTime,
13+
Map<String, Object> properties
14+
15+
) implements UserActionTrackEvent {
16+
17+
public LikeActionTrackEvent(Long userId, Long productId, String action) {
18+
this(userId, productId, action, ZonedDateTime.now(), Map.of());
19+
}
20+
21+
@Override
22+
public String eventType() {
23+
return "LIKE_ACTION";
24+
}
25+
26+
@Override
27+
public Map<String, Object> getProperties() {
28+
return properties;
29+
}
30+
}

apps/commerce-api/src/main/java/com/loopers/application/like/LikeFacade.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public LikeInfo like(long userId, long productId) {
3131

3232
eventPublisher.publishEvent(new LikeCreatedEvent(productId, 1));
3333

34+
eventPublisher.publishEvent(new LikeActionTrackEvent(
35+
userId,
36+
productId,
37+
"LIKE"
38+
));
39+
3440
return LikeInfo.from(newLike, product.getLikeCount());
3541
}
3642

@@ -41,6 +47,12 @@ public int unLike(long userId, long productId) {
4147

4248
eventPublisher.publishEvent(new LikeCreatedEvent(productId, -1));
4349

50+
eventPublisher.publishEvent(new LikeActionTrackEvent(
51+
userId,
52+
productId,
53+
"UNLIKE"
54+
));
55+
4456
return productService.getProduct(productId).getLikeCount();
4557

4658
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.loopers.domain.event;
2+
3+
import java.time.ZonedDateTime;
4+
import java.util.Map;
5+
6+
public interface UserActionTrackEvent {
7+
Long userId();
8+
String eventType();
9+
ZonedDateTime eventTime();
10+
Map<String, Object> getProperties();
11+
}

0 commit comments

Comments
 (0)