-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1.實作遊戲結束功能 2.實作遊戲結束推播 * 根據第一次code review修正 --------- Co-authored-by: Ted <[email protected]>
- Loading branch information
Showing
9 changed files
with
142 additions
and
5 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/EndGameUseCase.kt
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,36 @@ | ||
package tw.waterballsa.gaas.application.usecases | ||
|
||
import tw.waterballsa.gaas.application.eventbus.EventBus | ||
import tw.waterballsa.gaas.application.repositories.RoomRepository | ||
import tw.waterballsa.gaas.application.repositories.UserRepository | ||
import tw.waterballsa.gaas.domain.Room | ||
import tw.waterballsa.gaas.events.EndedGameEvent | ||
import tw.waterballsa.gaas.events.EndedGameEvent.Data | ||
import tw.waterballsa.gaas.events.enums.EventMessageType.GAME_ENDED | ||
import javax.inject.Named | ||
|
||
@Named | ||
class EndGameUseCase( | ||
roomRepository: RoomRepository, | ||
userRepository: UserRepository, | ||
private val eventBus: EventBus, | ||
) : AbstractRoomUseCase(roomRepository, userRepository) { | ||
fun execute(request: Request) { | ||
val room = findRoomById(request.roomId) | ||
room.endGame() | ||
roomRepository.update(room) | ||
|
||
val endedGameEvent = room.endGameByGameService() | ||
eventBus.broadcast(endedGameEvent) | ||
} | ||
|
||
data class Request( | ||
val roomId: String, | ||
) | ||
} | ||
|
||
fun Room.endGameByGameService(): EndedGameEvent { | ||
val type = GAME_ENDED | ||
val data = Data(roomId!!.value) | ||
return EndedGameEvent(type, data) | ||
} |
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: 12 additions & 0 deletions
12
domain/src/main/kotlin/tw/waterballsa/gaas/events/EndedGameEvent.kt
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,12 @@ | ||
package tw.waterballsa.gaas.events | ||
|
||
import tw.waterballsa.gaas.events.enums.EventMessageType | ||
|
||
data class EndedGameEvent( | ||
val type: EventMessageType, | ||
val data: Data, | ||
) : DomainEvent() { | ||
data class Data( | ||
val roomId: String, | ||
) | ||
} |
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