Skip to content

Commit 9cbb99c

Browse files
committed
feat: 사용자 행동 상태 로깅
- 상품 조회 시 - 좋아요 클릭 시
1 parent bd1a567 commit 9cbb99c

6 files changed

Lines changed: 24 additions & 13 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.loopers.application.like;
22

3+
import com.loopers.application.product.UserActionEvent;
4+
import com.loopers.domain.actionlog.ActionType;
35
import com.loopers.domain.like.Like;
46
import com.loopers.domain.like.LikeRepository;
57
import com.loopers.domain.product.ProductRepository;
@@ -45,6 +47,7 @@ public LikeInfo doLike(LikeV1Dto.LikeRequest request) {
4547
likeRepository.save(newLike);
4648

4749
publisher.publishEvent(new LikeCreateEvent(userId, productId));
50+
publisher.publishEvent(new UserActionEvent(userId, productId, ActionType.DO_LIKE));
4851

4952
return LikeInfo.from(newLike);
5053
});

apps/commerce-api/src/main/java/com/loopers/application/product/ProductFacade.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.loopers.application.product;
22

3+
import com.loopers.domain.actionlog.ActionType;
34
import com.loopers.domain.brand.BrandRepository;
45
import com.loopers.domain.product.Product;
56
import com.loopers.domain.product.ProductRepository;
@@ -55,7 +56,8 @@ public ProductInfo findProductById(Long id) {
5556
() -> new CoreException(ErrorType.NOT_FOUND, "찾고자 하는 상품이 존재하지 않습니다.")
5657
);
5758

58-
publisher.publishEvent(new ProductLookedUpEvent(product.getId()));
59+
// 유저 ID는 임시로 하드 코딩했습니다. 추후 인증/인가 기능이 추가되면 수정할 예정입니다.
60+
publisher.publishEvent(new UserActionEvent(1L, product.getId(), ActionType.PRODUCT_LOOKED_UP));
5961

6062
return ProductInfo.from(product);
6163
}

apps/commerce-api/src/main/java/com/loopers/application/product/ProductLookedUpEvent.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.loopers.application.product;
2+
3+
import com.loopers.domain.actionlog.ActionType;
4+
5+
public record UserActionEvent(
6+
Long userId,
7+
Long productId,
8+
ActionType actionType
9+
) {
10+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.loopers.domain.actionlog;
22

33
public enum ActionType {
4-
PRODUCT_LOOKUP,
4+
PRODUCT_LOOKED_UP,
55
DO_LIKE,
66
CREATE_ORDER
77
}

apps/commerce-api/src/main/java/com/loopers/domain/actionlog/UserActionLog.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.loopers.domain.actionlog;
22

3-
import com.loopers.application.product.ProductLookedUpEvent;
3+
import com.loopers.application.product.UserActionEvent;
44
import com.loopers.domain.BaseEntity;
55
import jakarta.persistence.*;
66
import lombok.AccessLevel;
@@ -17,9 +17,8 @@ public class UserActionLog extends BaseEntity {
1717
@GeneratedValue(strategy = GenerationType.IDENTITY)
1818
private Long id;
1919

20-
/*
21-
유저는 추후 추가 예정
22-
*/
20+
@Column(name = "user_id", nullable = false)
21+
private Long userId;
2322

2423
@Column(name = "product_id", nullable = false)
2524
private Long productId;
@@ -28,12 +27,13 @@ public class UserActionLog extends BaseEntity {
2827
@Column(name = "action_type", nullable = false)
2928
private ActionType actionType;
3029

31-
public UserActionLog(Long productId, ActionType actionType) {
30+
public UserActionLog(Long userId, Long productId, ActionType actionType) {
31+
this.userId = userId;
3232
this.productId = productId;
3333
this.actionType = actionType;
3434
}
3535

36-
public static UserActionLog create(ProductLookedUpEvent event) {
37-
return new UserActionLog(event.productId(), event.actionType());
36+
public static UserActionLog create(UserActionEvent event) {
37+
return new UserActionLog(event.userId(), event.productId(), event.actionType());
3838
}
3939
}

0 commit comments

Comments
 (0)