Skip to content
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

[Feature]: 그룹 생성 이벤트를 외부 시스템에 발행한다. #164

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ApplyPayloadApi {
@GetMapping("/applies/{applyId}")
public ResponseEntity<ApplyPayload> getApplyPayload(
@PathVariable("applyId") Long applyId,
@RequestParam("eventType") ApplyEventType eventType
@RequestParam(value = "eventType", required = false) ApplyEventType eventType
) {
ApplyPayload response = applyPayloadService.getPayload(applyId, eventType);
return ResponseEntity.ok(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class GroupPayloadApi {
@GetMapping("/groups/{groupId}")
public ResponseEntity<GroupPayload> getGroupPayload(
@PathVariable("groupId") Long groupId,
@RequestParam("eventType") GroupPayloadEventType eventType
@RequestParam(value = "eventType", required = false) GroupPayloadEventType eventType
) {
GroupPayload response = groupPayloadService.getGroupPayload(groupId, eventType);
return ApiResponse.ok(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class GroupCreateEvent implements Event {
private Long userId;
private Long groupId;
}
2 changes: 2 additions & 0 deletions src/main/java/com/gloddy/server/messaging/sns/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public enum Topic {
APPLY_APPROVE("지원서가 승인 처리 되었을 때", "apply-topic"),
APPLY_REFUSE("지원서가 거절 처리 되었을 때", "apply-topic"),

CREATE_GROUP("그룹이 생성 되었을 때", "group-topic"),

CREATE_GENERAL_ARTICLE("그룹 일반 게시글이 생성될 떄", "group-article-topic"),
CREATE_NOTICE_ARTICLE("그룹 공지글이 생성될 때", "group-article-topic"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@AllArgsConstructor
@Getter
public enum GroupEventType {

CREATE_GROUP("모임이 생성될 때"),
APPROACHING_GROUP("모임 시작이 임박할 때"),
END_GROUP("모임이 완료됏을 때");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gloddy.server.article.event.GroupArticleCreateEvent;
import com.gloddy.server.batch.group.event.GroupApproachingEvent;
import com.gloddy.server.batch.group.event.GroupEndEvent;
import com.gloddy.server.group.event.GroupCreateEvent;
import com.gloddy.server.group_member.event.GroupMemberLeaveEvent;
import com.gloddy.server.outbox.adapter.group.event.GroupAdapterEvent;
import com.gloddy.server.outbox.adapter.group.event.GroupArticleAdapterEvent;
Expand All @@ -21,6 +22,12 @@ public class GroupAdapterEventHandler {

private final OutboxEventSaveService outboxEventSaveService;

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handle(GroupCreateEvent event) {
GroupAdapterEvent adapterEvent = GroupEventMapper.mapToGroupAdapterEvent(event);
outboxEventSaveService.save(adapterEvent);
}

@TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT)
public void handle(GroupArticleCreateEvent event) {
GroupArticleAdapterEvent adapterEvent = GroupEventMapper.mapToGroupArticleAdapterEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gloddy.server.article.event.GroupArticleCreateEvent;
import com.gloddy.server.batch.group.event.GroupApproachingEvent;
import com.gloddy.server.batch.group.event.GroupEndEvent;
import com.gloddy.server.group.event.GroupCreateEvent;
import com.gloddy.server.group_member.event.GroupMemberLeaveEvent;
import com.gloddy.server.outbox.adapter.group.event.GroupAdapterEvent;
import com.gloddy.server.outbox.adapter.group.event.GroupArticleAdapterEvent;
Expand Down Expand Up @@ -46,4 +47,12 @@ public static GroupAdapterEvent mapToGroupAdapterEvent(GroupEndEvent event) {
LocalDateTime.now()
);
}

public static GroupAdapterEvent mapToGroupAdapterEvent(GroupCreateEvent event) {
return new GroupAdapterEvent(
event.getGroupId(),
GroupEventType.CREATE_GROUP,
LocalDateTime.now()
);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/gloddy/server/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Group saveGroup(GroupFactory groupFactory, GroupEventProducer groupEventP
GroupCommandHandler groupCommandHandler, GroupRequest.Create groupInfo) {
Group group = groupCommandHandler.save(groupFactory.getGroupFrom(this, groupInfo));

groupEventProducer.produceEvent(new GroupCreateEvent(this.getId()));
groupEventProducer.produceEvent(new GroupCreateEvent(this.getId() ,group.getId()));
groupEventProducer.produceEvent(new GroupParticipateEvent(this.getId(), group.getId()));
return group;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spring:
group-article-topic: ${GROUP_ARTICLE_TOPIC}
group-status-topic: ${GROUP_STATUS_TOPIC}
user-topic: ${USER_TOPIC}
group-topic: ${GROUP_TOPIC}

logging:
level:
Expand Down
Loading