Skip to content

Commit

Permalink
Merge pull request #84 from YAPP-Github/feature/jake/deactivate-member
Browse files Browse the repository at this point in the history
feat: detail에 own 댓글 추가
  • Loading branch information
kingjakeu authored Jul 24, 2023
2 parents eb42d4b + bdb0b5e commit e55a3b7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.yapp.cvs.admin.product

import com.yapp.cvs.admin.product.dto.ProductSearchFormDTO
import com.yapp.cvs.admin.product.dto.ProductUpdateRequestDTO
import com.yapp.cvs.domain.member.entity.Member
import com.yapp.cvs.domain.product.application.ProductProcessor
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
Expand All @@ -26,10 +27,11 @@ class ProductController(

@GetMapping("/{productId}")
fun getProductDetail(
member: Member,
@PathVariable productId: Long,
model: Model
): String{
val vo = productProcessor.getProductDetail(productId, 1L)
val vo = productProcessor.getProductDetail(productId, member)
model.addAttribute("contents", vo)
return "product/detail"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ProductController(
@Parameter(hidden = true) member: Member,
@PathVariable productId: Long
): ProductDetailDTO {
return ProductDetailDTO.from(productProcessor.getProductDetail(productId, member.memberId!!))
return ProductDetailDTO.from(productProcessor.getProductDetail(productId, member))
}

@GetMapping("/search")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yapp.cvs.api.product.dto

import com.yapp.cvs.api.comment.dto.ProductCommentDTO
import com.yapp.cvs.domain.product.vo.ProductDetailVO

data class ProductDetailDTO(
Expand All @@ -13,7 +14,8 @@ data class ProductDetailDTO(
val imageUrl: String?,
val promotionList: List<ProductPromotionDTO>,
val score: ProductScoreDTO?,
val commentCount: Long
val commentCount: Long,
val ownComment: ProductCommentDTO?
) {
companion object {
fun from(productDetailVO: ProductDetailVO): ProductDetailDTO {
Expand All @@ -28,7 +30,8 @@ data class ProductDetailDTO(
imageUrl = productDetailVO.imageUrl,
promotionList = productDetailVO.productPromotionVOList.map { ProductPromotionDTO.from(it) },
score = productDetailVO.productScoreVO?.let { ProductScoreDTO.from(it) },
commentCount = productDetailVO.commentCount
commentCount = productDetailVO.commentCount,
ownComment = productDetailVO.ownCommentVO?.let { ProductCommentDTO.from(it) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class ProductCommentService(
?: throw NotFoundSourceException("commentId: $commentId 에 해당하는 코멘트가 존재하지 않습니다.")
}

fun findProductCommentByMember(productId: Long, member: Member): ProductCommentVO? {
val productCommentView = productCommentRepository.findByProductIdAndMemberId(productId, member.memberId!!)

return productCommentView?.let {
ProductCommentVO.of(it, member,
productCommentRatingHistoryRepository.findLatestMemberRatingOnProductComment(it.productComment.memberId, it.productComment.productCommentId!!))
}
}

fun findAllByMember(memberId: Long): List<ProductComment> {
return productCommentRepository.findAllByMemberId(memberId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ interface ProductCommentRepositoryCustom {
fun findLatestByProductIdAndMemberId(productId: Long, memberId: Long): ProductComment?
fun findByProductIdAndSearchCondition(productId: Long, productCommentSearchVO: ProductCommentSearchVO): List<ProductCommentView>
fun findRecentCommentList(size: Int): List<ProductCommentDetailView>
fun findByProductIdAndMemberId(productId: Long, memberId: Long): ProductCommentView?
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ class ProductCommentRepositoryRepositoryImpl: QuerydslRepositorySupport(ProductC
).fetch()
}

override fun findByProductIdAndMemberId(productId: Long, memberId: Long): ProductCommentView? {
return from(productComment)
.leftJoin(productCommentRatingSummary)
.on(productComment.productCommentId.eq(productCommentRatingSummary.productCommentId))
.leftJoin(memberProductLikeMapping)
.on(productComment.memberId.eq(memberProductLikeMapping.memberId).and(productComment.productId.eq(memberProductLikeMapping.productId)))
.where(productComment.productId.eq(productId)
.and(productComment.memberId.eq(memberId))
.and(productComment.valid.isTrue)
)
.select(Projections.constructor(ProductCommentView::class.java,
productComment,
productCommentRatingSummary.likeCount,
memberProductLikeMapping.likeType)
).fetchFirst()
}

private fun getOrderBy(productCommentOrderType: ProductCommentOrderType): OrderSpecifier<*>? {
return if (productCommentOrderType == ProductCommentOrderType.LIKE) {
productCommentRatingSummary.likeCount.desc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import com.yapp.cvs.domain.base.vo.PageSearchVO
import com.yapp.cvs.domain.base.vo.PageVO
import com.yapp.cvs.domain.comment.application.ProductCommentService
import com.yapp.cvs.domain.like.application.MemberProductLikeMappingService
import com.yapp.cvs.domain.like.entity.MemberProductLikeMapping
import com.yapp.cvs.domain.like.entity.MemberProductMappingKey
import com.yapp.cvs.domain.member.entity.Member
import com.yapp.cvs.domain.product.vo.ProductDetailVO
import com.yapp.cvs.domain.product.vo.ProductSearchVO
import com.yapp.cvs.domain.product.vo.ProductUpdateVO
import com.yapp.cvs.domain.product.vo.ProductVO
import org.springframework.stereotype.Service
import java.security.PrivateKey
import javax.transaction.Transactional

@Service
Expand All @@ -24,18 +22,18 @@ class ProductProcessor(
private val memberProductLikeMappingService: MemberProductLikeMappingService,
private val productCommentService: ProductCommentService
) {
fun getProductDetail(productId: Long, memberId: Long): ProductDetailVO {
fun getProductDetail(productId: Long, member: Member): ProductDetailVO {
val product = productService.findProduct(productId)

val memberProductLikeMapping = memberProductLikeMappingService.findByMemberProductLike(
MemberProductMappingKey(productId, memberId)
MemberProductMappingKey(productId, member.memberId!!)
)

val commentCount = productCommentService.countTotalCommentByProduct(productId)

val ownComment = productCommentService.findProductCommentByMember(productId, member)
productService.increaseProductViewCount(productId)

return ProductDetailVO.from(product, memberProductLikeMapping, commentCount)
return ProductDetailVO.from(product, memberProductLikeMapping, commentCount, ownComment)
}

fun searchProductPageList(offsetSearchVO: OffsetSearchVO, productSearchVO: ProductSearchVO): OffsetPageVO<ProductVO> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yapp.cvs.domain.product.vo

import com.yapp.cvs.domain.comment.vo.ProductCommentVO
import com.yapp.cvs.domain.enums.ProductCategoryType
import com.yapp.cvs.domain.enums.ProductLikeType
import com.yapp.cvs.domain.like.entity.MemberProductLikeMapping
Expand All @@ -16,10 +17,11 @@ data class ProductDetailVO(
val imageUrl: String?,
val productPromotionVOList: List<ProductPromotionVO>,
val productScoreVO: ProductScoreVO?,
val commentCount: Long
val commentCount: Long,
val ownCommentVO: ProductCommentVO?
) {
companion object {
fun from(product: Product, memberProductMapping: MemberProductLikeMapping?, commentCount: Long): ProductDetailVO {
fun from(product: Product, memberProductMapping: MemberProductLikeMapping?, commentCount: Long, ownCommentVO: ProductCommentVO?): ProductDetailVO {
return ProductDetailVO(
productId = product.productId!!,
brandName = product.brandName,
Expand All @@ -31,7 +33,8 @@ data class ProductDetailVO(
imageUrl = product.imageUrl,
productPromotionVOList = product.productPromotionList.map { ProductPromotionVO.from(it) },
productScoreVO = product.productLikeSummaryList.firstOrNull()?.let { ProductScoreVO.from(it) },
commentCount = commentCount
commentCount = commentCount,
ownCommentVO = ownCommentVO
)
}
}
Expand Down

0 comments on commit e55a3b7

Please sign in to comment.