시그니처 후원
- 재생 시간 추가
This commit is contained in:
		| @@ -205,6 +205,16 @@ class LiveRoomController( | ||||
|         ApiResponse.ok(service.donation(request, member)) | ||||
|     } | ||||
|  | ||||
|     @PostMapping("/donation/v2") | ||||
|     fun donationV2( | ||||
|         @RequestBody request: LiveRoomDonationRequest, | ||||
|         @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member? | ||||
|     ) = run { | ||||
|         if (member == null) throw SodaException("로그인 정보를 확인해주세요.") | ||||
|  | ||||
|         ApiResponse.ok(service.donationV2(request, member)) | ||||
|     } | ||||
|  | ||||
|     @PostMapping("/donation/refund/{id}") | ||||
|     fun refundDonation( | ||||
|         @PathVariable id: Long, | ||||
|   | ||||
| @@ -33,6 +33,7 @@ import kr.co.vividnext.sodalive.live.room.donation.GetLiveRoomDonationStatusResp | ||||
| import kr.co.vividnext.sodalive.live.room.donation.GetLiveRoomDonationTotalResponse | ||||
| import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationMessage | ||||
| import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationRequest | ||||
| import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationResponse | ||||
| import kr.co.vividnext.sodalive.live.room.info.GetRoomInfoResponse | ||||
| import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfo | ||||
| import kr.co.vividnext.sodalive.live.room.info.LiveRoomInfoRedisRepository | ||||
| @@ -1059,6 +1060,49 @@ class LiveRoomService( | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     @Transactional | ||||
|     fun donationV2(request: LiveRoomDonationRequest, member: Member): LiveRoomDonationResponse? { | ||||
|         val room = repository.findByIdOrNull(request.roomId) | ||||
|             ?: throw SodaException("해당하는 라이브가 없습니다.") | ||||
|  | ||||
|         val host = room.member ?: throw SodaException("잘못된 요청입니다.") | ||||
|  | ||||
|         if (host.role != MemberRole.CREATOR) { | ||||
|             throw SodaException("비비드넥스트와 계약한\n크리에이터에게만 후원을 하실 수 있습니다.") | ||||
|         } | ||||
|  | ||||
|         canPaymentService.spendCan( | ||||
|             memberId = member.id!!, | ||||
|             needCan = request.can, | ||||
|             canUsage = CanUsage.DONATION, | ||||
|             liveRoom = room, | ||||
|             container = request.container | ||||
|         ) | ||||
|  | ||||
|         if (request.message.isNotBlank()) { | ||||
|             val lock = getOrCreateLock(memberId = member.id!!) | ||||
|             lock.write { | ||||
|                 val roomInfo = roomInfoRepository.findByIdOrNull(room.id!!) | ||||
|                     ?: throw SodaException("해당하는 라이브의 정보가 없습니다.") | ||||
|  | ||||
|                 roomInfo.addDonationMessage( | ||||
|                     nickname = member.nickname, | ||||
|                     can = request.can, | ||||
|                     donationMessage = request.message | ||||
|                 ) | ||||
|  | ||||
|                 roomInfoRepository.save(roomInfo) | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return signatureCanRepository.findByCreatorIdAndCan( | ||||
|             creatorId = host.id!!, | ||||
|             can = request.can, | ||||
|             imageHost = cloudFrontHost, | ||||
|             isAdult = room.isAdult | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     @Transactional | ||||
|     fun refundDonation(roomId: Long, member: Member) { | ||||
|         val donator = memberRepository.findByIdOrNull(member.id) | ||||
|   | ||||
| @@ -0,0 +1,5 @@ | ||||
| package kr.co.vividnext.sodalive.live.room.donation | ||||
|  | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
|  | ||||
| data class LiveRoomDonationResponse @QueryProjection constructor(val imageUrl: String, val time: Int) | ||||
| @@ -1,6 +1,8 @@ | ||||
| package kr.co.vividnext.sodalive.live.signature | ||||
|  | ||||
| import com.querydsl.jpa.impl.JPAQueryFactory | ||||
| import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationResponse | ||||
| import kr.co.vividnext.sodalive.live.room.donation.QLiveRoomDonationResponse | ||||
| import kr.co.vividnext.sodalive.live.signature.QSignatureCan.signatureCan | ||||
| import org.springframework.data.jpa.repository.JpaRepository | ||||
|  | ||||
| @@ -8,6 +10,7 @@ interface SignatureCanRepository : JpaRepository<SignatureCan, Long>, SignatureC | ||||
|  | ||||
| interface SignatureCanQueryRepository { | ||||
|     fun findImageByCreatorIdAndCan(creatorId: Long, can: Int, imageHost: String, isAdult: Boolean): String? | ||||
|     fun findByCreatorIdAndCan(creatorId: Long, can: Int, imageHost: String, isAdult: Boolean): LiveRoomDonationResponse? | ||||
| } | ||||
|  | ||||
| class SignatureCanQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : SignatureCanQueryRepository { | ||||
| @@ -27,4 +30,31 @@ class SignatureCanQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) | ||||
|             .orderBy(signatureCan.isAdult.desc()) | ||||
|             .fetchFirst() | ||||
|     } | ||||
|  | ||||
|     override fun findByCreatorIdAndCan( | ||||
|         creatorId: Long, | ||||
|         can: Int, | ||||
|         imageHost: String, | ||||
|         isAdult: Boolean | ||||
|     ): LiveRoomDonationResponse? { | ||||
|         var where = signatureCan.creator.id.eq(creatorId) | ||||
|             .and(signatureCan.can.eq(can)) | ||||
|             .and(signatureCan.isActive.isTrue) | ||||
|  | ||||
|         if (!isAdult) { | ||||
|             where = where.and(signatureCan.isAdult.isFalse()) | ||||
|         } | ||||
|  | ||||
|         return queryFactory | ||||
|             .select( | ||||
|                 QLiveRoomDonationResponse( | ||||
|                     signatureCan.image.prepend("/").prepend(imageHost), | ||||
|                     signatureCan.time | ||||
|                 ) | ||||
|             ) | ||||
|             .from(signatureCan) | ||||
|             .where(where) | ||||
|             .orderBy(signatureCan.isAdult.desc()) | ||||
|             .fetchFirst() | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user