Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import com.sns.article.component.article.domains.ArticleScope
import com.sns.article.component.article.repositories.ArticleRepository
import com.sns.article.component.comment.domains.Comment
import com.sns.article.component.comment.repositories.CommentRepository
import com.sns.article.component.reaction.domains.ReactionRepository
import com.sns.article.component.reaction.domains.ReactionTarget
import com.sns.article.component.reaction.domains.ReactionTargetType
import com.sns.article.component.reaction.repositories.ReactionRepository
import com.sns.commons.exceptions.NoAuthorityException
import com.sns.commons.exceptions.NotFoundException
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import kotlin.streams.toList

/**
* @author Hyounglin Jun
Expand Down Expand Up @@ -55,7 +58,13 @@ class ArticleCommandService(

articleRepository.delete(article)
commentRepository.findAllByRootIdInAndRootType(listOf(articleId.id.toString()), Comment.Root.Type.ARTICLE)
.let { commentRepository.deleteAll(it) }
// FIXME reaction 을 삭제하는 방법 확인 (DB 정의가 없음)
.let {
commentRepository.deleteAll(it)
reactionRepository.findAllByTargetIn(it.stream()
.map { a -> ReactionTarget(ReactionTargetType.COMMENT, a.id!!) }
.toList())
.let { reactions -> reactionRepository.deleteAll(reactions) }
Comment on lines +63 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reactionRepository.findAllByTargetIn(it.stream()
.map { a -> ReactionTarget(ReactionTargetType.COMMENT, a.id!!) }
.toList())
.let { reactions -> reactionRepository.deleteAll(reactions) }
reactionRepository.findAllByTargetIn(it.map { r -> ReactionTarget(ReactionTargetType.COMMENT, r.id!!) }
.let { reactions -> reactionRepository.deleteAll(reactions) }

kotlin 에서는 stream 으로 변환하지 않아도 사용할 수 있어요

}
reactionRepository.findAllByTargetIn(listOf(ReactionTarget(ReactionTargetType.ARTICLE, articleId.id.toLong())))
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.sns.article.component.reaction.application

import com.sns.article.component.reaction.domains.Reaction
import com.sns.article.component.reaction.domains.ReactionRepository
import com.sns.article.component.reaction.domains.ReactionTarget
import com.sns.article.component.reaction.domains.ReactionValidator
import com.sns.article.component.reaction.dtos.ReactionDto
import com.sns.article.component.reaction.repositories.ReactionRepository
import com.sns.article.endpoints.reaction.requests.ReactionCreateRequest
import com.sns.commons.exceptions.NotFoundException
import org.springframework.context.ApplicationEventPublisher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.sns.article.component.reaction.application

import com.sns.article.component.reaction.domains.ReactionCreatedEvent
import com.sns.article.component.reaction.domains.ReactionNotFoundException
import com.sns.article.component.reaction.domains.ReactionRepository
import com.sns.article.component.reaction.repositories.ReactionRepository
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.sns.article.component.reaction.application

import com.sns.article.component.reaction.domains.ReactionNotFoundException
import com.sns.article.component.reaction.domains.ReactionRepository
import com.sns.article.component.reaction.dtos.ReactionDto
import com.sns.article.component.reaction.repositories.ReactionRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sns.article.component.reaction.repositories

import org.springframework.stereotype.Repository


@Repository
class DefaultReactionRepository(reactionCrudRepository: ReactionCrudRepository) : ReactionRepository,
ReactionCrudRepository by reactionCrudRepository
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sns.article.component.reaction.repositories

import com.sns.article.component.reaction.domains.Reaction
import com.sns.article.component.reaction.domains.ReactionTarget
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository

/**
* Created by JunSeok Youn on 2022/03/06
*/
@Repository
interface ReactionCrudRepository : CrudRepository<Reaction, Long> {
fun findAllByTargetIn(targets: List<ReactionTarget>): List<Reaction>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sns.article.component.reaction.repositories

import com.sns.article.component.reaction.domains.Reaction
import com.sns.article.component.reaction.domains.ReactionTarget
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository

/**
* Created by JunSeok Youn on 2022/03/06
*/
@Repository
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거는 NoRepositoryBean 으로 변경되어야할 것 같아요

interface ReactionRepository : CrudRepository<Reaction, Long> {
fun findAllByTargetIn(targets: List<ReactionTarget>): List<Reaction>
}

This file was deleted.