Compare commits

..

No commits in common. "ae04b22b2ac3e1ac398db92af6f8fbe25f07f107" and "945fd5d5a380184cc798afc25aa4edf8a4f75c88" have entirely different histories.

6 changed files with 74 additions and 100 deletions

View File

@ -11,8 +11,5 @@ data class CreateLiveRoomRequest(
val price: Int = 0,
val timezone: String,
val type: LiveRoomType = LiveRoomType.OPEN,
val password: String? = null,
val menuPanId: Long = 0,
val menuPan: String = "",
val isActiveMenuPan: Boolean = false
val password: String? = null
)

View File

@ -5,8 +5,5 @@ data class EditLiveRoomInfoRequest(
val notice: String?,
val numberOfPeople: Int?,
val beginDateTimeString: String?,
val timezone: String?,
val menuPanId: Long = 0,
val menuPan: String = "",
val isActiveMenuPan: Boolean
val timezone: String?
)

View File

@ -38,9 +38,6 @@ import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfo
import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfoRedisRepository
import kr.co.vividnext.sodalive.live.room.info.LiveRoomMember
import kr.co.vividnext.sodalive.live.room.kickout.LiveRoomKickOutService
import kr.co.vividnext.sodalive.live.room.menu.CreateLiveMenuRequest
import kr.co.vividnext.sodalive.live.room.menu.LiveRoomMenuService
import kr.co.vividnext.sodalive.live.room.menu.UpdateLiveMenuRequest
import kr.co.vividnext.sodalive.live.room.visit.LiveRoomVisitService
import kr.co.vividnext.sodalive.live.roulette.NewRouletteRepository
import kr.co.vividnext.sodalive.live.tag.LiveTagRepository
@ -68,8 +65,6 @@ import kotlin.concurrent.write
@Service
@Transactional(readOnly = true)
class LiveRoomService(
private val menuService: LiveRoomMenuService,
private val repository: LiveRoomRepository,
private val rouletteRepository: NewRouletteRepository,
private val roomInfoRepository: LiveRoomInfoRedisRepository,
@ -274,27 +269,6 @@ class LiveRoomService(
room.bgImage = request.coverImageUrl
}
if (request.isActiveMenuPan) {
if (request.menuPanId > 0) {
menuService.updateLiveMenu(
memberId = member.id!!,
request = UpdateLiveMenuRequest(
id = request.menuPanId,
menu = request.menuPan,
isActive = true
)
)
} else {
menuService.createLiveMenu(
memberId = member.id!!,
request = CreateLiveMenuRequest(
menu = request.menuPan,
isActive = true
)
)
}
}
applicationEventPublisher.publishEvent(
FcmEvent(
type = FcmEventType.CREATE_LIVE,
@ -630,28 +604,6 @@ class LiveRoomService(
throw SodaException("변경사항이 없습니다.")
}
if (coverImage != null) {
val metadata = ObjectMetadata()
metadata.contentLength = coverImage.size
// 커버 이미지 파일명 생성
val coverImageFileName = generateFileName(prefix = "${room.id}-cover")
// 커버 이미지 업로드
val coverImagePath = s3Uploader.upload(
inputStream = coverImage.inputStream,
bucket = coverImageBucket,
filePath = "live_room_cover/${room.id}/$coverImageFileName",
metadata = metadata
)
room.bgImage = coverImagePath
if (room.channelName == null) {
room.coverImage = coverImagePath
}
}
if (requestString != null) {
val request = objectMapper.readValue(requestString, EditLiveRoomInfoRequest::class.java)
@ -673,28 +625,27 @@ class LiveRoomService(
.withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime()
}
}
if (request.isActiveMenuPan) {
if (request.menuPanId > 0) {
menuService.updateLiveMenu(
memberId = member.id!!,
request = UpdateLiveMenuRequest(
id = request.menuPanId,
menu = request.menuPan,
isActive = true
)
)
} else {
menuService.createLiveMenu(
memberId = member.id!!,
request = CreateLiveMenuRequest(
menu = request.menuPan,
isActive = true
)
)
}
} else {
menuService.deactivateAll(memberId = member.id!!)
if (coverImage != null) {
val metadata = ObjectMetadata()
metadata.contentLength = coverImage.size
// 커버 이미지 파일명 생성
val coverImageFileName = generateFileName(prefix = "${room.id}-cover")
// 커버 이미지 업로드
val coverImagePath = s3Uploader.upload(
inputStream = coverImage.inputStream,
bucket = coverImageBucket,
filePath = "live_room_cover/${room.id}/$coverImageFileName",
metadata = metadata
)
room.bgImage = coverImagePath
if (room.channelName == null) {
room.coverImage = coverImagePath
}
}
}
@ -752,8 +703,6 @@ class LiveRoomService(
listOf()
}
val menuPan = menuService.getLiveMenu(creatorId = room.member!!.id!!)
return GetRoomInfoResponse(
roomId = roomId,
title = room.title,
@ -789,7 +738,6 @@ class LiveRoomService(
listenerList = roomInfo.listenerList,
managerList = roomInfo.managerList,
donationRankingTop3UserIds = donationRankingTop3UserIds,
menuPan = menuPan?.menu ?: "",
isPrivateRoom = room.type == LiveRoomType.PRIVATE,
password = room.password,
isActiveRoulette = isActiveRoulette

View File

@ -19,7 +19,6 @@ data class GetRoomInfoResponse(
val listenerList: List<LiveRoomMember>,
val managerList: List<LiveRoomMember>,
val donationRankingTop3UserIds: List<Long>,
val menuPan: String,
val isPrivateRoom: Boolean = false,
val password: String? = null,
val isActiveRoulette: Boolean = false

View File

@ -3,9 +3,13 @@ package kr.co.vividnext.sodalive.live.room.menu
import kr.co.vividnext.sodalive.common.ApiResponse
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.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.PutMapping
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
@ -13,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/live/room/menu")
class LiveRoomMenuController(private val service: LiveRoomMenuService) {
@GetMapping("/all")
@GetMapping("/creator")
@PreAuthorize("hasRole('CREATOR')")
fun getAllLiveMenu(
@RequestParam creatorId: Long,
@ -23,4 +27,40 @@ class LiveRoomMenuController(private val service: LiveRoomMenuService) {
ApiResponse.ok(service.getAllLiveMenu(creatorId = creatorId, memberId = member.id!!))
}
@PostMapping
@PreAuthorize("hasRole('CREATOR')")
fun createLiveMenu(
@RequestBody request: CreateLiveMenuRequest,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null || member.role != MemberRole.CREATOR) {
throw SodaException("로그인 정보를 확인해주세요.")
}
ApiResponse.ok(service.createLiveMenu(memberId = member.id!!, request = request))
}
@PutMapping
@PreAuthorize("hasRole('CREATOR')")
fun updateLiveMenu(
@RequestBody request: UpdateLiveMenuRequest,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null || member.role != MemberRole.CREATOR) {
throw SodaException("로그인 정보를 확인해주세요.")
}
ApiResponse.ok(service.updateLiveMenu(memberId = member.id!!, request = request))
}
@GetMapping
fun getMenu(
@RequestParam creatorId: Long,
@AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?
) = run {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
ApiResponse.ok(service.getLiveMenu(creatorId = creatorId))
}
}

View File

@ -22,13 +22,8 @@ class LiveRoomMenuService(
fun createLiveMenu(memberId: Long, request: CreateLiveMenuRequest): Boolean {
liveMenuValidate(menu = request.menu)
val menuList = repository.findByCreatorId(creatorId = memberId)
if (menuList.size >= 3) {
throw SodaException("메뉴판의 최대개수는 3개입니다.")
}
if (request.isActive) {
val menuList = repository.findByCreatorId(creatorId = memberId)
menuList.forEach {
it.isActive = false
repository.save(it)
@ -46,7 +41,7 @@ class LiveRoomMenuService(
return request.isActive
}
fun updateLiveMenu(memberId: Long, request: UpdateLiveMenuRequest) {
fun updateLiveMenu(memberId: Long, request: UpdateLiveMenuRequest): Boolean {
liveMenuValidate(menu = request.menu)
val menuList = repository.findByCreatorId(creatorId = memberId)
@ -54,7 +49,12 @@ class LiveRoomMenuService(
throw SodaException("잘못된 요청입니다.")
}
var isActive = false
menuList.forEach {
if (request.isActive || it.isActive) {
isActive = true
}
if (it.id == request.id) {
it.menu = request.menu
it.isActive = request.isActive
@ -64,9 +64,11 @@ class LiveRoomMenuService(
repository.save(it)
}
}
return isActive
}
fun getLiveMenu(creatorId: Long): GetMenuResponse? {
fun getLiveMenu(creatorId: Long): GetMenuResponse {
val menuList = repository.findByCreatorId(creatorId = creatorId)
if (menuList.isEmpty()) {
@ -82,21 +84,12 @@ class LiveRoomMenuService(
}
if (activeMenu == null || activeMenu.menu.isEmpty()) {
return null
throw SodaException("설정된 메뉴판이 없습니다.")
}
return GetMenuResponse(id = activeMenu.id, menu = activeMenu.menu)
}
fun deactivateAll(memberId: Long) {
val menuList = repository.findByCreatorId(creatorId = memberId)
menuList.forEach {
it.isActive = false
repository.save(it)
}
}
private fun liveMenuValidate(menu: String) {
if (menu.isBlank()) {
throw SodaException("메뉴판은 빈칸일 수 없습니다.")