-
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.
* 解衝突 * 依據 create room 修改 join room * 依據code review結果修正 * 依據二次 code review 修正 * 依據三次 code review 修正 * 依據第四次 code review修正 * 依據第五次code review修正 * 依據第六次code review修正 --------- Co-authored-by: Ted <azoocx791029@gmai.com>
- Loading branch information
Showing
14 changed files
with
255 additions
and
46 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
application/src/main/kotlin/tw/waterballsa/gaas/application/extension/UserExtensions.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,8 @@ | ||
package tw.waterballsa.gaas.application.extension | ||
|
||
import tw.waterballsa.gaas.domain.Room | ||
import tw.waterballsa.gaas.domain.User | ||
import tw.waterballsa.gaas.domain.Room.Player | ||
|
||
internal fun User.toRoomPlayer(): Player = | ||
Player(Player.Id(id!!.value), nickname) |
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
54 changes: 54 additions & 0 deletions
54
application/src/main/kotlin/tw/waterballsa/gaas/application/usecases/JoinRoomUsecase.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,54 @@ | ||
package tw.waterballsa.gaas.application.usecases | ||
|
||
import tw.waterballsa.gaas.application.eventbus.EventBus | ||
import tw.waterballsa.gaas.application.extension.toRoomPlayer | ||
import tw.waterballsa.gaas.application.repositories.RoomRepository | ||
import tw.waterballsa.gaas.application.repositories.UserRepository | ||
import tw.waterballsa.gaas.domain.Room | ||
import tw.waterballsa.gaas.domain.User | ||
import tw.waterballsa.gaas.exceptions.NotFoundException.Companion.notFound | ||
import tw.waterballsa.gaas.exceptions.PlatformException | ||
import javax.inject.Named | ||
|
||
@Named | ||
class JoinRoomUsecase( | ||
private val roomRepository: RoomRepository, | ||
private val userRepository: UserRepository, | ||
private val eventBus: EventBus | ||
){ | ||
|
||
fun execute(request: Request) { | ||
with(request) { | ||
val room = findRoomById(Room.Id(roomId)) | ||
room.validateRoomPassword(password) | ||
room.joinPlayer(userId) | ||
} | ||
} | ||
|
||
private fun findRoomById(roomId: Room.Id) = | ||
roomRepository.findById(roomId) | ||
?: throw notFound(Room::class).id(roomId) | ||
|
||
private fun Room.validateRoomPassword(password: String?) { | ||
if(isLocked && !isPasswordCorrect(password)){ | ||
throw PlatformException("wrong password") | ||
} | ||
} | ||
|
||
private fun Room.joinPlayer(userId: String): Room { | ||
val player = findPlayerByUserId(User.Id(userId)) | ||
addPlayer(player) | ||
return roomRepository.joinRoom(this) | ||
} | ||
|
||
private fun findPlayerByUserId(userId: User.Id) = | ||
userRepository.findById(userId) | ||
?.toRoomPlayer() | ||
?: throw notFound(User::class).id(userId.value) | ||
|
||
data class Request( | ||
val roomId: String, | ||
val userId: String, | ||
val password: String? = null, | ||
) | ||
} |
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
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.