-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sandbox' of https://github.com/YAPP-Github/24th-App-Tea…
…m-2-BE into sandbox
- Loading branch information
Showing
12 changed files
with
113 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ enum class RequestAction( | |
START_GAME("마피아 게임 시작"), | ||
DRAW("그림 그리기"), | ||
END_TURN("턴 넘기기"), | ||
VOTE("마피아 투표"), | ||
} |
5 changes: 5 additions & 0 deletions
5
...bsocket/src/main/kotlin/com/xorker/draw/websocket/message/request/dto/VoteMafiaRequest.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,5 @@ | ||
package com.xorker.draw.websocket.message.request.dto | ||
|
||
data class VoteMafiaRequest( | ||
val userId: Long, | ||
) |
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
16 changes: 16 additions & 0 deletions
16
.../src/main/kotlin/com/xorker/draw/websocket/message/response/dto/MafiaVoteStatusMessage.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,16 @@ | ||
package com.xorker.draw.websocket.message.response.dto | ||
|
||
import com.xorker.draw.user.UserId | ||
import com.xorker.draw.websocket.ResponseAction | ||
import com.xorker.draw.websocket.SessionMessage | ||
|
||
class MafiaVoteStatusMessage( | ||
override val body: MafiaVoteStatusBody, | ||
) : SessionMessage { | ||
override val action = ResponseAction.VOTE_STATUS | ||
override val status = SessionMessage.Status.OK | ||
} | ||
|
||
data class MafiaVoteStatusBody( | ||
val players: Map<UserId, Set<UserId>>, | ||
) |
46 changes: 46 additions & 0 deletions
46
core/src/main/kotlin/com/xorker/draw/mafia/MafiaVoteService.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,46 @@ | ||
package com.xorker.draw.mafia | ||
|
||
import com.xorker.draw.exception.InvalidMafiaGameVotePhaseStatusException | ||
import com.xorker.draw.exception.InvalidRequestValueException | ||
import com.xorker.draw.user.UserId | ||
import com.xorker.draw.websocket.Session | ||
import java.util.concurrent.ConcurrentHashMap | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
internal class MafiaVoteService( | ||
private val mafiaGameRepository: MafiaGameRepository, | ||
private val mafiaGameMessenger: MafiaGameMessenger, | ||
) : MafiaVoteUseCase { | ||
|
||
override fun voteMafia(session: Session, targetUserId: UserId) { | ||
val roomId = session.roomId | ||
|
||
val voter = session.user | ||
val voterUserId = voter.id | ||
|
||
val gameInfo = mafiaGameRepository.getGameInfo(roomId) ?: throw InvalidMafiaGameVotePhaseStatusException | ||
|
||
val phase = gameInfo.phase as? MafiaPhase.Vote ?: throw InvalidMafiaGameVotePhaseStatusException | ||
|
||
vote(phase.players, voterUserId, targetUserId) | ||
|
||
mafiaGameMessenger.broadcastVoteStatus(gameInfo) | ||
} | ||
|
||
@Synchronized | ||
private fun vote( | ||
players: ConcurrentHashMap<UserId, MutableSet<UserId>>, | ||
voterUserId: UserId, | ||
targetUserId: UserId, | ||
) { | ||
players.forEach { player -> | ||
val userIds = player.value | ||
|
||
if (voterUserId in userIds) { | ||
userIds.remove(voterUserId) | ||
} | ||
} | ||
players[targetUserId]?.add(voterUserId) ?: InvalidRequestValueException | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
core/src/main/kotlin/com/xorker/draw/mafia/MafiaVoteUseCase.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 com.xorker.draw.mafia | ||
|
||
import com.xorker.draw.user.UserId | ||
import com.xorker.draw.websocket.Session | ||
|
||
interface MafiaVoteUseCase { | ||
fun voteMafia(session: Session, targetUserId: UserId) | ||
} |
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