-
Notifications
You must be signed in to change notification settings - Fork 3
[feat] SSE 알림 기능 구현 #29
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b9a4ce3
:sparkles: feat: quizId로 조회한 Quiz로 응답에 포함하는 기능 추가
LimKangHyun dab4a28
chore: Java 스타일 수정
9606b10
:sparkles: feat: Room 생성, 수정, 삭제에 대한 이벤트 리스너 추가
LimKangHyun 69c69d7
chore: Java 스타일 수정
6e1454f
:sparkles: feat: 이벤트에 대한 브로드 캐스팅 메서드 추가
LimKangHyun f87d0f1
chore: Java 스타일 수정
2d9678d
:recycle: emitter.onCompletion 부분 중괄호 삭제
LimKangHyun 32a802d
:recycle: RoomCreatedPayload Integer -> int로 통일
LimKangHyun 8683a67
chore: Java 스타일 수정
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/io/f1/backend/domain/game/event/RoomCreatedEvent.java
This file contains hidden or 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 io.f1.backend.domain.game.event; | ||
|
|
||
| import io.f1.backend.domain.game.model.Room; | ||
| import io.f1.backend.domain.quiz.entity.Quiz; | ||
|
|
||
| public record RoomCreatedEvent(Room room, Quiz quiz) {} |
3 changes: 3 additions & 0 deletions
3
backend/src/main/java/io/f1/backend/domain/game/event/RoomDeletedEvent.java
This file contains hidden or 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,3 @@ | ||
| package io.f1.backend.domain.game.event; | ||
|
|
||
| public record RoomDeletedEvent(Long roomId) {} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/io/f1/backend/domain/game/event/RoomUpdatedEvent.java
This file contains hidden or 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 io.f1.backend.domain.game.event; | ||
|
|
||
| import io.f1.backend.domain.game.model.Room; | ||
| import io.f1.backend.domain.quiz.entity.Quiz; | ||
|
|
||
| public record RoomUpdatedEvent(Room room, Quiz quiz) {} |
This file contains hidden or 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: 3 additions & 0 deletions
3
backend/src/main/java/io/f1/backend/domain/game/sse/dto/LobbySseEvent.java
This file contains hidden or 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,3 @@ | ||
| package io.f1.backend.domain.game.sse.dto; | ||
|
|
||
| public record LobbySseEvent<T>(String type, T payload) {} | ||
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/io/f1/backend/domain/game/sse/dto/RoomCreatedPayload.java
This file contains hidden or 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,14 @@ | ||
| package io.f1.backend.domain.game.sse.dto; | ||
|
|
||
| public record RoomCreatedPayload( | ||
| Long roomId, | ||
| String roomName, | ||
| int maxUserCount, | ||
| int currentUserCount, | ||
| boolean locked, | ||
dlsrks1021 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String roomState, | ||
| String quizTitle, | ||
| String description, | ||
| String creator, | ||
| int numberOfQuestion, | ||
| String thumbnailUrl) {} | ||
3 changes: 3 additions & 0 deletions
3
backend/src/main/java/io/f1/backend/domain/game/sse/dto/RoomDeletedPayload.java
This file contains hidden or 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,3 @@ | ||
| package io.f1.backend.domain.game.sse.dto; | ||
|
|
||
| public record RoomDeletedPayload(Long roomId) {} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/io/f1/backend/domain/game/sse/dto/RoomUpdatedPayload.java
This file contains hidden or 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,11 @@ | ||
| package io.f1.backend.domain.game.sse.dto; | ||
|
|
||
| public record RoomUpdatedPayload( | ||
| Long roomId, | ||
| int currentUserCount, | ||
| String roomState, | ||
| String quizTitle, | ||
| String description, | ||
| String creator, | ||
| int numberOfQuestion, | ||
| String thumbnailUrl) {} |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/io/f1/backend/domain/game/sse/dto/SseEventType.java
This file contains hidden or 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,7 @@ | ||
| package io.f1.backend.domain.game.sse.dto; | ||
|
|
||
| public enum SseEventType { | ||
| CREATE, | ||
| UPDATE, | ||
| DELETE | ||
| } |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/io/f1/backend/domain/game/sse/listener/RoomCreatedEventListener.java
This file contains hidden or 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,28 @@ | ||
| package io.f1.backend.domain.game.sse.listener; | ||
|
|
||
| import static io.f1.backend.domain.game.sse.mapper.SseMapper.*; | ||
|
|
||
| import io.f1.backend.domain.game.event.RoomCreatedEvent; | ||
| import io.f1.backend.domain.game.sse.app.SseService; | ||
| import io.f1.backend.domain.game.sse.dto.LobbySseEvent; | ||
| import io.f1.backend.domain.game.sse.dto.RoomCreatedPayload; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class RoomCreatedEventListener { | ||
|
|
||
| private final SseService sseService; | ||
|
|
||
| @Async | ||
| @EventListener | ||
| public void roomCreate(RoomCreatedEvent event) { | ||
| LobbySseEvent<RoomCreatedPayload> sseEvent = fromRoomCreated(event); | ||
| sseService.notifyLobbyUpdate(sseEvent); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/io/f1/backend/domain/game/sse/listener/RoomDeletedEventListener.java
This file contains hidden or 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,26 @@ | ||
| package io.f1.backend.domain.game.sse.listener; | ||
|
|
||
| import static io.f1.backend.domain.game.sse.mapper.SseMapper.*; | ||
|
|
||
| import io.f1.backend.domain.game.event.RoomDeletedEvent; | ||
| import io.f1.backend.domain.game.sse.app.SseService; | ||
| import io.f1.backend.domain.game.sse.dto.LobbySseEvent; | ||
| import io.f1.backend.domain.game.sse.dto.RoomDeletedPayload; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.scheduling.annotation.Async; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class RoomDeletedEventListener { | ||
|
|
||
| private final SseService sseService; | ||
|
|
||
| @Async | ||
| @EventListener | ||
| public void roomDelete(RoomDeletedEvent event) { | ||
| LobbySseEvent<RoomDeletedPayload> sseEvent = fromRoomDeleted(event); | ||
| sseService.notifyLobbyUpdate(sseEvent); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/io/f1/backend/domain/game/sse/listener/RoomUpdatedEventListener.java
This file contains hidden or 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,25 @@ | ||
| package io.f1.backend.domain.game.sse.listener; | ||
|
|
||
| import io.f1.backend.domain.game.event.RoomUpdatedEvent; | ||
| import io.f1.backend.domain.game.sse.app.SseService; | ||
| import io.f1.backend.domain.game.sse.dto.LobbySseEvent; | ||
| import io.f1.backend.domain.game.sse.dto.RoomUpdatedPayload; | ||
| import io.f1.backend.domain.game.sse.mapper.SseMapper; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.scheduling.annotation.Async; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class RoomUpdatedEventListener { | ||
|
|
||
| private final SseService sseService; | ||
|
|
||
| @Async | ||
| @EventListener | ||
| public void roomUpdate(RoomUpdatedEvent event) { | ||
| LobbySseEvent<RoomUpdatedPayload> sseEvent = SseMapper.fromRoomUpdated(event); | ||
| sseService.notifyLobbyUpdate(sseEvent); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
backend/src/main/java/io/f1/backend/domain/game/sse/mapper/SseMapper.java
This file contains hidden or 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,56 @@ | ||
| package io.f1.backend.domain.game.sse.mapper; | ||
|
|
||
| import io.f1.backend.domain.game.event.RoomCreatedEvent; | ||
| import io.f1.backend.domain.game.event.RoomDeletedEvent; | ||
| import io.f1.backend.domain.game.event.RoomUpdatedEvent; | ||
| import io.f1.backend.domain.game.model.Room; | ||
| import io.f1.backend.domain.game.sse.dto.LobbySseEvent; | ||
| import io.f1.backend.domain.game.sse.dto.RoomCreatedPayload; | ||
| import io.f1.backend.domain.game.sse.dto.RoomDeletedPayload; | ||
| import io.f1.backend.domain.game.sse.dto.RoomUpdatedPayload; | ||
| import io.f1.backend.domain.game.sse.dto.SseEventType; | ||
| import io.f1.backend.domain.quiz.entity.Quiz; | ||
|
|
||
| public class SseMapper { | ||
|
|
||
| public static LobbySseEvent<RoomCreatedPayload> fromRoomCreated(RoomCreatedEvent event) { | ||
| Room room = event.room(); | ||
| Quiz quiz = event.quiz(); | ||
| RoomCreatedPayload payload = | ||
| new RoomCreatedPayload( | ||
| room.getId(), | ||
| room.getRoomSetting().roomName(), | ||
| room.getRoomSetting().maxUserCount(), | ||
| room.getPlayerSessionMap().size(), | ||
| room.getRoomSetting().locked(), | ||
| room.getState().name(), | ||
| quiz.getTitle(), | ||
| quiz.getDescription(), | ||
| quiz.getCreator().getNickname(), | ||
| quiz.getQuestions().size(), | ||
| quiz.getThumbnailUrl()); | ||
| return new LobbySseEvent<>(SseEventType.CREATE.name(), payload); | ||
| } | ||
|
|
||
| public static LobbySseEvent<RoomUpdatedPayload> fromRoomUpdated(RoomUpdatedEvent event) { | ||
| Room room = event.room(); | ||
| Quiz quiz = event.quiz(); | ||
| RoomUpdatedPayload payload = | ||
| new RoomUpdatedPayload( | ||
| room.getId(), | ||
| room.getPlayerSessionMap().size(), | ||
| room.getState().name(), | ||
| quiz.getTitle(), | ||
| quiz.getDescription(), | ||
| quiz.getCreator().getNickname(), | ||
| quiz.getQuestions().size(), | ||
| quiz.getThumbnailUrl()); | ||
| return new LobbySseEvent<>(SseEventType.UPDATE.name(), payload); | ||
| } | ||
|
|
||
| public static LobbySseEvent<RoomDeletedPayload> fromRoomDeleted(RoomDeletedEvent event) { | ||
| Long roomId = event.roomId(); | ||
| RoomDeletedPayload payload = new RoomDeletedPayload(roomId); | ||
| return new LobbySseEvent<>(SseEventType.DELETE.name(), payload); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.