룰렛 방식 수정 #178
|
@ -14,3 +14,9 @@ data class NewRoulette(
|
||||||
var isActive: Boolean,
|
var isActive: Boolean,
|
||||||
var items: List<RouletteItem> = mutableListOf()
|
var items: List<RouletteItem> = mutableListOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class RouletteItem(
|
||||||
|
val title: String,
|
||||||
|
val weight: Int,
|
||||||
|
val percentage: Float = 0.0F
|
||||||
|
)
|
||||||
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -1,8 +1,26 @@
|
||||||
package kr.co.vividnext.sodalive.live.roulette.v2
|
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.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/roulette")
|
@RequestMapping("/v2/roulette")
|
||||||
class RouletteController(private val service: RouletteService)
|
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!!))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,4 +5,6 @@ import org.springframework.data.repository.CrudRepository
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface RouletteRepository : CrudRepository<NewRoulette, Long>
|
interface RouletteRepository : CrudRepository<NewRoulette, Long> {
|
||||||
|
fun findByCreatorId(creatorId: Long): List<NewRoulette>
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,26 @@
|
||||||
package kr.co.vividnext.sodalive.live.roulette.v2
|
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
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue