diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/live/recommend/LiveRecommendRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/live/recommend/LiveRecommendRepository.kt index 6cb0357..2032a5b 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/live/recommend/LiveRecommendRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/live/recommend/LiveRecommendRepository.kt @@ -195,6 +195,7 @@ class LiveRecommendRepository( .and(member.id.notIn(withOutCreatorList)) .and(creatorFollowing.isActive.isTrue) .and(creatorFollowing.member.id.eq(memberId)) + .and(creatorFollowing.member.isActive.isTrue) ) .orderBy(Expressions.numberTemplate(Double::class.java, "function('rand')").asc()) .limit(limit) @@ -209,6 +210,7 @@ class LiveRecommendRepository( .and(member.isActive.isTrue) .and(creatorFollowing.isActive.isTrue) .and(creatorFollowing.member.id.eq(memberId)) + .and(creatorFollowing.member.isActive.isTrue) return queryFactory .select(creatorFollowing.creator.id) @@ -233,6 +235,7 @@ class LiveRecommendRepository( .and(member.isActive.isTrue) .and(creatorFollowing.isActive.isTrue) .and(creatorFollowing.member.id.eq(memberId)) + .and(creatorFollowing.member.isActive.isTrue) return queryFactory .select( diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt index e65e2e9..91da556 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberController.kt @@ -6,6 +6,7 @@ import kr.co.vividnext.sodalive.member.block.MemberBlockRequest import kr.co.vividnext.sodalive.member.following.CreatorFollowRequest import kr.co.vividnext.sodalive.member.login.LoginRequest import kr.co.vividnext.sodalive.member.notification.UpdateNotificationSettingRequest +import org.springframework.data.domain.Pageable import org.springframework.security.core.annotation.AuthenticationPrincipal import org.springframework.security.core.userdetails.User import org.springframework.web.bind.annotation.GetMapping @@ -153,6 +154,32 @@ class MemberController(private val service: MemberService) { ApiResponse.ok(service.creatorUnFollow(creatorId = request.creatorId, memberId = member.id!!)) } + @GetMapping("/block/id") + fun getBlockedMemberIdList( + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?, + pageable: Pageable + ) = run { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + ApiResponse.ok(service.getBlockedMemberIdList(member.id!!)) + } + + @GetMapping("/block") + fun getBlockedMemberList( + @AuthenticationPrincipal(expression = "#this == 'anonymousUser' ? null : member") member: Member?, + pageable: Pageable + ) = run { + if (member == null) throw SodaException("로그인 정보를 확인해주세요.") + + ApiResponse.ok( + service.getBlockedMemberList( + member.id!!, + offset = pageable.offset, + limit = pageable.pageSize.toLong() + ) + ) + } + @PostMapping("/block") fun memberBlock( @RequestBody request: MemberBlockRequest, diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt index 364f2e4..177b2d2 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberRepository.kt @@ -135,7 +135,7 @@ class MemberQueryRepositoryImpl( .and(creatorFollowing.member.email.notIn("admin@sodalive.net")) .and( creatorFollowing.member.id.notIn( - blockMemberRepository.getBlockedMemberList(creatorId) + blockMemberRepository.getBlockedMemberIdList(creatorId) ) ) .and(creatorFollowing.member.pushToken.isNotNull) @@ -179,7 +179,7 @@ class MemberQueryRepositoryImpl( .and(creatorFollowing.member.email.notIn("admin@sodalive.net")) .and( creatorFollowing.member.id.notIn( - blockMemberRepository.getBlockedMemberList(creatorId) + blockMemberRepository.getBlockedMemberIdList(creatorId) ) ) .and(creatorFollowing.member.pushToken.isNotNull) @@ -211,7 +211,7 @@ class MemberQueryRepositoryImpl( .and(liveReservation.room.id.eq(roomId)) .and( liveReservation.member.id.notIn( - blockMemberRepository.getBlockedMemberList(creatorId) + blockMemberRepository.getBlockedMemberIdList(creatorId) ) ) @@ -248,7 +248,7 @@ class MemberQueryRepositoryImpl( .and(creatorFollowing.member.notification.uploadContent.isTrue) .and( creatorFollowing.member.id.notIn( - blockMemberRepository.getBlockedMemberList(creatorId) + blockMemberRepository.getBlockedMemberIdList(creatorId) ) ) .and(creatorFollowing.member.pushToken.isNotNull) @@ -361,7 +361,7 @@ class MemberQueryRepositoryImpl( .and(creatorFollowing.member.email.notIn("admin@sodalive.net")) .and( creatorFollowing.member.id.notIn( - blockMemberRepository.getBlockedMemberList(creatorId) + blockMemberRepository.getBlockedMemberIdList(creatorId) ) ) .and(creatorFollowing.member.pushToken.isNotNull) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberService.kt index de05f33..e658ba2 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/MemberService.kt @@ -14,6 +14,7 @@ import kr.co.vividnext.sodalive.live.reservation.LiveReservationRepository import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailUser import kr.co.vividnext.sodalive.member.block.BlockMember import kr.co.vividnext.sodalive.member.block.BlockMemberRepository +import kr.co.vividnext.sodalive.member.block.GetBlockedMemberListResponse import kr.co.vividnext.sodalive.member.block.MemberBlockRequest import kr.co.vividnext.sodalive.member.following.CreatorFollowing import kr.co.vividnext.sodalive.member.following.CreatorFollowingRepository @@ -357,6 +358,17 @@ class MemberService( } } + fun getBlockedMemberIdList(memberId: Long): List { + return blockMemberRepository.getBlockedMemberIdList(memberId) + } + + fun getBlockedMemberList(memberId: Long, offset: Long, limit: Long): GetBlockedMemberListResponse { + val totalCount = blockMemberRepository.getBlockedMemberTotalCount(memberId) + val items = blockMemberRepository.getBlockedMemberList(offset = offset, limit = limit, memberId = memberId) + + return GetBlockedMemberListResponse(totalCount = totalCount, items = items) + } + @Transactional fun memberBlock(request: MemberBlockRequest, memberId: Long) { var blockMember = blockMemberRepository.getBlockAccount( @@ -365,10 +377,15 @@ class MemberService( ) if (blockMember == null) { - blockMember = BlockMember( - blockedMemberId = request.blockMemberId, - memberId = memberId - ) + val blockedMember = repository.findByIdOrNull(id = request.blockMemberId) + ?: throw SodaException("잘못된 요청입니다.") + + val member = repository.findByIdOrNull(id = memberId) + ?: throw SodaException("잘못된 요청입니다.") + + blockMember = BlockMember() + blockMember.member = member + blockMember.blockedMember = blockedMember blockMemberRepository.save(blockMember) } else { diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMember.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMember.kt index 57811cd..a19cd35 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMember.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMember.kt @@ -1,12 +1,21 @@ package kr.co.vividnext.sodalive.member.block import kr.co.vividnext.sodalive.common.BaseEntity +import kr.co.vividnext.sodalive.member.Member import javax.persistence.Entity +import javax.persistence.FetchType +import javax.persistence.JoinColumn +import javax.persistence.ManyToOne @Entity data class BlockMember( - val blockedMemberId: Long, - val memberId: Long -) : BaseEntity() { var isActive: Boolean = true +) : BaseEntity() { + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "blocked_member_id", nullable = false) + var blockedMember: Member? = null + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + var member: Member? = null } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMemberRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMemberRepository.kt index f81572d..155c454 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMemberRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/block/BlockMemberRepository.kt @@ -1,7 +1,9 @@ package kr.co.vividnext.sodalive.member.block import com.querydsl.jpa.impl.JPAQueryFactory +import kr.co.vividnext.sodalive.member.QMember.member import kr.co.vividnext.sodalive.member.block.QBlockMember.blockMember +import org.springframework.beans.factory.annotation.Value import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository @@ -11,17 +13,24 @@ interface BlockMemberRepository : JpaRepository, BlockMemberQ interface BlockMemberQueryRepository { fun getBlockAccount(blockedMemberId: Long, memberId: Long): BlockMember? fun isBlocked(blockedMemberId: Long, memberId: Long): Boolean - fun getBlockedMemberList(creatorId: Long): List + fun getBlockedMemberIdList(memberId: Long): List + fun getBlockedMemberList(offset: Long, limit: Long, memberId: Long): List + fun getBlockedMemberTotalCount(memberId: Long): Int } @Repository -class BlockMemberQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : BlockMemberQueryRepository { +class BlockMemberQueryRepositoryImpl( + private val queryFactory: JPAQueryFactory, + + @Value("\${cloud.aws.cloud-front.host}") + private val cloudFrontHost: String +) : BlockMemberQueryRepository { override fun getBlockAccount(blockedMemberId: Long, memberId: Long): BlockMember? { return queryFactory .selectFrom(blockMember) .where( - blockMember.blockedMemberId.eq(blockedMemberId) - .and(blockMember.memberId.eq(memberId)) + blockMember.blockedMember.id.eq(blockedMemberId) + .and(blockMember.member.id.eq(memberId)) ) .orderBy(blockMember.id.desc()) .fetchFirst() @@ -32,8 +41,8 @@ class BlockMemberQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) .select(blockMember.id) .from(blockMember) .where( - blockMember.memberId.eq(memberId) - .and(blockMember.blockedMemberId.eq(blockedMemberId)) + blockMember.member.id.eq(memberId) + .and(blockMember.blockedMember.id.eq(blockedMemberId)) .and(blockMember.isActive.isTrue) ) .fetchOne() @@ -41,14 +50,49 @@ class BlockMemberQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) return blockedAccount != null } - override fun getBlockedMemberList(creatorId: Long): List { + override fun getBlockedMemberIdList(memberId: Long): List { return queryFactory - .select(blockMember.blockedMemberId) + .select(blockMember.blockedMember.id) .from(blockMember) .where( - blockMember.memberId.eq(creatorId) + blockMember.member.id.eq(memberId) .and(blockMember.isActive.isTrue) ) .fetch() } + + override fun getBlockedMemberList(offset: Long, limit: Long, memberId: Long): List { + return queryFactory + .select( + QGetBlockedMemberListItem( + blockMember.blockedMember.id, + blockMember.blockedMember.nickname, + blockMember.blockedMember.profileImage.prepend("/").prepend(cloudFrontHost), + blockMember.isActive + ) + ) + .from(blockMember) + .innerJoin(blockMember.blockedMember, member) + .where( + blockMember.member.id.eq(memberId) + .and(blockMember.isActive.isTrue) + .and(blockMember.blockedMember.isActive.isTrue) + ) + .offset(offset) + .limit(limit) + .fetch() + } + + override fun getBlockedMemberTotalCount(memberId: Long): Int { + return queryFactory + .select(blockMember.id) + .from(blockMember) + .where( + blockMember.member.id.eq(memberId) + .and(blockMember.isActive.isTrue) + .and(blockMember.blockedMember.isActive.isTrue) + ) + .fetch() + .size + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/member/block/GetBlockedMemberListResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/member/block/GetBlockedMemberListResponse.kt new file mode 100644 index 0000000..057fd13 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/member/block/GetBlockedMemberListResponse.kt @@ -0,0 +1,15 @@ +package kr.co.vividnext.sodalive.member.block + +import com.querydsl.core.annotations.QueryProjection + +data class GetBlockedMemberListResponse( + val totalCount: Int, + val items: List +) + +data class GetBlockedMemberListItem @QueryProjection constructor( + val memberId: Long, + val nickname: String, + val profileImageUrl: String, + val isBlocked: Boolean +)