라이브 메뉴

- 생성 or 수정 API 추가
This commit is contained in:
Klaus 2024-10-08 15:10:24 +09:00
parent e0424b1678
commit f813d8eae4
1 changed files with 21 additions and 1 deletions

View File

@ -6,15 +6,16 @@ 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.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
@RestController
@PreAuthorize("hasRole('CREATOR')")
@RequestMapping("/live/room/menu")
class LiveRoomMenuController(private val service: LiveRoomMenuService) {
@GetMapping("/all")
@PreAuthorize("hasRole('CREATOR')")
fun getAllLiveMenu(
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
@ -23,4 +24,23 @@ class LiveRoomMenuController(private val service: LiveRoomMenuService) {
ApiResponse.ok(service.getAllLiveMenu(creatorId = creatorId, memberId = member.id!!))
}
@PostMapping
fun createOrUpdateLiveMenu(
@RequestParam request: UpdateLiveMenuRequest,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(
if (request.id > 0) {
service.updateLiveMenu(memberId = member.id!!, request = request)
} else {
service.createLiveMenu(
memberId = member.id!!,
request = CreateLiveMenuRequest(menu = request.menu, isActive = false)
)
}
)
}
}