-
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.
- 유저의 게임 입장과 알림을 구현했습니다.
- Loading branch information
Showing
11 changed files
with
190 additions
and
46 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
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
27 changes: 27 additions & 0 deletions
27
backend/poker-service/src/main/java/com/pokerservice/controller/rest/GameInfoController.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,27 @@ | ||
package com.pokerservice.controller.rest; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class GameInfoController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(GameInfoController.class); | ||
|
||
@GetMapping("/gameInfo/{gameId}") | ||
public void getGameInfo(@PathVariable long gameId) { | ||
|
||
} | ||
|
||
@GetMapping("/gameInfo/players/{gameId}") | ||
public void getPlayers(@PathVariable long gameId) { | ||
|
||
} | ||
|
||
@GetMapping("/gameInfo/ping/{gameId}") | ||
public void ping(@PathVariable long gameId) { | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...nd/poker-service/src/main/java/com/pokerservice/controller/rest/GameManageController.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,24 @@ | ||
package com.pokerservice.controller.rest; | ||
|
||
import com.pokerservice.core.domain.GameType; | ||
import com.pokerservice.core.port.GameMakeUseCase; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class GameManageController { | ||
|
||
private final GameMakeUseCase gameMakeUseCase; | ||
|
||
public GameManageController(GameMakeUseCase gameMakeUseCase) { | ||
this.gameMakeUseCase = gameMakeUseCase; | ||
} | ||
|
||
|
||
@PostMapping("/game") | ||
public ResponseEntity<Long> makeGame(GameType gameType) { | ||
return ResponseEntity.ok(gameMakeUseCase.makeGame(gameType)); | ||
} | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
backend/poker-service/src/main/java/com/pokerservice/controller/ws/TestController.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,34 @@ | ||
package com.pokerservice.controller.ws; | ||
|
||
import com.pokerservice.controller.ws.GameMessage.MessageType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; | ||
import org.springframework.messaging.simp.SimpMessageSendingOperations; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class TestController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(TestController.class); | ||
private final SimpMessageSendingOperations sendingOperations; | ||
|
||
public TestController(SimpMessageSendingOperations sendingOperations) { | ||
this.sendingOperations = sendingOperations; | ||
} | ||
|
||
@MessageMapping("/test") | ||
public void test(@Payload GameMessage gameMessage, SimpMessageHeaderAccessor headerAccessor) { | ||
try { | ||
headerAccessor.getSessionAttributes() | ||
.put("ws-session", headerAccessor.getUser().getName()); | ||
} catch (Exception e) { | ||
sendingOperations.convertAndSend("/sub/public/" + gameMessage.getGameId(), | ||
new GameMessage(MessageType.ERROR, null, null, 0, 0)); | ||
} | ||
|
||
sendingOperations.convertAndSend("/sub/public/" + gameMessage.getGameId(), gameMessage); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,5 @@ | |
|
||
public interface GameUseCase { | ||
|
||
boolean gameStart(long gameId); | ||
|
||
void betting(long gameId, int bettingAmount); | ||
} |
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
11 changes: 11 additions & 0 deletions
11
backend/poker-service/src/main/java/com/pokerservice/core/service/SessionMessage.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,11 @@ | ||
package com.pokerservice.core.service; | ||
|
||
import com.pokerservice.controller.ws.GameMessage; | ||
|
||
public record SessionMessage( | ||
GameMessage gameMessage, | ||
String session, | ||
String name | ||
) { | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
backend/poker-service/src/test/java/com/pokerservice/RandomTest.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,32 @@ | ||
package com.pokerservice; | ||
|
||
import com.pokerservice.controller.ws.GameMessage.MessageType; | ||
import java.util.Random; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class RandomTest { | ||
|
||
@Test | ||
void randomTest(){ | ||
int min = 1; | ||
int max = 10; | ||
Random random = new Random(); | ||
for (int i = 0; i < 100; i++) { | ||
System.out.println(random.nextInt((max - min) + min) + min); | ||
} | ||
} | ||
|
||
@Test | ||
void enumToStringTest(){ | ||
// given | ||
MessageType join = MessageType.valueOf("JOIN"); | ||
MessageType draw = MessageType.valueOf("DRAW"); | ||
|
||
// when | ||
Assertions.assertTrue(join == MessageType.JOIN); | ||
Assertions.assertFalse(join == MessageType.DRAW); | ||
|
||
// then | ||
} | ||
} |