Skip to content

Commit ebab8b7

Browse files
committed
add: saveBoardView method apply
1 parent 111dff9 commit ebab8b7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/main/kotlin/gogo/gogostage/domain/community/root/application/CommunityProcessor.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import gogo.gogostage.domain.community.board.persistence.Board
44
import gogo.gogostage.domain.community.board.persistence.BoardRepository
55
import gogo.gogostage.domain.community.boardlike.persistence.BoardLike
66
import gogo.gogostage.domain.community.boardlike.persistence.BoardLikeRepository
7+
import gogo.gogostage.domain.community.boardview.persistence.BoardView
8+
import gogo.gogostage.domain.community.boardview.persistence.BoardViewRepository
79
import gogo.gogostage.domain.community.comment.persistence.Comment
810
import gogo.gogostage.domain.community.comment.persistence.CommentRepository
911
import gogo.gogostage.domain.community.commentlike.persistence.CommentLike
@@ -24,6 +26,7 @@ class CommunityProcessor(
2426
private val commentLikeRepository: CommentLikeRepository,
2527
private val commentMapper: CommunityMapper,
2628
private val boardRepository: BoardRepository,
29+
private val boardViewRepository: BoardViewRepository,
2730
) {
2831

2932
fun likeBoard(studentId: Long, board: Board): LikeResDto {
@@ -130,4 +133,19 @@ class CommunityProcessor(
130133

131134
commentRepository.save(comment)
132135
}
136+
137+
fun saveBoardView(board: Board, studentId: Long) {
138+
if (!boardViewRepository.existsByBoardIdAndStudentId(board.id, studentId)) {
139+
val newBoardView = BoardView(
140+
board = board,
141+
studentId = studentId,
142+
)
143+
144+
boardViewRepository.save(newBoardView)
145+
146+
board.plusViewCount()
147+
148+
boardRepository.save(board)
149+
}
150+
}
133151
}

src/main/kotlin/gogo/gogostage/domain/community/root/application/CommunityServiceImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CommunityServiceImpl(
5555
val board = boardReader.read(boardId)
5656
stageValidator.validStage(student, board.community.stage.id)
5757
stageValidator.validProfanityFilter(student, board)
58+
communityProcessor.saveBoardView(board, student.studentId)
5859
return communityReader.readBoardInfo(isFiltered, board, student)
5960
}
6061

0 commit comments

Comments
 (0)