-
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.
Merge pull request #47 from PaulKreft/persist-multiplayer-games
Persist multiplayer games
- Loading branch information
Showing
28 changed files
with
262 additions
and
108 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
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/de/neuefische/paulkreft/backend/exception/LobbyGoneException.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 de.neuefische.paulkreft.backend.exception; | ||
|
||
public class LobbyGoneException extends RuntimeException { | ||
public LobbyGoneException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
7 changes: 0 additions & 7 deletions
7
backend/src/main/java/de/neuefische/paulkreft/backend/exception/LobbyNotFoundException.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...rc/main/java/de/neuefische/paulkreft/backend/exception/RequestQueueNotFoundException.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 de.neuefische.paulkreft.backend.exception; | ||
|
||
public class RequestQueueNotFoundException extends RuntimeException { | ||
public RequestQueueNotFoundException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...ckend/game/controller/GameController.java → ...me/classic/controller/GameController.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
...he/paulkreft/backend/game/model/Game.java → ...reft/backend/game/classic/model/Game.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
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
4 changes: 2 additions & 2 deletions
4
...eft/backend/game/repository/GameRepo.java → ...end/game/classic/repository/GameRepo.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
12 changes: 6 additions & 6 deletions
12
...eft/backend/game/service/GameService.java → ...end/game/classic/service/GameService.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
24 changes: 24 additions & 0 deletions
24
...va/de/neuefische/paulkreft/backend/game/multiplayer/controller/MultiplayerController.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 de.neuefische.paulkreft.backend.game.multiplayer.controller; | ||
|
||
import de.neuefische.paulkreft.backend.game.multiplayer.model.MultiplayerGame; | ||
import de.neuefische.paulkreft.backend.game.multiplayer.model.MultiplayerGameCreate; | ||
import de.neuefische.paulkreft.backend.game.multiplayer.service.MultiplayerService; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/game/multiplayer") | ||
public class MultiplayerController { | ||
private final MultiplayerService multiplayerService; | ||
|
||
public MultiplayerController(MultiplayerService multiplayerService) { | ||
this.multiplayerService = multiplayerService; | ||
} | ||
|
||
@PostMapping | ||
public MultiplayerGame createMultiplayerGame(@RequestBody MultiplayerGameCreate multiplayerGameCreate) { | ||
return multiplayerService.createGame(multiplayerGameCreate); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/de/neuefische/paulkreft/backend/game/multiplayer/model/MultiplayerGame.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,19 @@ | ||
package de.neuefische.paulkreft.backend.game.multiplayer.model; | ||
|
||
import org.springframework.data.annotation.Id; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
public record MultiplayerGame( | ||
@Id | ||
String id, | ||
List<String> playerIds, | ||
int difficulty, | ||
Integer streakToWin, | ||
String winnerId, | ||
List<String> loserIds, | ||
Integer wonInMilliseconds, | ||
Instant createdAt | ||
) { | ||
} |
17 changes: 17 additions & 0 deletions
17
...in/java/de/neuefische/paulkreft/backend/game/multiplayer/model/MultiplayerGameCreate.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,17 @@ | ||
package de.neuefische.paulkreft.backend.game.multiplayer.model; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
|
||
public record MultiplayerGameCreate( | ||
List<String> playerIds, | ||
int difficulty, | ||
Integer streakToWin, | ||
String winnerId, | ||
List<String> loserIds, | ||
Integer wonInMilliseconds | ||
) { | ||
public MultiplayerGame withIdAndCreatedAt(String id, Instant createdAt) { | ||
return new MultiplayerGame(id, this.playerIds, this.difficulty, this.streakToWin, this.winnerId, this.loserIds, this.wonInMilliseconds, createdAt); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...java/de/neuefische/paulkreft/backend/game/multiplayer/repository/MultiplayerGameRepo.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,9 @@ | ||
package de.neuefische.paulkreft.backend.game.multiplayer.repository; | ||
|
||
import de.neuefische.paulkreft.backend.game.multiplayer.model.MultiplayerGame; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MultiplayerGameRepo extends MongoRepository<MultiplayerGame, String> { | ||
} |
25 changes: 25 additions & 0 deletions
25
...ain/java/de/neuefische/paulkreft/backend/game/multiplayer/service/MultiplayerService.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,25 @@ | ||
package de.neuefische.paulkreft.backend.game.multiplayer.service; | ||
|
||
import de.neuefische.paulkreft.backend.game.multiplayer.model.MultiplayerGame; | ||
import de.neuefische.paulkreft.backend.game.multiplayer.model.MultiplayerGameCreate; | ||
import de.neuefische.paulkreft.backend.game.multiplayer.repository.MultiplayerGameRepo; | ||
import de.neuefische.paulkreft.backend.utils.service.IdService; | ||
import de.neuefische.paulkreft.backend.utils.service.TimeService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class MultiplayerService { | ||
private final MultiplayerGameRepo multiplayerGameRepo; | ||
private final IdService idService; | ||
private final TimeService timeService; | ||
|
||
public MultiplayerService(MultiplayerGameRepo multiplayerGameRepo, IdService idService, TimeService timeService) { | ||
this.multiplayerGameRepo = multiplayerGameRepo; | ||
this.idService = idService; | ||
this.timeService = timeService; | ||
} | ||
|
||
public MultiplayerGame createGame(MultiplayerGameCreate multiplayerGameCreate) { | ||
return multiplayerGameRepo.save(multiplayerGameCreate.withIdAndCreatedAt(idService.generateUUID(), timeService.getNow())); | ||
} | ||
} |
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
8 changes: 4 additions & 4 deletions
8
backend/src/main/java/de/neuefische/paulkreft/backend/user/service/UserService.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
.../paulkreft/backend/service/IdService.java → ...reft/backend/utils/service/IdService.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
...aulkreft/backend/service/TimeService.java → ...ft/backend/utils/service/TimeService.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
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: 6 additions & 5 deletions
11
backend/src/test/java/de/neuefische/paulkreft/backend/game/service/GameServiceTest.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
Oops, something went wrong.