룰렛 데이터 읽기 API 추가

This commit is contained in:
Klaus 2023-11-28 15:21:50 +09:00
parent e96b3d9bd4
commit 516853b05f
3 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,6 @@
package kr.co.vividnext.sodalive.live.roulette
data class GetRouletteResponse(
val can: Int,
val items: List<RouletteItem>
)

View File

@ -5,9 +5,11 @@ import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.member.Member
import kr.co.vividnext.sodalive.member.MemberRole
import org.springframework.security.core.annotation.AuthenticationPrincipal
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
@ -24,4 +26,17 @@ class RouletteController(private val service: RouletteService) {
ApiResponse.ok(service.createOrUpdateRoulette(memberId = member.id!!, request = request))
}
@GetMapping
fun getRoulette(
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
): ApiResponse<GetRouletteResponse> {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
val response = service.getRoulette(creatorId = creatorId)
?: throw SodaException("룰렛을 사용할 수 없습니다.")
return ApiResponse.ok(response)
}
}

View File

@ -36,4 +36,14 @@ class RouletteService(private val repository: RouletteRepository) {
throw SodaException("옵션 확률의 합이 100%가 아닙니다.")
}
}
fun getRoulette(creatorId: Long): GetRouletteResponse? {
val roulette = repository.findByIdOrNull(id = creatorId)
if (roulette == null || !roulette.isActive || roulette.items.isEmpty()) {
return null
}
return GetRouletteResponse(can = roulette.can, items = roulette.items)
}
}