Skip to content

Commit

Permalink
Merge pull request #260 from depromeet/feature/#171
Browse files Browse the repository at this point in the history
목표 추가시 기본 카운트 추가
  • Loading branch information
ManHyuk authored Apr 25, 2024
2 parents 12e2397 + 2bc8d43 commit 39c9f54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import io.raemian.api.event.model.DeletedCommentEvent
import io.raemian.api.support.exception.CoreApiException
import io.raemian.api.support.exception.ErrorInfo
import io.raemian.storage.db.core.comment.Comment
import io.raemian.storage.db.core.comment.CommentCount
import io.raemian.storage.db.core.comment.CommentCountRepository
import io.raemian.storage.db.core.comment.CommentJdbcQueryRepository
import io.raemian.storage.db.core.comment.CommentRepository
import io.raemian.storage.db.core.comment.model.GoalCommentCountQueryResult
Expand All @@ -24,6 +26,7 @@ import java.time.LocalDateTime
class CommentService(
private val commentRepository: CommentRepository,
private val commentJdbcQueryRepository: CommentJdbcQueryRepository,
private val commentCountRepository: CommentCountRepository,
private val goalRepository: GoalRepository,
private val userRepository: UserRepository,
private val applicationEventPublisher: ApplicationEventPublisher,
Expand Down Expand Up @@ -83,6 +86,11 @@ class CommentService(
fun findGoalCommentCounts(goalIds: List<Long>): List<GoalCommentCountQueryResult> =
commentJdbcQueryRepository.findAllGoalCommentCountByGoalIdIn(goalIds)

@Transactional
fun addDefaultCount(goalId: Long) {
commentCountRepository.save(CommentCount(0, goalId))
}

private fun createComment(goal: Goal, currentUser: User, content: String): Comment {
return try {
Comment(goal, currentUser, content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.raemian.api.goal.service

import io.raemian.api.comment.service.CommentService
import io.raemian.api.emoji.service.EmojiService
import io.raemian.api.event.model.CreatedCommentEvent
import io.raemian.api.event.model.CreatedGoalEvent
import io.raemian.api.event.model.DeletedGoalEvent
import io.raemian.api.goal.controller.request.CreateGoalRequest
Expand Down Expand Up @@ -60,10 +59,8 @@ class GoalService(
CreatedGoalEvent(lifeMap.id!!),
)

// goal 생성시 comment count 이벤트 발행
applicationEventPublisher.publishEvent(
CreatedCommentEvent(goal.id!!),
)
// goal 생성시 기본 comment count 생성
commentService.addDefaultCount(goal.id!!)

return CreateGoalResult(goal)
}
Expand Down

0 comments on commit 39c9f54

Please sign in to comment.