generated from Game-as-a-Service/Gaas-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #98 from Game-as-a-Service/feature/add-create-game…
…-usecase ✨ add create game usecase
- Loading branch information
Showing
26 changed files
with
259 additions
and
94 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/java/app/output/GameRepository.java → ...java/app/repositories/GameRepository.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,4 +1,4 @@ | ||
package app.output; | ||
package app.repositories; | ||
|
||
import domain.Game; | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package app.usecase; | ||
|
||
import app.repositories.GameRepository; | ||
import domain.Game; | ||
import domain.Player; | ||
import lombok.*; | ||
|
||
import javax.inject.Named; | ||
import java.util.List; | ||
|
||
@Named | ||
@RequiredArgsConstructor | ||
public class CreateGameUseCase { | ||
private final GameRepository gameRepository; | ||
|
||
public void execute(Request request, Presenter presenter) { | ||
|
||
Player player = request.toPlayer(); | ||
Game game = new Game(List.of(player)); | ||
|
||
// 存 | ||
gameRepository.save(game); | ||
|
||
// 推 | ||
presenter.present(game.toCreateGameEvent()); | ||
} | ||
|
||
public record Request(String playerId, String playerName) { | ||
private Player toPlayer() { | ||
return new Player(playerId, playerName); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package app.usecase; | ||
|
||
import domain.events.DomainEvent; | ||
|
||
import java.util.List; | ||
|
||
public interface Presenter { | ||
void present(List<DomainEvent> events); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package domain.events; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CreateGameEvent extends DomainEvent { | ||
private String gameId; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package spring.presenter; | ||
|
||
import app.usecase.Presenter; | ||
import domain.events.DomainEvent; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public abstract class AbstractPresenter implements Presenter { | ||
@SuppressWarnings("unchecked") | ||
public static <T extends DomainEvent> Optional<T> getEvent(List<DomainEvent> events, | ||
Class<T> type) { | ||
return events.stream() | ||
.filter(e -> type.isAssignableFrom(e.getClass())) | ||
.map(e -> (T) e) | ||
.findFirst(); | ||
} | ||
} |
Oops, something went wrong.