diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/CreateLiveRoomRequest.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/CreateLiveRoomRequest.kt index 22b5468..9a50a39 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/CreateLiveRoomRequest.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/CreateLiveRoomRequest.kt @@ -11,5 +11,8 @@ data class CreateLiveRoomRequest( val price: Int = 0, val timezone: String, val type: LiveRoomType = LiveRoomType.OPEN, - val password: String? = null + val password: String? = null, + val menuPanId: Long = 0, + val menuPan: String = "", + val isActiveMenuPan: Boolean = false ) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/EditLiveRoomInfoRequest.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/EditLiveRoomInfoRequest.kt index 437e8f9..9d24bfd 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/EditLiveRoomInfoRequest.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/EditLiveRoomInfoRequest.kt @@ -5,5 +5,8 @@ data class EditLiveRoomInfoRequest( val notice: String?, val numberOfPeople: Int?, val beginDateTimeString: String?, - val timezone: String? + val timezone: String?, + val menuPanId: Long = 0, + val menuPan: String = "", + val isActiveMenuPan: Boolean ) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt index c8937bc..74b2d48 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/LiveRoomService.kt @@ -38,7 +38,9 @@ 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 @@ -272,6 +274,27 @@ 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, @@ -607,6 +630,28 @@ 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) @@ -628,27 +673,28 @@ class LiveRoomService( .withZoneSameInstant(ZoneId.of("UTC")) .toLocalDateTime() } - } - 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 (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!!) } } } @@ -743,7 +789,7 @@ class LiveRoomService( listenerList = roomInfo.listenerList, managerList = roomInfo.managerList, donationRankingTop3UserIds = donationRankingTop3UserIds, - menuPan = menuPan.menu, + menuPan = menuPan?.menu ?: "", isPrivateRoom = room.type == LiveRoomType.PRIVATE, password = room.password, isActiveRoulette = isActiveRoulette diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuService.kt index 4673943..f6ab126 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/room/menu/LiveRoomMenuService.kt @@ -22,8 +22,13 @@ 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) @@ -41,7 +46,7 @@ class LiveRoomMenuService( return request.isActive } - fun updateLiveMenu(memberId: Long, request: UpdateLiveMenuRequest): Boolean { + fun updateLiveMenu(memberId: Long, request: UpdateLiveMenuRequest) { liveMenuValidate(menu = request.menu) val menuList = repository.findByCreatorId(creatorId = memberId) @@ -49,12 +54,7 @@ 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,11 +64,9 @@ 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()) { @@ -84,12 +82,21 @@ class LiveRoomMenuService( } if (activeMenu == null || activeMenu.menu.isEmpty()) { - throw SodaException("설정된 메뉴판이 없습니다.") + return null } 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("메뉴판은 빈칸일 수 없습니다.")