2626import io .f1 .backend .domain .game .dto .response .RoomResponse ;
2727import io .f1 .backend .domain .game .dto .response .RoomSettingResponse ;
2828import io .f1 .backend .domain .game .dto .response .SystemNoticeResponse ;
29+ import io .f1 .backend .domain .game .event .RoomCreatedEvent ;
2930import io .f1 .backend .domain .game .model .GameSetting ;
3031import io .f1 .backend .domain .game .model .Player ;
3132import io .f1 .backend .domain .game .model .Room ;
@@ -67,7 +68,8 @@ public class RoomService {
6768 public RoomCreateResponse saveRoom (RoomCreateRequest request ) {
6869
6970 QuizMinData quizMinData = quizService .getQuizMinData ();
70- // Quiz quiz = quizService.getQuizWithQuestionsById(quizMinId);
71+
72+ Quiz quiz = quizService .findQuizById (quizMinData .quizMinId ());
7173
7274 GameSetting gameSetting = toGameSetting (quizMinData );
7375
@@ -83,7 +85,7 @@ public RoomCreateResponse saveRoom(RoomCreateRequest request) {
8385
8486 roomRepository .saveRoom (room );
8587
86- // eventPublisher.publishEvent(new RoomCreatedEvent(room, quiz));
88+ eventPublisher .publishEvent (new RoomCreatedEvent (room , quiz ));
8789
8890 return new RoomCreateResponse (newId );
8991 }
@@ -108,7 +110,7 @@ public void enterRoom(RoomValidationRequest request) {
108110 }
109111
110112 if (room .getRoomSetting ().locked ()
111- && !room .getRoomSetting ().password ().equals (request .password ())) {
113+ && !room .getRoomSetting ().password ().equals (request .password ())) {
112114 throw new CustomException (RoomErrorCode .WRONG_PASSWORD );
113115 }
114116
@@ -117,7 +119,7 @@ public void enterRoom(RoomValidationRequest request) {
117119 }
118120
119121 public RoomInitialData initializeRoomSocket (
120- Long roomId , String sessionId , UserPrincipal principal ) {
122+ Long roomId , String sessionId , UserPrincipal principal ) {
121123
122124 Room room = findRoom (roomId );
123125
@@ -143,15 +145,15 @@ public RoomInitialData initializeRoomSocket(
143145 Quiz quiz = quizService .getQuizWithQuestionsById (quizId );
144146
145147 GameSettingResponse gameSettingResponse =
146- toGameSettingResponse (room .getGameSetting (), quiz );
148+ toGameSettingResponse (room .getGameSetting (), quiz );
147149
148150 PlayerListResponse playerListResponse = toPlayerListResponse (room );
149151
150152 SystemNoticeResponse systemNoticeResponse =
151- ofPlayerEvent (player .getNickname (), RoomEventType .ENTER );
153+ ofPlayerEvent (player .getNickname (), RoomEventType .ENTER );
152154
153155 return new RoomInitialData (
154- roomSettingResponse , gameSettingResponse , playerListResponse , systemNoticeResponse );
156+ roomSettingResponse , gameSettingResponse , playerListResponse , systemNoticeResponse );
155157 }
156158
157159 public RoomExitData exitRoom (Long roomId , String sessionId , UserPrincipal principal ) {
@@ -177,7 +179,7 @@ public RoomExitData exitRoom(Long roomId, String sessionId, UserPrincipal princi
177179 removePlayer (room , sessionId , removePlayer );
178180
179181 SystemNoticeResponse systemNoticeResponse =
180- ofPlayerEvent (removePlayer .nickname , RoomEventType .EXIT );
182+ ofPlayerEvent (removePlayer .nickname , RoomEventType .EXIT );
181183
182184 PlayerListResponse playerListResponse = toPlayerListResponse (room );
183185
@@ -187,9 +189,9 @@ public RoomExitData exitRoom(Long roomId, String sessionId, UserPrincipal princi
187189
188190 public PlayerListResponse handlePlayerReady (Long roomId , String sessionId ) {
189191 Player player =
190- roomRepository
191- .findPlayerInRoomBySessionId (roomId , sessionId )
192- .orElseThrow (() -> new CustomException (RoomErrorCode .PLAYER_NOT_FOUND ));
192+ roomRepository
193+ .findPlayerInRoomBySessionId (roomId , sessionId )
194+ .orElseThrow (() -> new CustomException (RoomErrorCode .PLAYER_NOT_FOUND ));
193195
194196 player .toggleReady ();
195197
@@ -201,15 +203,15 @@ public PlayerListResponse handlePlayerReady(Long roomId, String sessionId) {
201203 public RoomListResponse getAllRooms () {
202204 List <Room > rooms = roomRepository .findAll ();
203205 List <RoomResponse > roomResponses =
204- rooms .stream ()
205- .map (
206- room -> {
207- Long quizId = room .getGameSetting ().getQuizId ();
208- Quiz quiz = quizService .getQuizWithQuestionsById (quizId );
209-
210- return toRoomResponse (room , quiz );
211- })
212- .toList ();
206+ rooms .stream ()
207+ .map (
208+ room -> {
209+ Long quizId = room .getGameSetting ().getQuizId ();
210+ Quiz quiz = quizService .getQuizWithQuestionsById (quizId );
211+
212+ return toRoomResponse (room , quiz );
213+ })
214+ .toList ();
213215 return new RoomListResponse (roomResponses );
214216 }
215217
@@ -232,12 +234,12 @@ public RoundResult chat(Long roomId, String sessionId, ChatMessage chatMessage)
232234 room .increasePlayerCorrectCount (sessionId );
233235
234236 return RoundResult .builder ()
235- .questionResult (
236- toQuestionResultResponse (currentQuestion .getId (), chatMessage , answer ))
237- .rankUpdate (toRankUpdateResponse (room ))
238- .systemNotice (ofPlayerEvent (chatMessage .nickname (), RoomEventType .ENTER ))
239- .chat (chatMessage )
240- .build ();
237+ .questionResult (
238+ toQuestionResultResponse (currentQuestion .getId (), chatMessage , answer ))
239+ .rankUpdate (toRankUpdateResponse (room ))
240+ .systemNotice (ofPlayerEvent (chatMessage .nickname (), RoomEventType .ENTER ))
241+ .chat (chatMessage )
242+ .build ();
241243 }
242244
243245 private Player getRemovePlayer (Room room , String sessionId , UserPrincipal principal ) {
@@ -259,8 +261,8 @@ private Player createPlayer() {
259261
260262 private Room findRoom (Long roomId ) {
261263 return roomRepository
262- .findRoom (roomId )
263- .orElseThrow (() -> new CustomException (RoomErrorCode .ROOM_NOT_FOUND ));
264+ .findRoom (roomId )
265+ .orElseThrow (() -> new CustomException (RoomErrorCode .ROOM_NOT_FOUND ));
264266 }
265267
266268 private boolean isLastPlayer (Room room , String sessionId ) {
@@ -280,14 +282,14 @@ private void changeHost(Room room, String hostSessionId) {
280282 Map <String , Player > playerSessionMap = room .getPlayerSessionMap ();
281283
282284 Optional <String > nextHostSessionId =
283- playerSessionMap .keySet ().stream ()
284- .filter (key -> !key .equals (hostSessionId ))
285- .findFirst ();
285+ playerSessionMap .keySet ().stream ()
286+ .filter (key -> !key .equals (hostSessionId ))
287+ .findFirst ();
286288
287289 Player nextHost =
288- playerSessionMap .get (
289- nextHostSessionId .orElseThrow (
290- () -> new CustomException (RoomErrorCode .SOCKET_SESSION_NOT_FOUND )));
290+ playerSessionMap .get (
291+ nextHostSessionId .orElseThrow (
292+ () -> new CustomException (RoomErrorCode .SOCKET_SESSION_NOT_FOUND )));
291293
292294 room .updateHost (nextHost );
293295 log .info ("user_id:{} 방장 변경 완료 " , nextHost .getId ());
@@ -301,4 +303,4 @@ private void removePlayer(Room room, String sessionId, Player removePlayer) {
301303 private RoundResult buildResultOnlyChat (ChatMessage chatMessage ) {
302304 return RoundResult .builder ().chat (chatMessage ).build ();
303305 }
304- }
306+ }
0 commit comments