-
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.
Feat: 허브 태그 자동 생성 이벤트 리스너를 구현한다.
- Loading branch information
Showing
6 changed files
with
138 additions
and
5 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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/seong/shoutlink/domain/link/service/event/CreateHubLinkEvent.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,37 @@ | ||
package com.seong.shoutlink.domain.link.service.event; | ||
|
||
import java.util.Objects; | ||
|
||
public class CreateHubLinkEvent extends CreateLinkEvent { | ||
|
||
private final Long hubId; | ||
|
||
public CreateHubLinkEvent(Long linkId, String url, Long hubId) { | ||
super(linkId, url); | ||
this.hubId = hubId; | ||
} | ||
|
||
public Long hubId() { | ||
return hubId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
CreateHubLinkEvent that = (CreateHubLinkEvent) o; | ||
return Objects.equals(hubId, that.hubId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), hubId); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/seong/shoutlink/domain/link/service/event/CreateMemberLinkEvent.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,37 @@ | ||
package com.seong.shoutlink.domain.link.service.event; | ||
|
||
import java.util.Objects; | ||
|
||
public class CreateMemberLinkEvent extends CreateLinkEvent{ | ||
|
||
private final Long memberId; | ||
|
||
public CreateMemberLinkEvent(Long linkId, String url, Long memberId) { | ||
super(linkId, url); | ||
this.memberId = memberId; | ||
} | ||
|
||
public Long memberId() { | ||
return memberId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
CreateMemberLinkEvent that = (CreateMemberLinkEvent) o; | ||
return Objects.equals(memberId, that.memberId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), memberId); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/seong/shoutlink/global/event/TagEventListener.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,35 @@ | ||
package com.seong.shoutlink.global.event; | ||
|
||
import com.seong.shoutlink.domain.exception.ErrorCode; | ||
import com.seong.shoutlink.domain.exception.ShoutLinkException; | ||
import com.seong.shoutlink.domain.link.service.event.CreateHubLinkEvent; | ||
import com.seong.shoutlink.domain.tag.service.TagService; | ||
import com.seong.shoutlink.domain.tag.service.request.AutoCreateTagCommand; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class TagEventListener { | ||
|
||
private final TagService tagService; | ||
|
||
@TransactionalEventListener | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
public void createHubTags(CreateHubLinkEvent event) { | ||
AutoCreateTagCommand command = new AutoCreateTagCommand(event.hubId()); | ||
try { | ||
tagService.autoCreateHubTags(command); | ||
log.debug("[Tag] 링크 개수가 최소 태그 자동 생성 조건을 만족"); | ||
} catch (ShoutLinkException e) { | ||
if(e.getErrorCode().equals(ErrorCode.NOT_MET_CONDITION)) { | ||
log.debug("[Tag] 링크 개수가 최소 태그 자동 생성 조건을 만족하지 않음"); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} |