Skip to content

Commit cce37c4

Browse files
author
github-actions
committed
chore: Java 스타일 수정
1 parent e25f2f2 commit cce37c4

File tree

6 files changed

+62
-68
lines changed

6 files changed

+62
-68
lines changed

backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void enterRoom(RoomValidationRequest request) {
119119
}
120120

121121
if (room.getRoomSetting().locked()
122-
&& !room.getRoomSetting().password().equals(request.password())) {
122+
&& !room.getRoomSetting().password().equals(request.password())) {
123123
throw new CustomException(RoomErrorCode.WRONG_PASSWORD);
124124
}
125125

@@ -141,12 +141,12 @@ public void initializeRoomSocket(Long roomId, String sessionId, UserPrincipal pr
141141
Quiz quiz = quizService.getQuizWithQuestionsById(quizId);
142142

143143
GameSettingResponse gameSettingResponse =
144-
toGameSettingResponse(room.getGameSetting(), quiz);
144+
toGameSettingResponse(room.getGameSetting(), quiz);
145145

146146
PlayerListResponse playerListResponse = toPlayerListResponse(room);
147147

148148
SystemNoticeResponse systemNoticeResponse =
149-
ofPlayerEvent(player.getNickname(), RoomEventType.ENTER);
149+
ofPlayerEvent(player.getNickname(), RoomEventType.ENTER);
150150

151151
String destination = getDestination(roomId);
152152

@@ -182,7 +182,7 @@ public void exitRoom(Long roomId, String sessionId, UserPrincipal principal) {
182182
removePlayer(room, sessionId, removePlayer);
183183

184184
SystemNoticeResponse systemNoticeResponse =
185-
ofPlayerEvent(removePlayer.nickname, RoomEventType.EXIT);
185+
ofPlayerEvent(removePlayer.nickname, RoomEventType.EXIT);
186186

187187
PlayerListResponse playerListResponse = toPlayerListResponse(room);
188188

@@ -193,9 +193,9 @@ public void exitRoom(Long roomId, String sessionId, UserPrincipal principal) {
193193

194194
public void handlePlayerReady(Long roomId, String sessionId) {
195195
Player player =
196-
roomRepository
197-
.findPlayerInRoomBySessionId(roomId, sessionId)
198-
.orElseThrow(() -> new CustomException(RoomErrorCode.PLAYER_NOT_FOUND));
196+
roomRepository
197+
.findPlayerInRoomBySessionId(roomId, sessionId)
198+
.orElseThrow(() -> new CustomException(RoomErrorCode.PLAYER_NOT_FOUND));
199199

200200
player.toggleReady();
201201

@@ -209,15 +209,15 @@ public void handlePlayerReady(Long roomId, String sessionId) {
209209
public RoomListResponse getAllRooms() {
210210
List<Room> rooms = roomRepository.findAll();
211211
List<RoomResponse> roomResponses =
212-
rooms.stream()
213-
.map(
214-
room -> {
215-
Long quizId = room.getGameSetting().getQuizId();
216-
Quiz quiz = quizService.getQuizWithQuestionsById(quizId);
217-
218-
return toRoomResponse(room, quiz);
219-
})
220-
.toList();
212+
rooms.stream()
213+
.map(
214+
room -> {
215+
Long quizId = room.getGameSetting().getQuizId();
216+
Quiz quiz = quizService.getQuizWithQuestionsById(quizId);
217+
218+
return toRoomResponse(room, quiz);
219+
})
220+
.toList();
221221
return new RoomListResponse(roomResponses);
222222
}
223223

@@ -242,14 +242,14 @@ public void chat(Long roomId, String sessionId, ChatMessage chatMessage) {
242242
room.increasePlayerCorrectCount(sessionId);
243243

244244
messageSender.send(
245-
destination,
246-
MessageType.QUESTION_RESULT,
247-
toQuestionResultResponse(chatMessage.nickname(), answer));
245+
destination,
246+
MessageType.QUESTION_RESULT,
247+
toQuestionResultResponse(chatMessage.nickname(), answer));
248248
messageSender.send(destination, MessageType.RANK_UPDATE, toRankUpdateResponse(room));
249249
messageSender.send(
250-
destination,
251-
MessageType.SYSTEM_NOTICE,
252-
ofPlayerEvent(chatMessage.nickname(), RoomEventType.CORRECT_ANSWER));
250+
destination,
251+
MessageType.SYSTEM_NOTICE,
252+
ofPlayerEvent(chatMessage.nickname(), RoomEventType.CORRECT_ANSWER));
253253

254254
timerService.cancelTimer(room);
255255

@@ -264,29 +264,29 @@ public void chat(Long roomId, String sessionId, ChatMessage chatMessage) {
264264
// 타이머 추가하기
265265
timerService.startTimer(room, CONTINUE_DELAY);
266266
messageSender.send(
267-
destination,
268-
MessageType.QUESTION_START,
269-
toQuestionStartResponse(room, CONTINUE_DELAY));
267+
destination,
268+
MessageType.QUESTION_START,
269+
toQuestionStartResponse(room, CONTINUE_DELAY));
270270
}
271271
}
272272

273273
public void reconnectSession(
274-
Long roomId, String oldSessionId, String newSessionId, UserPrincipal principal) {
274+
Long roomId, String oldSessionId, String newSessionId, UserPrincipal principal) {
275275
Room room = findRoom(roomId);
276276
room.reconnectSession(oldSessionId, newSessionId);
277277

278278
String destination = getDestination(roomId);
279279

280280
messageSender.send(
281-
destination,
282-
MessageType.SYSTEM_NOTICE,
283-
ofPlayerEvent(principal.getUserNickname(), RoomEventType.RECONNECT));
281+
destination,
282+
MessageType.SYSTEM_NOTICE,
283+
ofPlayerEvent(principal.getUserNickname(), RoomEventType.RECONNECT));
284284

285285
if (room.isPlaying()) {
286286
// todo 현재 round 및 타이머 ..
287287
// todo 랭킹 리스트
288288
messageSender.send(
289-
destination, MessageType.GAME_START, toGameStartResponse(room.getQuestions()));
289+
destination, MessageType.GAME_START, toGameStartResponse(room.getQuestions()));
290290

291291
} else {
292292

@@ -296,7 +296,7 @@ public void reconnectSession(
296296
Quiz quiz = quizService.getQuizWithQuestionsById(quizId);
297297

298298
GameSettingResponse gameSettingResponse =
299-
toGameSettingResponse(room.getGameSetting(), quiz);
299+
toGameSettingResponse(room.getGameSetting(), quiz);
300300

301301
PlayerListResponse playerListResponse = toPlayerListResponse(room);
302302

@@ -342,8 +342,8 @@ private Player createPlayer() {
342342

343343
private Room findRoom(Long roomId) {
344344
return roomRepository
345-
.findRoom(roomId)
346-
.orElseThrow(() -> new CustomException(RoomErrorCode.ROOM_NOT_FOUND));
345+
.findRoom(roomId)
346+
.orElseThrow(() -> new CustomException(RoomErrorCode.ROOM_NOT_FOUND));
347347
}
348348

349349
private void removeRoom(Room room) {
@@ -357,16 +357,16 @@ private void changeHost(Room room, String hostSessionId) {
357357
Map<String, Player> playerSessionMap = room.getPlayerSessionMap();
358358

359359
Optional<String> nextHostSessionId =
360-
playerSessionMap.entrySet().stream()
361-
.filter(entry -> !entry.getKey().equals(hostSessionId))
362-
.filter(entry -> entry.getValue().getState() == ConnectionState.CONNECTED)
363-
.map(Map.Entry::getKey)
364-
.findFirst();
360+
playerSessionMap.entrySet().stream()
361+
.filter(entry -> !entry.getKey().equals(hostSessionId))
362+
.filter(entry -> entry.getValue().getState() == ConnectionState.CONNECTED)
363+
.map(Map.Entry::getKey)
364+
.findFirst();
365365

366366
Player nextHost =
367-
playerSessionMap.get(
368-
nextHostSessionId.orElseThrow(
369-
() -> new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND)));
367+
playerSessionMap.get(
368+
nextHostSessionId.orElseThrow(
369+
() -> new CustomException(RoomErrorCode.SOCKET_SESSION_NOT_FOUND)));
370370

371371
room.updateHost(nextHost);
372372
log.info("user_id:{} 방장 변경 완료 ", nextHost.getId());

backend/src/main/java/io/f1/backend/domain/game/model/Room.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ public boolean isExit(String sessionId) {
134134
}
135135

136136
public boolean isLastPlayer(String sessionId) {
137-
long connectedCount = playerSessionMap.values().stream()
138-
.filter(player -> player.getState() == ConnectionState.CONNECTED)
139-
.count();
137+
long connectedCount =
138+
playerSessionMap.values().stream()
139+
.filter(player -> player.getState() == ConnectionState.CONNECTED)
140+
.count();
140141
return connectedCount == 1 && playerSessionMap.containsKey(sessionId);
141142
}
142143
}

backend/src/main/java/io/f1/backend/domain/game/websocket/controller/GameSocketController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ public void initializeRoomSocket(@DestinationVariable Long roomId, Message<?> me
3939
if (!roomService.isExit(oldSessionId, roomId)) {
4040
roomService.reconnectSession(roomId, oldSessionId, websocketSessionId, principal);
4141
}
42-
}else{
42+
} else {
4343
roomService.initializeRoomSocket(roomId, websocketSessionId, principal);
4444
}
45-
4645
}
4746

4847
@MessageMapping("/room/exit/{roomId}")
@@ -64,8 +63,8 @@ public void gameStart(@DestinationVariable Long roomId, Message<?> message) {
6463

6564
@MessageMapping("room/chat/{roomId}")
6665
public void chat(
67-
@DestinationVariable Long roomId,
68-
Message<DefaultWebSocketRequest<ChatMessage>> message) {
66+
@DestinationVariable Long roomId,
67+
Message<DefaultWebSocketRequest<ChatMessage>> message) {
6968

7069
roomService.chat(roomId, getSessionId(message), message.getPayload().getMessage());
7170
}

backend/src/main/java/io/f1/backend/domain/game/websocket/eventlistener/WebsocketEventListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
import io.f1.backend.domain.game.websocket.service.SessionService;
88
import io.f1.backend.domain.user.dto.UserPrincipal;
9+
910
import lombok.RequiredArgsConstructor;
1011
import lombok.extern.slf4j.Slf4j;
12+
1113
import org.springframework.context.event.EventListener;
1214
import org.springframework.messaging.Message;
1315
import org.springframework.stereotype.Component;
@@ -47,10 +49,9 @@ public void handleSubscribeListener(SessionSubscribeEvent event) {
4749
if (subscribeType[2].equals("room")) {
4850
Long roomId = Long.parseLong(subscribeType[3]);
4951
sessionService.addRoomId(roomId, sessionId);
50-
}
52+
}
5153
}
5254

53-
5455
@EventListener
5556
public void handleDisconnectedListener(SessionDisconnectEvent event) {
5657

backend/src/main/java/io/f1/backend/domain/game/websocket/service/SessionService.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public void addRoomId(Long roomId, String sessionId) {
3434
sessionIdRoom.put(sessionId, roomId);
3535
}
3636

37-
public boolean hasOldSessionId(Long userId){
37+
public boolean hasOldSessionId(Long userId) {
3838
return userIdLatestSession.get(userId) != null;
3939
}
4040

41-
public String getOldSessionId(Long userId){
41+
public String getOldSessionId(Long userId) {
4242
return userIdLatestSession.get(userId);
4343
}
4444

@@ -59,15 +59,15 @@ public void handleUserDisconnect(String sessionId, UserPrincipal principal) {
5959

6060
// 5초 뒤 실행
6161
scheduler.schedule(
62-
() -> {
63-
/* 재연결 실패 */
64-
if (sessionId.equals(userIdSession.get(userId))) {
65-
roomService.exitIfNotPlaying(roomId, sessionId, principal);
66-
}
67-
removeSession(sessionId, userId);
68-
},
69-
5,
70-
TimeUnit.SECONDS);
62+
() -> {
63+
/* 재연결 실패 */
64+
if (sessionId.equals(userIdSession.get(userId))) {
65+
roomService.exitIfNotPlaying(roomId, sessionId, principal);
66+
}
67+
removeSession(sessionId, userId);
68+
},
69+
5,
70+
TimeUnit.SECONDS);
7171
}
7272

7373
public void removeSession(String sessionId, Long userId) {
@@ -80,5 +80,4 @@ public void removeSession(String sessionId, Long userId) {
8080

8181
userIdLatestSession.remove(userId);
8282
}
83-
8483
}

backend/src/test/java/io/f1/backend/domain/game/websocket/SessionServiceTests.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package io.f1.backend.domain.game.websocket;
22

33
import static org.junit.jupiter.api.Assertions.*;
4-
import static org.mockito.ArgumentMatchers.any;
5-
import static org.mockito.ArgumentMatchers.anyLong;
6-
import static org.mockito.ArgumentMatchers.anyString;
74
import static org.mockito.ArgumentMatchers.eq;
8-
import static org.mockito.Mockito.never;
95
import static org.mockito.Mockito.times;
106
import static org.mockito.Mockito.verify;
11-
import static org.mockito.Mockito.when;
127

138
import io.f1.backend.domain.game.app.RoomService;
149
import io.f1.backend.domain.game.model.ConnectionState;
@@ -85,7 +80,6 @@ void addRoomId_shouldAddSessionAndRoom() {
8580
assertEquals(roomId1, sessionIdRoom.get(sessionId1));
8681
}
8782

88-
8983
@Test
9084
@DisplayName("handleUserDisconnect: 연결 끊김 상태이고 재연결되지 않았으면 exitIfNotPlaying 호출")
9185
void handleUserDisconnect_shouldExitIfNotPlayingIfDisconnected() throws InterruptedException {

0 commit comments

Comments
 (0)