From f577e137c25ae5837bf6f4a73763f27e6080c016 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 19 Feb 2024 12:02:32 +0900 Subject: [PATCH 01/19] redis ssl true --- src/main/resources/application.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 62f24c6..936b925 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -53,6 +53,7 @@ spring: redis: host: ${REDIS_HOST} port: ${REDIS_PORT} + ssl: true datasource: driver-class-name: com.mysql.cj.jdbc.Driver From dd8634c47b3403cd81a3dcaeeb43a5004e8629c9 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 19 Feb 2024 12:26:03 +0900 Subject: [PATCH 02/19] redis ssl false --- src/main/resources/application.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 936b925..62f24c6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -53,7 +53,6 @@ spring: redis: host: ${REDIS_HOST} port: ${REDIS_PORT} - ssl: true datasource: driver-class-name: com.mysql.cj.jdbc.Driver From 81a94082aab62b06b48aabc88a47787d0e36dad0 Mon Sep 17 00:00:00 2001 From: Klaus Date: Mon, 19 Feb 2024 14:26:42 +0900 Subject: [PATCH 03/19] redis ssl true --- .../kr/co/vividnext/sodalive/configs/RedisConfig.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/configs/RedisConfig.kt b/src/main/kotlin/kr/co/vividnext/sodalive/configs/RedisConfig.kt index 5b0ec53..09989bd 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/configs/RedisConfig.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/configs/RedisConfig.kt @@ -7,6 +7,8 @@ import org.springframework.context.annotation.Configuration import org.springframework.data.redis.cache.RedisCacheConfiguration import org.springframework.data.redis.cache.RedisCacheManager import org.springframework.data.redis.connection.RedisConnectionFactory +import org.springframework.data.redis.connection.RedisStandaloneConfiguration +import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory import org.springframework.data.redis.core.RedisTemplate import org.springframework.data.redis.repository.configuration.EnableRedisRepositories @@ -26,7 +28,12 @@ class RedisConfig( ) { @Bean fun redisConnectionFactory(): RedisConnectionFactory { - return LettuceConnectionFactory(host, port) + val clientConfiguration = LettuceClientConfiguration.builder() + .useSsl() + .disablePeerVerification() + .build() + + return LettuceConnectionFactory(RedisStandaloneConfiguration(host, port), clientConfiguration) } @Bean From f36965071182ae7538e9b837b5107e54b8afd2df Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 12:39:49 +0900 Subject: [PATCH 04/19] =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=ED=94=84=EB=A6=AC?= =?UTF-8?q?=EC=85=8B=20API=20=EC=B6=94=EA=B0=80=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20-=20=EB=A3=B0=EB=A0=9B=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=ED=94=84=EB=A6=AC=EC=85=8B=20=EC=A0=84=EC=B2=B4=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/roulette/CreateNewRouletteRequest.kt | 7 + .../live/roulette/GetNewRouletteResponse.kt | 8 + .../sodalive/live/roulette/NewRoulette.kt | 14 ++ .../live/roulette/NewRouletteController.kt | 87 ++++++++ .../live/roulette/NewRouletteRepository.kt | 8 + .../live/roulette/NewRouletteService.kt | 199 ++++++++++++++++++ .../live/roulette/RedisIdGenerator.kt | 11 + .../sodalive/live/roulette/RouletteService.kt | 4 +- .../live/roulette/UpdateNewRouletteRequest.kt | 8 + 9 files changed, 344 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/CreateNewRouletteRequest.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/GetNewRouletteResponse.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteController.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RedisIdGenerator.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/UpdateNewRouletteRequest.kt diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/CreateNewRouletteRequest.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/CreateNewRouletteRequest.kt new file mode 100644 index 0000000..979a025 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/CreateNewRouletteRequest.kt @@ -0,0 +1,7 @@ +package kr.co.vividnext.sodalive.live.roulette + +data class CreateNewRouletteRequest( + val can: Int, + val isActive: Boolean, + val items: List +) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/GetNewRouletteResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/GetNewRouletteResponse.kt new file mode 100644 index 0000000..2dcb511 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/GetNewRouletteResponse.kt @@ -0,0 +1,8 @@ +package kr.co.vividnext.sodalive.live.roulette + +data class GetNewRouletteResponse( + val id: Long, + val can: Int, + val isActive: Boolean, + val items: List +) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt new file mode 100644 index 0000000..0548502 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt @@ -0,0 +1,14 @@ +package kr.co.vividnext.sodalive.live.roulette + +import org.springframework.data.redis.core.RedisHash +import javax.persistence.Id + +@RedisHash("newRoulette") +data class NewRoulette( + @Id + val id: Long, + val creatorId: Long, + var can: Int, + var isActive: Boolean, + var items: List = mutableListOf() +) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteController.kt new file mode 100644 index 0000000..9464285 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteController.kt @@ -0,0 +1,87 @@ +package kr.co.vividnext.sodalive.live.roulette + +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.PathVariable +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 + +@RestController +@RequestMapping("/new-roulette") +class NewRouletteController(private val service: NewRouletteService) { + @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!!)) + } + + @PostMapping + @PreAuthorize("hasRole('CREATOR')") + fun createNewRoulette( + @RequestBody request: CreateNewRouletteRequest, + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ) = run { + if (member == null || member.role != MemberRole.CREATOR) { + throw SodaException("로그인 정보를 확인해주세요.") + } + + ApiResponse.ok(service.createRoulette(memberId = member.id!!, request = request)) + } + + @PutMapping + @PreAuthorize("hasRole('CREATOR')") + fun updateNewRoulette( + @RequestBody request: UpdateNewRouletteRequest, + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ) = run { + if (member == null || member.role != MemberRole.CREATOR) { + throw SodaException("로그인 정보를 확인해주세요.") + } + + ApiResponse.ok(service.updateRoulette(memberId = member.id!!, request = request)) + } + + @GetMapping + fun getRoulette( + @RequestParam creatorId: Long, + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ): ApiResponse { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + return ApiResponse.ok(service.getRoulette(creatorId = creatorId, memberId = member.id!!)) + } + + @PostMapping("/spin") + fun spinRoulette( + @RequestBody request: SpinRouletteRequest, + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ) = run { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + ApiResponse.ok(service.spinRoulette(request = request, memberId = member.id!!)) + } + + @PostMapping("/refund/{id}") + fun refundDonation( + @PathVariable id: Long, + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? + ) = run { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + ApiResponse.ok(service.refundDonation(id, member)) + } +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt new file mode 100644 index 0000000..fca5623 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt @@ -0,0 +1,8 @@ +package kr.co.vividnext.sodalive.live.roulette + +import org.springframework.data.repository.CrudRepository + +interface NewRouletteRepository : CrudRepository { + fun findByCreatorId(creatorId: Long): List + fun findByCreatorIdAndActive(creatorId: Long, isActive: Boolean): List +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt new file mode 100644 index 0000000..4288f3f --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -0,0 +1,199 @@ +package kr.co.vividnext.sodalive.live.roulette + +import kr.co.vividnext.sodalive.can.CanRepository +import kr.co.vividnext.sodalive.can.charge.Charge +import kr.co.vividnext.sodalive.can.charge.ChargeRepository +import kr.co.vividnext.sodalive.can.charge.ChargeStatus +import kr.co.vividnext.sodalive.can.payment.CanPaymentService +import kr.co.vividnext.sodalive.can.payment.Payment +import kr.co.vividnext.sodalive.can.payment.PaymentGateway +import kr.co.vividnext.sodalive.can.payment.PaymentStatus +import kr.co.vividnext.sodalive.can.use.CanUsage +import kr.co.vividnext.sodalive.can.use.UseCanCalculateRepository +import kr.co.vividnext.sodalive.can.use.UseCanCalculateStatus +import kr.co.vividnext.sodalive.common.SodaException +import kr.co.vividnext.sodalive.live.room.LiveRoomRepository +import kr.co.vividnext.sodalive.member.Member +import kr.co.vividnext.sodalive.member.MemberRepository +import kr.co.vividnext.sodalive.member.MemberRole +import org.springframework.data.repository.findByIdOrNull +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class NewRouletteService( + private val idGenerator: RedisIdGenerator, + private val canPaymentService: CanPaymentService, + + private val canRepository: CanRepository, + private val repository: NewRouletteRepository, + private val oldRepository: RouletteRepository, + private val roomRepository: LiveRoomRepository, + private val memberRepository: MemberRepository, + private val chargeRepository: ChargeRepository, + private val useCanCalculateRepository: UseCanCalculateRepository +) { + fun getAllRoulette(creatorId: Long, memberId: Long): List { + if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") + + val rouletteList = repository.findByCreatorId(creatorId) + if (rouletteList.isEmpty()) { + val roulette = oldRepository.findByIdOrNull(creatorId) + if (roulette != null) { + val newRoulette = repository.save( + NewRoulette( + id = idGenerator.generateId(SEQUENCE_NAME), + creatorId = creatorId, + can = roulette.can, + isActive = false, + items = roulette.items + ) + ) + + rouletteList.toMutableList().add(newRoulette) + } + } + + rouletteList.sortedBy { it.id } + return rouletteList.asSequence() + .map { + GetNewRouletteResponse( + it.id, + it.can, + it.isActive, + it.items + ) + } + .toList() + } + + fun createRoulette(memberId: Long, request: CreateNewRouletteRequest): Boolean { + rouletteValidate(can = request.can, items = request.items) + + val roulette = NewRoulette( + id = idGenerator.generateId(SEQUENCE_NAME), + creatorId = memberId, + can = request.can, + isActive = request.isActive, + items = request.items + ) + + repository.save(roulette) + return request.isActive + } + + fun updateRoulette(memberId: Long, request: UpdateNewRouletteRequest): Boolean { + rouletteValidate(can = request.can, items = request.items) + + val roulette = repository.findByIdOrNull(request.id) + ?: throw SodaException("잘못된 요청입니다.") + + if (roulette.creatorId != memberId) { + throw SodaException("잘못된 요청입니다.") + } + + roulette.can = request.can + roulette.items = request.items + roulette.isActive = request.isActive + repository.save(roulette) + + return request.isActive + } + + fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse { + val roulette = repository.findByCreatorIdAndActive(creatorId = creatorId, isActive = true) + + if (roulette.isEmpty() || !roulette[0].isActive || roulette[0].items.isEmpty()) { + throw SodaException("룰렛을 사용할 수 없습니다.") + } + + return GetRouletteResponse( + can = roulette[0].can, + isActive = roulette[0].isActive, + items = roulette[0].items + ) + } + + @Transactional + fun spinRoulette(request: SpinRouletteRequest, memberId: Long): GetRouletteResponse { + // STEP 1 - 라이브 정보 가져오기 + val room = roomRepository.findByIdOrNull(request.roomId) + ?: throw SodaException("해당하는 라이브가 없습니다.") + + val host = room.member ?: throw SodaException("잘못된 요청입니다.") + + if (host.role != MemberRole.CREATOR) { + throw SodaException("비비드넥스트와 계약한\n크리에이터의 룰렛만 사용하실 수 있습니다.") + } + + // STEP 2 - 룰렛 데이터 가져오기 + val rouletteList = repository.findByCreatorIdAndActive(creatorId = host.id!!, isActive = true) + + if (rouletteList.isEmpty() || !rouletteList[0].isActive || rouletteList[0].items.isEmpty()) { + throw SodaException("룰렛을 사용할 수 없습니다.") + } + + // STEP 3 - 캔 사용 + val roulette = rouletteList[0] + canPaymentService.spendCan( + memberId = memberId, + needCan = roulette.can, + canUsage = CanUsage.SPIN_ROULETTE, + liveRoom = room, + container = request.container + ) + + return GetRouletteResponse(can = roulette.can, isActive = roulette.isActive, items = roulette.items) + } + + @Transactional + fun refundDonation(roomId: Long, member: Member) { + val donator = memberRepository.findByIdOrNull(member.id) + ?: throw SodaException("룰렛 돌리기에 실패한 캔이 환불되지 않았습니다\n고객센터로 문의해주세요.") + + val useCan = canRepository.getCanUsedForLiveRoomNotRefund( + memberId = member.id!!, + roomId = roomId, + canUsage = CanUsage.SPIN_ROULETTE + ) ?: throw SodaException("룰렛 돌리기에 실패한 캔이 환불되지 않았습니다\n고객센터로 문의해주세요.") + useCan.isRefund = true + + val useCanCalculates = useCanCalculateRepository.findByUseCanIdAndStatus(useCan.id!!) + useCanCalculates.forEach { + it.status = UseCanCalculateStatus.REFUND + val charge = Charge(0, it.can, status = ChargeStatus.REFUND_CHARGE) + charge.title = "${it.can} 캔" + charge.useCan = useCan + + when (it.paymentGateway) { + PaymentGateway.GOOGLE_IAP -> donator.googleRewardCan += charge.rewardCan + PaymentGateway.APPLE_IAP -> donator.appleRewardCan += charge.rewardCan + else -> donator.pgRewardCan += charge.rewardCan + } + charge.member = donator + + val payment = Payment( + status = PaymentStatus.COMPLETE, + paymentGateway = it.paymentGateway + ) + payment.method = "룰렛 환불" + charge.payment = payment + + chargeRepository.save(charge) + } + } + + private fun rouletteValidate(can: Int, items: List) { + if (can < 5) { + throw SodaException("룰렛 금액은 최소 5캔 입니다.") + } + + if (items.size < 2 || items.size > 10) { + throw SodaException("룰렛 옵션은 최소 2개, 최대 10개까지 설정할 수 있습니다.") + } + } + + companion object { + const val SEQUENCE_NAME = "newRoulette:sequence" + } +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RedisIdGenerator.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RedisIdGenerator.kt new file mode 100644 index 0000000..f6a31e1 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RedisIdGenerator.kt @@ -0,0 +1,11 @@ +package kr.co.vividnext.sodalive.live.roulette + +import org.springframework.data.redis.core.StringRedisTemplate +import org.springframework.stereotype.Service + +@Service +class RedisIdGenerator(private val stringRedisTemplate: StringRedisTemplate) { + fun generateId(key: String): Long { + return stringRedisTemplate.opsForValue().increment(key, 1) ?: 1L + } +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RouletteService.kt index 82d9039..d3826e4 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/RouletteService.kt @@ -86,7 +86,7 @@ class RouletteService( val host = room.member ?: throw SodaException("잘못된 요청입니다.") if (host.role != MemberRole.CREATOR) { - throw SodaException("비비드넥스트와 계약한\n크리에이터에게만 후원을 하실 수 있습니다.") + throw SodaException("비비드넥스트와 계약한\n크리에이터의 룰렛만 사용하실 수 있습니다.") } // STEP 2 - 룰렛 데이터 가져오기 @@ -138,7 +138,7 @@ class RouletteService( status = PaymentStatus.COMPLETE, paymentGateway = it.paymentGateway ) - payment.method = "환불" + payment.method = "룰렛 환불" charge.payment = payment chargeRepository.save(charge) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/UpdateNewRouletteRequest.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/UpdateNewRouletteRequest.kt new file mode 100644 index 0000000..e2752f7 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/UpdateNewRouletteRequest.kt @@ -0,0 +1,8 @@ +package kr.co.vividnext.sodalive.live.roulette + +data class UpdateNewRouletteRequest( + val id: Long, + val can: Int, + val isActive: Boolean, + val items: List +) From 95717824c64a76405a0977b67e7786d90f292ebc Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 16:03:37 +0900 Subject: [PATCH 05/19] =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=ED=94=84=EB=A6=AC?= =?UTF-8?q?=EC=85=8B=20API=20=EC=B6=94=EA=B0=80=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20-=20=EB=A3=B0=EB=A0=9B=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=ED=94=84=EB=A6=AC=EC=85=8B=20=EC=A0=84=EC=B2=B4=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vividnext/sodalive/live/roulette/NewRouletteService.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 4288f3f..3b09e17 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -36,11 +36,11 @@ class NewRouletteService( fun getAllRoulette(creatorId: Long, memberId: Long): List { if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") - val rouletteList = repository.findByCreatorId(creatorId) + var rouletteList = repository.findByCreatorId(creatorId) if (rouletteList.isEmpty()) { val roulette = oldRepository.findByIdOrNull(creatorId) if (roulette != null) { - val newRoulette = repository.save( + repository.save( NewRoulette( id = idGenerator.generateId(SEQUENCE_NAME), creatorId = creatorId, @@ -50,7 +50,7 @@ class NewRouletteService( ) ) - rouletteList.toMutableList().add(newRoulette) + rouletteList = repository.findByCreatorId(creatorId) } } From eb552f01f0d6aff531782f2395bc32112c950ccb Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 16:04:06 +0900 Subject: [PATCH 06/19] =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=ED=94=84=EB=A6=AC?= =?UTF-8?q?=EC=85=8B=20API=20=EC=B6=94=EA=B0=80=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20-=20=EB=A3=B0=EB=A0=9B=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=ED=94=84=EB=A6=AC=EC=85=8B=20=EC=A0=84=EC=B2=B4=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/vividnext/sodalive/live/roulette/NewRouletteService.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 3b09e17..35d8a37 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -55,6 +55,9 @@ class NewRouletteService( } rouletteList.sortedBy { it.id } + + println(rouletteList) + return rouletteList.asSequence() .map { GetNewRouletteResponse( From 6c9d57b18a3a59b5e6d203a1a3d4ade19e4e6e4a Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 16:11:06 +0900 Subject: [PATCH 07/19] =?UTF-8?q?=EB=94=94=EB=B2=84=EA=B9=85=EC=9A=A9=20pr?= =?UTF-8?q?int=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/roulette/NewRouletteService.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 35d8a37..1a0bd72 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -37,16 +37,20 @@ class NewRouletteService( if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") var rouletteList = repository.findByCreatorId(creatorId) + println(rouletteList) if (rouletteList.isEmpty()) { val roulette = oldRepository.findByIdOrNull(creatorId) + println(roulette) if (roulette != null) { - repository.save( - NewRoulette( - id = idGenerator.generateId(SEQUENCE_NAME), - creatorId = creatorId, - can = roulette.can, - isActive = false, - items = roulette.items + println( + repository.save( + NewRoulette( + id = idGenerator.generateId(SEQUENCE_NAME), + creatorId = creatorId, + can = roulette.can, + isActive = false, + items = roulette.items + ) ) ) From 183f8098be297f245757d01e5c1fb62ea14d577b Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 17:26:11 +0900 Subject: [PATCH 08/19] findBy -> findAllBy --- .../sodalive/live/roulette/NewRouletteRepository.kt | 4 ++-- .../sodalive/live/roulette/NewRouletteService.kt | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt index fca5623..76cf94f 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt @@ -3,6 +3,6 @@ package kr.co.vividnext.sodalive.live.roulette import org.springframework.data.repository.CrudRepository interface NewRouletteRepository : CrudRepository { - fun findByCreatorId(creatorId: Long): List - fun findByCreatorIdAndActive(creatorId: Long, isActive: Boolean): List + fun findAllByCreatorId(creatorId: Long): List + fun findAllByCreatorIdAndActive(creatorId: Long, isActive: Boolean): List } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 1a0bd72..691343d 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -36,7 +36,7 @@ class NewRouletteService( fun getAllRoulette(creatorId: Long, memberId: Long): List { if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") - var rouletteList = repository.findByCreatorId(creatorId) + var rouletteList = repository.findAllByCreatorId(creatorId) println(rouletteList) if (rouletteList.isEmpty()) { val roulette = oldRepository.findByIdOrNull(creatorId) @@ -54,7 +54,7 @@ class NewRouletteService( ) ) - rouletteList = repository.findByCreatorId(creatorId) + rouletteList = repository.findAllByCreatorId(creatorId) } } @@ -108,7 +108,7 @@ class NewRouletteService( } fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse { - val roulette = repository.findByCreatorIdAndActive(creatorId = creatorId, isActive = true) + val roulette = repository.findAllByCreatorIdAndActive(creatorId = creatorId, isActive = true) if (roulette.isEmpty() || !roulette[0].isActive || roulette[0].items.isEmpty()) { throw SodaException("룰렛을 사용할 수 없습니다.") @@ -134,7 +134,7 @@ class NewRouletteService( } // STEP 2 - 룰렛 데이터 가져오기 - val rouletteList = repository.findByCreatorIdAndActive(creatorId = host.id!!, isActive = true) + val rouletteList = repository.findAllByCreatorIdAndActive(creatorId = host.id!!, isActive = true) if (rouletteList.isEmpty() || !rouletteList[0].isActive || rouletteList[0].items.isEmpty()) { throw SodaException("룰렛을 사용할 수 없습니다.") From 3e89025fd9edbe089d7432438de6ac6de871ef46 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 18:01:19 +0900 Subject: [PATCH 09/19] =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=ED=94=84=EB=A6=AC?= =?UTF-8?q?=EC=85=8B=20API=20=EC=B6=94=EA=B0=80=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=EB=A7=8C=EB=93=A4=EA=B8=B0=20-=20=EB=A3=B0=EB=A0=9B=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20-=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=20=ED=94=84=EB=A6=AC=EC=85=8B=20=EC=A0=84=EC=B2=B4=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt | 2 ++ .../sodalive/live/roulette/NewRouletteRepository.kt | 4 ++-- .../sodalive/live/roulette/NewRouletteService.kt | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt index 0548502..262bf40 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt @@ -1,12 +1,14 @@ package kr.co.vividnext.sodalive.live.roulette import org.springframework.data.redis.core.RedisHash +import org.springframework.data.redis.core.index.Indexed import javax.persistence.Id @RedisHash("newRoulette") data class NewRoulette( @Id val id: Long, + @Indexed val creatorId: Long, var can: Int, var isActive: Boolean, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt index 76cf94f..fca5623 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt @@ -3,6 +3,6 @@ package kr.co.vividnext.sodalive.live.roulette import org.springframework.data.repository.CrudRepository interface NewRouletteRepository : CrudRepository { - fun findAllByCreatorId(creatorId: Long): List - fun findAllByCreatorIdAndActive(creatorId: Long, isActive: Boolean): List + fun findByCreatorId(creatorId: Long): List + fun findByCreatorIdAndActive(creatorId: Long, isActive: Boolean): List } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 691343d..1a0bd72 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -36,7 +36,7 @@ class NewRouletteService( fun getAllRoulette(creatorId: Long, memberId: Long): List { if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") - var rouletteList = repository.findAllByCreatorId(creatorId) + var rouletteList = repository.findByCreatorId(creatorId) println(rouletteList) if (rouletteList.isEmpty()) { val roulette = oldRepository.findByIdOrNull(creatorId) @@ -54,7 +54,7 @@ class NewRouletteService( ) ) - rouletteList = repository.findAllByCreatorId(creatorId) + rouletteList = repository.findByCreatorId(creatorId) } } @@ -108,7 +108,7 @@ class NewRouletteService( } fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse { - val roulette = repository.findAllByCreatorIdAndActive(creatorId = creatorId, isActive = true) + val roulette = repository.findByCreatorIdAndActive(creatorId = creatorId, isActive = true) if (roulette.isEmpty() || !roulette[0].isActive || roulette[0].items.isEmpty()) { throw SodaException("룰렛을 사용할 수 없습니다.") @@ -134,7 +134,7 @@ class NewRouletteService( } // STEP 2 - 룰렛 데이터 가져오기 - val rouletteList = repository.findAllByCreatorIdAndActive(creatorId = host.id!!, isActive = true) + val rouletteList = repository.findByCreatorIdAndActive(creatorId = host.id!!, isActive = true) if (rouletteList.isEmpty() || !rouletteList[0].isActive || rouletteList[0].items.isEmpty()) { throw SodaException("룰렛을 사용할 수 없습니다.") From 4fb97a7c956271a2413795233e9c9a62069f06df Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 18:27:56 +0900 Subject: [PATCH 10/19] =?UTF-8?q?=EB=94=94=EB=B2=84=EA=B9=85=EC=9A=A9=20pr?= =?UTF-8?q?int=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/roulette/NewRouletteService.kt | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 1a0bd72..a58dfb0 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -37,31 +37,25 @@ class NewRouletteService( if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") var rouletteList = repository.findByCreatorId(creatorId) - println(rouletteList) if (rouletteList.isEmpty()) { val roulette = oldRepository.findByIdOrNull(creatorId) - println(roulette) if (roulette != null) { - println( - repository.save( - NewRoulette( - id = idGenerator.generateId(SEQUENCE_NAME), - creatorId = creatorId, - can = roulette.can, - isActive = false, - items = roulette.items - ) + repository.save( + NewRoulette( + id = idGenerator.generateId(SEQUENCE_NAME), + creatorId = creatorId, + can = roulette.can, + isActive = false, + items = roulette.items ) ) rouletteList = repository.findByCreatorId(creatorId) + oldRepository.deleteById(roulette.creatorId) } } - rouletteList.sortedBy { it.id } - println(rouletteList) - return rouletteList.asSequence() .map { GetNewRouletteResponse( From 7328283b6b1b5ac957d83213a221655763563ea7 Mon Sep 17 00:00:00 2001 From: Klaus Date: Thu, 22 Feb 2024 18:34:07 +0900 Subject: [PATCH 11/19] =?UTF-8?q?=EB=94=94=EB=B2=84=EA=B9=85=EC=9A=A9=20pr?= =?UTF-8?q?int=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/vividnext/sodalive/live/roulette/NewRouletteService.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index a58dfb0..1c93c64 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -37,8 +37,10 @@ class NewRouletteService( if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") var rouletteList = repository.findByCreatorId(creatorId) + println(rouletteList) if (rouletteList.isEmpty()) { val roulette = oldRepository.findByIdOrNull(creatorId) + println(roulette) if (roulette != null) { repository.save( NewRoulette( @@ -55,6 +57,8 @@ class NewRouletteService( } } rouletteList.sortedBy { it.id } + println(rouletteList) + println(oldRepository.findByIdOrNull(creatorId)) return rouletteList.asSequence() .map { From b16342751429f800b7dddc67f88f31839e6ddeab Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 23 Feb 2024 14:04:23 +0900 Subject: [PATCH 12/19] =?UTF-8?q?=EB=94=94=EB=B2=84=EA=B9=85=EC=9A=A9=20pr?= =?UTF-8?q?int=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/vividnext/sodalive/live/roulette/NewRouletteService.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 1c93c64..a58dfb0 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -37,10 +37,8 @@ class NewRouletteService( if (creatorId != memberId) throw SodaException("잘못된 요청입니다.") var rouletteList = repository.findByCreatorId(creatorId) - println(rouletteList) if (rouletteList.isEmpty()) { val roulette = oldRepository.findByIdOrNull(creatorId) - println(roulette) if (roulette != null) { repository.save( NewRoulette( @@ -57,8 +55,6 @@ class NewRouletteService( } } rouletteList.sortedBy { it.id } - println(rouletteList) - println(oldRepository.findByIdOrNull(creatorId)) return rouletteList.asSequence() .map { From 01aeb8e759b05866d4431366bba5e3a6f4ca8267 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 23 Feb 2024 14:12:30 +0900 Subject: [PATCH 13/19] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EC=A2=85?= =?UTF-8?q?=EB=A3=8C=20-=20=EB=AA=A8=EB=93=A0=20=EB=A3=B0=EB=A0=9B=20?= =?UTF-8?q?=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/live/room/LiveRoomService.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 25ab32f..1a3feaa 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 @@ -39,7 +39,7 @@ 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.visit.LiveRoomVisitService -import kr.co.vividnext.sodalive.live.roulette.RouletteRepository +import kr.co.vividnext.sodalive.live.roulette.NewRouletteRepository import kr.co.vividnext.sodalive.live.tag.LiveTagRepository import kr.co.vividnext.sodalive.member.Gender import kr.co.vividnext.sodalive.member.Member @@ -66,7 +66,7 @@ import kotlin.concurrent.write @Transactional(readOnly = true) class LiveRoomService( private val repository: LiveRoomRepository, - private val rouletteRepository: RouletteRepository, + private val rouletteRepository: NewRouletteRepository, private val roomInfoRepository: LiveRoomInfoRedisRepository, private val roomCancelRepository: LiveRoomCancelRepository, private val kickOutService: LiveRoomKickOutService, @@ -1004,10 +1004,12 @@ class LiveRoomService( kickOutService.deleteKickOutData(roomId = room.id!!) roomInfoRepository.deleteById(roomInfo.roomId) - val roulette = rouletteRepository.findByIdOrNull(member.id!!) - if (roulette != null) { - roulette.isActive = false - rouletteRepository.save(roulette) + val rouletteList = rouletteRepository.findByCreatorId(creatorId = member.id!!) + if (rouletteList.isNotEmpty()) { + rouletteList.forEach { + it.isActive = false + rouletteRepository.save(it) + } } } else { roomInfo.removeSpeaker(member) From c097cb54f17c357e1442d38c9af3b8127a3c4c58 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 23 Feb 2024 14:20:02 +0900 Subject: [PATCH 14/19] =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20-=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= =?UTF-8?q?=20=ED=95=98=EB=8A=94=20=EB=A3=B0=EB=A0=9B=EC=9D=B4=20=ED=99=9C?= =?UTF-8?q?=EC=84=B1=ED=99=94=20=EB=90=98=EB=8A=94=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EB=8B=A4=EB=A5=B8=20=EB=A3=B0=EB=A0=9B=20=EB=AA=A8=EB=91=90=20?= =?UTF-8?q?=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/roulette/NewRouletteService.kt | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index a58dfb0..8f88cb0 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -86,18 +86,38 @@ class NewRouletteService( fun updateRoulette(memberId: Long, request: UpdateNewRouletteRequest): Boolean { rouletteValidate(can = request.can, items = request.items) - val roulette = repository.findByIdOrNull(request.id) - ?: throw SodaException("잘못된 요청입니다.") + if (request.isActive) { + val rouletteList = repository.findByCreatorId(creatorId = memberId) - if (roulette.creatorId != memberId) { - throw SodaException("잘못된 요청입니다.") + if (rouletteList.isEmpty()) { + throw SodaException("잘못된 요청입니다.") + } + + rouletteList.forEach { + if (it.id == request.id) { + it.can = request.can + it.items = request.items + it.isActive = true + } else { + it.isActive = false + } + + repository.save(it) + } + } else { + val roulette = repository.findByIdOrNull(request.id) + ?: throw SodaException("잘못된 요청입니다.") + + if (roulette.creatorId != memberId) { + throw SodaException("잘못된 요청입니다.") + } + + roulette.can = request.can + roulette.items = request.items + roulette.isActive = false + repository.save(roulette) } - roulette.can = request.can - roulette.items = request.items - roulette.isActive = request.isActive - repository.save(roulette) - return request.isActive } From 0e9863050ffbb2a8a72ab064c6e1d62dcc23c48c Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 23 Feb 2024 16:31:57 +0900 Subject: [PATCH 15/19] =?UTF-8?q?@Indexed=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt index 262bf40..90dd115 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt @@ -11,6 +11,7 @@ data class NewRoulette( @Indexed val creatorId: Long, var can: Int, + @Indexed var isActive: Boolean, var items: List = mutableListOf() ) From bcd094c5dd412bb4ba1fb8bfc565eb25cf773c8f Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 23 Feb 2024 16:47:49 +0900 Subject: [PATCH 16/19] =?UTF-8?q?=ED=99=9C=EC=84=B1=ED=99=94=EB=90=9C=20?= =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/live/roulette/NewRoulette.kt | 1 - .../live/roulette/NewRouletteRepository.kt | 1 - .../live/roulette/NewRouletteService.kt | 47 +++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt index 90dd115..262bf40 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRoulette.kt @@ -11,7 +11,6 @@ data class NewRoulette( @Indexed val creatorId: Long, var can: Int, - @Indexed var isActive: Boolean, var items: List = mutableListOf() ) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt index fca5623..f2043be 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteRepository.kt @@ -4,5 +4,4 @@ import org.springframework.data.repository.CrudRepository interface NewRouletteRepository : CrudRepository { fun findByCreatorId(creatorId: Long): List - fun findByCreatorIdAndActive(creatorId: Long, isActive: Boolean): List } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index 8f88cb0..e457872 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -122,16 +122,28 @@ class NewRouletteService( } fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse { - val roulette = repository.findByCreatorIdAndActive(creatorId = creatorId, isActive = true) + val rouletteList = repository.findByCreatorId(creatorId = creatorId) - if (roulette.isEmpty() || !roulette[0].isActive || roulette[0].items.isEmpty()) { + if (rouletteList.isEmpty()) { + throw SodaException("룰렛을 사용할 수 없습니다.") + } + + var activeRoulette: NewRoulette? = null + for (roulette in rouletteList) { + if (roulette.isActive) { + activeRoulette = roulette + break + } + } + + if (activeRoulette == null || activeRoulette.items.isEmpty()) { throw SodaException("룰렛을 사용할 수 없습니다.") } return GetRouletteResponse( - can = roulette[0].can, - isActive = roulette[0].isActive, - items = roulette[0].items + can = activeRoulette.can, + isActive = activeRoulette.isActive, + items = activeRoulette.items ) } @@ -148,23 +160,38 @@ class NewRouletteService( } // STEP 2 - 룰렛 데이터 가져오기 - val rouletteList = repository.findByCreatorIdAndActive(creatorId = host.id!!, isActive = true) + val rouletteList = repository.findByCreatorId(creatorId = host.id!!) - if (rouletteList.isEmpty() || !rouletteList[0].isActive || rouletteList[0].items.isEmpty()) { + if (rouletteList.isEmpty()) { + throw SodaException("룰렛을 사용할 수 없습니다.") + } + + var activeRoulette: NewRoulette? = null + for (roulette in rouletteList) { + if (roulette.isActive) { + activeRoulette = roulette + break + } + } + + if (activeRoulette == null || activeRoulette.items.isEmpty()) { throw SodaException("룰렛을 사용할 수 없습니다.") } // STEP 3 - 캔 사용 - val roulette = rouletteList[0] canPaymentService.spendCan( memberId = memberId, - needCan = roulette.can, + needCan = activeRoulette.can, canUsage = CanUsage.SPIN_ROULETTE, liveRoom = room, container = request.container ) - return GetRouletteResponse(can = roulette.can, isActive = roulette.isActive, items = roulette.items) + return GetRouletteResponse( + can = activeRoulette.can, + isActive = activeRoulette.isActive, + items = activeRoulette.items + ) } @Transactional From 348936a67e69c1efd7f0bdff539b0a6380dd5fc7 Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 23 Feb 2024 16:53:26 +0900 Subject: [PATCH 17/19] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0=20-=20?= =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=ED=99=9C=EC=84=B1=ED=99=94=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../co/vividnext/sodalive/live/room/LiveRoomService.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 1a3feaa..7fb751c 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 @@ -679,7 +679,15 @@ class LiveRoomService( .getNotificationUserIds(room.member!!.id!!) .contains(member.id) - val isActiveRoulette = rouletteRepository.findByIdOrNull(room.member!!.id!!)?.isActive ?: false + var isActiveRoulette = false + val rouletteList = rouletteRepository.findByCreatorId(creatorId = room.member!!.id!!) + + for (roulette in rouletteList) { + if (roulette.isActive) { + isActiveRoulette = true + break + } + } val donationRankingTop3UserIds = if (room.member!!.isVisibleDonationRank) { explorerQueryRepository From 9f3a25bd7defdc9e2b9e8a59da7b1283255e73bc Mon Sep 17 00:00:00 2001 From: Klaus Date: Fri, 23 Feb 2024 17:47:09 +0900 Subject: [PATCH 18/19] =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20-=20=EB=A3=B0=EB=A0=9B=20=ED=94=84?= =?UTF-8?q?=EB=A6=AC=EC=85=8B=20=EC=A4=91=20=ED=95=98=EB=82=98=EB=9D=BC?= =?UTF-8?q?=EB=8F=84=20=ED=99=9C=EC=84=B1=ED=99=94=20=EB=90=98=EC=96=B4=20?= =?UTF-8?q?=EC=9E=88=EC=9C=BC=EB=A9=B4=20=EA=B2=B0=EA=B3=BC=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20=ED=99=9C=EC=84=B1=ED=99=94=EB=A1=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=84=B4=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live/roulette/NewRouletteService.kt | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index e457872..c12ae55 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -86,39 +86,30 @@ class NewRouletteService( fun updateRoulette(memberId: Long, request: UpdateNewRouletteRequest): Boolean { rouletteValidate(can = request.can, items = request.items) - if (request.isActive) { - val rouletteList = repository.findByCreatorId(creatorId = memberId) + val rouletteList = repository.findByCreatorId(creatorId = memberId) - if (rouletteList.isEmpty()) { - throw SodaException("잘못된 요청입니다.") - } - - rouletteList.forEach { - if (it.id == request.id) { - it.can = request.can - it.items = request.items - it.isActive = true - } else { - it.isActive = false - } - - repository.save(it) - } - } else { - val roulette = repository.findByIdOrNull(request.id) - ?: throw SodaException("잘못된 요청입니다.") - - if (roulette.creatorId != memberId) { - throw SodaException("잘못된 요청입니다.") - } - - roulette.can = request.can - roulette.items = request.items - roulette.isActive = false - repository.save(roulette) + if (rouletteList.isEmpty()) { + throw SodaException("잘못된 요청입니다.") } - return request.isActive + var isActive = false + rouletteList.forEach { + if (request.isActive || it.isActive) { + isActive = true + } + + if (it.id == request.id) { + it.can = request.can + it.items = request.items + it.isActive = request.isActive + repository.save(it) + } else if (request.isActive) { + it.isActive = false + repository.save(it) + } + } + + return isActive } fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse { From 0826db0a5b10094bfca5e75101f9d9f9c61eb77c Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 24 Feb 2024 02:25:46 +0900 Subject: [PATCH 19/19] =?UTF-8?q?=EB=A3=B0=EB=A0=9B=20=EB=A7=8C=EB=93=A4?= =?UTF-8?q?=EA=B8=B0=20-=20=EB=A7=8C=EB=93=9C=EB=8A=94=20=EB=A3=B0?= =?UTF-8?q?=EB=A0=9B=EC=9D=B4=20=ED=99=9C=EC=84=B1=ED=99=94=ED=95=98?= =?UTF-8?q?=EB=A9=B4=20=EB=82=98=EB=A8=B8=EC=A7=80=20=EB=A3=B0=EB=A0=9B?= =?UTF-8?q?=EC=9D=84=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94=20=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/live/roulette/NewRouletteService.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt index c12ae55..fa3ea40 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/roulette/NewRouletteService.kt @@ -71,6 +71,14 @@ class NewRouletteService( fun createRoulette(memberId: Long, request: CreateNewRouletteRequest): Boolean { rouletteValidate(can = request.can, items = request.items) + if (request.isActive) { + val rouletteList = repository.findByCreatorId(creatorId = memberId) + rouletteList.forEach { + it.isActive = false + repository.save(it) + } + } + val roulette = NewRoulette( id = idGenerator.generateId(SEQUENCE_NAME), creatorId = memberId,