룰렛 전체 가져오기 로직 추가

- RouletteItem 에 percentage(확률) 추가
This commit is contained in:
Klaus 2024-05-08 22:25:16 +09:00
parent e6dec42a00
commit 4f77818406
5 changed files with 50 additions and 22 deletions

View File

@ -14,3 +14,9 @@ data class NewRoulette(
var isActive: Boolean,
var items: List<RouletteItem> = mutableListOf()
)
data class RouletteItem(
val title: String,
val weight: Int,
val percentage: Float = 0.0F
)

View File

@ -1,18 +0,0 @@
package kr.co.vividnext.sodalive.live.roulette
import org.springframework.data.annotation.Id
import org.springframework.data.redis.core.RedisHash
@RedisHash("roulette")
data class Roulette(
@Id
val creatorId: Long,
var can: Int,
var isActive: Boolean,
var items: List<RouletteItem> = mutableListOf()
)
data class RouletteItem(
val title: String,
val weight: Int
)

View File

@ -1,8 +1,26 @@
package kr.co.vividnext.sodalive.live.roulette.v2
import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.member.Member
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/roulette")
class RouletteController(private val service: RouletteService)
@RequestMapping("/v2/roulette")
class RouletteController(private val service: RouletteService) {
@GetMapping("/creator")
@PreAuthorize("hasRole('CREATOR')")
fun getAllRoulette(
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(service.getAllRoulette(creatorId = creatorId, memberId = member.id!!))
}
}

View File

@ -5,4 +5,6 @@ import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
@Repository
interface RouletteRepository : CrudRepository<NewRoulette, Long>
interface RouletteRepository : CrudRepository<NewRoulette, Long> {
fun findByCreatorId(creatorId: Long): List<NewRoulette>
}

View File

@ -1,6 +1,26 @@
package kr.co.vividnext.sodalive.live.roulette.v2
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.live.roulette.GetNewRouletteResponse
import org.springframework.stereotype.Service
@Service
class RouletteService
class RouletteService(
private val repository: RouletteRepository
) {
fun getAllRoulette(creatorId: Long, memberId: Long): List<GetNewRouletteResponse> {
if (creatorId != memberId) throw SodaException("잘못된 요청입니다.")
val rouletteList = repository.findByCreatorId(creatorId)
return rouletteList.sortedBy { it.id }
.map {
GetNewRouletteResponse(
it.id,
it.can,
it.isActive,
it.items
)
}
}
}