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 #88 from Game-as-a-Service/feature/add-BuyCardOrPa…
…ss-usecase Feature/add player buy card usecase
- Loading branch information
Showing
33 changed files
with
852 additions
and
215 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package app.usecase; | ||
|
||
import app.exception.NotFoundException; | ||
import app.output.GameRepository; | ||
import domain.Game; | ||
import domain.events.DomainEvent; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import javax.inject.Named; | ||
import java.util.List; | ||
|
||
@Named | ||
@RequiredArgsConstructor | ||
public class BuyCardUseCase { | ||
private final GameRepository gameRepository; | ||
|
||
public void execute(Request request, Presenter presenter) { | ||
Game game = findGameById(request.gameId); | ||
List<DomainEvent> events = game.turnPlayerBuyCard(request.getPlayerId(), request.getCardName()); | ||
gameRepository.save(game); | ||
presenter.present(events); | ||
} | ||
|
||
private Game findGameById(String gameId) { | ||
return gameRepository.findById(gameId).orElseThrow(NotFoundException::new); | ||
} | ||
|
||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Request { | ||
private String gameId; | ||
private String playerId; | ||
private String cardName; | ||
|
||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package app.usecase; | ||
|
||
import app.exception.NotFoundException; | ||
import app.output.GameRepository; | ||
import domain.Game; | ||
import domain.events.DomainEvent; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import spring.presenter.BuyCardPresenter; | ||
import spring.presenter.FlipLandMarkPresenter; | ||
|
||
import javax.inject.Named; | ||
import java.util.List; | ||
|
||
@Named | ||
@RequiredArgsConstructor | ||
public class FlipLandMarkUseCase { | ||
private final GameRepository gameRepository; | ||
|
||
public void execute(FlipLandMarkUseCase.Request request, FlipLandMarkPresenter presenter) { | ||
Game game = findGameById(request.gameId); | ||
List<DomainEvent> events = game.turnPlayerFlipLandMark(request.getPlayerId(), request.getCardName()); | ||
gameRepository.save(game); | ||
presenter.present(events); | ||
} | ||
|
||
private Game findGameById(String gameId) { | ||
return gameRepository.findById(gameId).orElseThrow(NotFoundException::new); | ||
} | ||
|
||
public interface Presenter { | ||
void present(List<DomainEvent> events); | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class Request { | ||
private String gameId; | ||
private String playerId; | ||
private String cardName; | ||
} | ||
} |
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
Oops, something went wrong.