-
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.
Browse files
Browse the repository at this point in the history
Refactor/#14 : 로깅, 예외처리, 소켓 to API
- Loading branch information
Showing
25 changed files
with
315 additions
and
182 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
6 changes: 3 additions & 3 deletions
6
...e/common/client/ContentServiceClient.java → .../client/content/ContentServiceClient.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
2 changes: 1 addition & 1 deletion
2
...service/common/client/dto/ContentRes.java → ...common/client/content/dto/ContentRes.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
7 changes: 7 additions & 0 deletions
7
src/main/java/io/urdego/urdego_game_service/common/client/user/UserServiceClient.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,7 @@ | ||
package io.urdego.urdego_game_service.common.client.user; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
|
||
@FeignClient(name = "user-service", url = "${feign.client.config.service.url}") | ||
public interface UserServiceClient { | ||
} |
36 changes: 16 additions & 20 deletions
36
src/main/java/io/urdego/urdego_game_service/common/config/WebSocketConfig.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 |
---|---|---|
@@ -1,24 +1,20 @@ | ||
package io.urdego.urdego_game_service.common.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
||
@Configuration | ||
@EnableWebSocketMessageBroker | ||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
registry.enableSimpleBroker("/game-service/sub"); | ||
registry.setApplicationDestinationPrefixes("/game-service/pub"); | ||
} | ||
|
||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
registry.addEndpoint("/game-service/connect") | ||
.setAllowedOrigins("*"); | ||
} | ||
} | ||
//@Configuration | ||
//@EnableWebSocketMessageBroker | ||
//public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
// | ||
// @Override | ||
// public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
// registry.enableSimpleBroker("/game-service/sub"); | ||
// registry.setApplicationDestinationPrefixes("/game-service/pub"); | ||
// } | ||
// | ||
// @Override | ||
// public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
// registry.addEndpoint("/game-service/connect") | ||
// .setAllowedOrigins("*"); | ||
// } | ||
//} |
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
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
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
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
44 changes: 19 additions & 25 deletions
44
src/main/java/io/urdego/urdego_game_service/controller/room/RoomSocketController.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 |
---|---|---|
@@ -1,38 +1,32 @@ | ||
package io.urdego.urdego_game_service.controller.room; | ||
|
||
import io.urdego.urdego_game_service.controller.room.dto.request.ContentSelectReq; | ||
import io.urdego.urdego_game_service.controller.room.dto.request.PlayerReq; | ||
import io.urdego.urdego_game_service.controller.room.dto.response.PlayerRes; | ||
import io.urdego.urdego_game_service.domain.room.service.RoomService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class RoomSocketController { | ||
|
||
private final RoomService roomService; | ||
private final SimpMessagingTemplate messagingTemplate; | ||
|
||
// 친구 초대 | ||
@MessageMapping("/room/player/invite") | ||
public void invitePlayer(PlayerReq request) { | ||
PlayerRes response = roomService.joinRoom(request); | ||
messagingTemplate.convertAndSend("/game-service/sub/" + response.roomId(), response); | ||
} | ||
|
||
// 컨텐츠 선택 (최대 5개, 0개일 경우 자체 컨텐츠 제공) | ||
@MessageMapping("/room/select-content") | ||
public void selectContent(ContentSelectReq request) { | ||
roomService.registerContents(request); | ||
} | ||
|
||
// 플레이어 삭제 | ||
@MessageMapping("/room/player/remove") | ||
public void removePlayer(PlayerReq request) { | ||
PlayerRes response = roomService.removePlayer(request); | ||
messagingTemplate.convertAndSend("/game-service/sub/" + response.roomId(), response); | ||
} | ||
// // 친구 초대 | ||
// @MessageMapping("/room/player/invite") | ||
// public void invitePlayer(PlayerReq request) { | ||
// PlayerRes response = roomService.joinRoom(request); | ||
// messagingTemplate.convertAndSend("/game-service/sub/" + response.roomId(), response); | ||
// } | ||
// | ||
// // 컨텐츠 선택 (최대 5개, 0개일 경우 자체 컨텐츠 제공) | ||
// @MessageMapping("/room/select-content") | ||
// public void selectContent(ContentSelectReq request) { | ||
// roomService.registerContents(request); | ||
// } | ||
// | ||
// // 플레이어 삭제 | ||
// @MessageMapping("/room/player/remove") | ||
// public void removePlayer(PlayerReq request) { | ||
// PlayerRes response = roomService.removePlayer(request); | ||
// messagingTemplate.convertAndSend("/game-service/sub/" + response.roomId(), response); | ||
// } | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
public record PlayerReq( | ||
String roomId, | ||
Long userId | ||
Long userId, | ||
Boolean isReady | ||
) { | ||
} |
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
20 changes: 0 additions & 20 deletions
20
src/main/java/io/urdego/urdego_game_service/controller/room/dto/response/PlayerRes.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/main/java/io/urdego/urdego_game_service/controller/room/dto/response/RoomPlayersRes.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,31 @@ | ||
package io.urdego.urdego_game_service.controller.room.dto.response; | ||
|
||
import io.urdego.urdego_game_service.common.enums.Status; | ||
import io.urdego.urdego_game_service.domain.room.entity.Room; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public record RoomPlayersRes( | ||
String roomId, | ||
Status status, | ||
List<String> currentPlayers, | ||
String isHost, | ||
Map<String, Boolean> readyStatus, | ||
Boolean allReady | ||
) { | ||
public static RoomPlayersRes from(Room room) { | ||
String hostId = room.getCurrentPlayers().isEmpty() ? null : room.getCurrentPlayers().get(0); | ||
boolean allReady = room.getReadyStatus().size() == room.getCurrentPlayers().size() | ||
&& room.getReadyStatus().values().stream().allMatch(ready -> ready); | ||
|
||
return new RoomPlayersRes( | ||
room.getRoomId(), | ||
room.getStatus(), | ||
room.getCurrentPlayers(), | ||
hostId, | ||
room.getReadyStatus(), | ||
allReady | ||
); | ||
} | ||
} |
Oops, something went wrong.