Skip to content

Commit 1b66b16

Browse files
authored
Merge pull request #165 from team-gogo/develop
v2025.4.16
2 parents b2e573c + 7f2eede commit 1b66b16

File tree

22 files changed

+262
-103
lines changed

22 files changed

+262
-103
lines changed

src/main/kotlin/gogo/gogostage/domain/community/board/application/BoardProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BoardProcessor(
1717
studentId: Long,
1818
writeCommunityBoardDto: WriteCommunityBoardDto,
1919

20-
) {
20+
): Board {
2121
val board = Board(
2222
community = community,
2323
studentId = studentId,
@@ -29,7 +29,7 @@ class BoardProcessor(
2929
createdAt = LocalDateTime.now()
3030
)
3131

32-
boardRepository.save(board)
32+
return boardRepository.save(board)
3333
}
3434

3535
}

src/main/kotlin/gogo/gogostage/domain/community/board/persistence/Board.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Board(
3232
var likeCount: Int,
3333

3434
@Column(name = "is_filtered", nullable = false)
35-
val isFiltered: Boolean,
35+
var isFiltered: Boolean,
3636

3737
@Column(name = "created_at", nullable = false)
3838
val createdAt: LocalDateTime
@@ -50,4 +50,8 @@ class Board(
5050
commentCount += 1
5151
}
5252

53+
fun changeBoardFilter() {
54+
isFiltered = true
55+
}
56+
5357
}

src/main/kotlin/gogo/gogostage/domain/community/comment/persistence/Comment.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Comment(
2323
val content: String,
2424

2525
@Column(name = "is_filtered", nullable = false)
26-
val isFiltered: Boolean,
26+
var isFiltered: Boolean,
2727

2828
@Column(name = "created_at", nullable = false)
2929
val createdAt: LocalDateTime,
@@ -40,4 +40,7 @@ class Comment(
4040
likeCount -= 1
4141
}
4242

43+
fun changeIsFiltered() {
44+
isFiltered = true
45+
}
4346
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package gogo.gogostage.domain.community.root.application
22

33
import gogo.gogostage.domain.community.comment.persistence.Comment
4-
import gogo.gogostage.domain.community.root.application.dto.AuthorDto
54
import gogo.gogostage.domain.community.root.application.dto.WriteBoardCommentReqDto
65
import gogo.gogostage.domain.community.root.application.dto.WriteBoardCommentResDto
76
import gogo.gogostage.global.internal.student.stub.StudentByIdStub
@@ -20,12 +19,6 @@ class CommunityMapper {
2019
content = writeBoardCommentDto.content,
2120
createdAt = comment.createdAt,
2221
likeCount = comment.likeCount,
23-
author = AuthorDto(
24-
studentId = student.studentId,
25-
name = student.name,
26-
classNumber = student.classNumber,
27-
studentNumber = student.studentNumber
28-
)
2922
)
3023

3124
}

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import gogo.gogostage.domain.community.comment.persistence.CommentRepository
99
import gogo.gogostage.domain.community.commentlike.persistence.CommentLike
1010
import gogo.gogostage.domain.community.commentlike.persistence.CommentLikeRepository
1111
import gogo.gogostage.domain.community.root.application.dto.*
12-
import gogo.gogostage.global.cache.CacheConstant
13-
import gogo.gogostage.global.cache.RedisCacheService
1412
import gogo.gogostage.global.error.StageException
1513
import gogo.gogostage.global.internal.student.stub.StudentByIdStub
14+
import org.springframework.data.repository.findByIdOrNull
1615
import org.springframework.http.HttpStatus
1716
import org.springframework.stereotype.Component
17+
import org.springframework.transaction.annotation.Transactional
1818
import java.time.LocalDateTime
1919

2020
@Component
@@ -24,7 +24,6 @@ class CommunityProcessor(
2424
private val commentLikeRepository: CommentLikeRepository,
2525
private val commentMapper: CommunityMapper,
2626
private val boardRepository: BoardRepository,
27-
private val redisCacheService: RedisCacheService
2827
) {
2928

3029
fun likeBoard(studentId: Long, board: Board): LikeResDto {
@@ -89,9 +88,6 @@ class CommunityProcessor(
8988
?: throw StageException("CommentLike Not Found, commentId=${comment.id}, studentId=${student.studentId}", HttpStatus.NOT_FOUND.value())
9089

9190
commentLikeRepository.delete(commentLike)
92-
93-
redisCacheService.deleteFromCache("${CacheConstant.COMMUNITY_INFO_CACHE_VALUE}::${comment.board.id}")
94-
9591
comment.minusLikeCount()
9692
commentRepository.save(comment)
9793

@@ -106,8 +102,6 @@ class CommunityProcessor(
106102

107103
commentLikeRepository.save(boardLike)
108104

109-
redisCacheService.deleteFromCache("${CacheConstant.COMMUNITY_INFO_CACHE_VALUE}::${comment.board.id}")
110-
111105
comment.plusLikeCount()
112106
commentRepository.save(comment)
113107

@@ -116,4 +110,24 @@ class CommunityProcessor(
116110
)
117111
}
118112
}
113+
114+
@Transactional
115+
fun boardFilteredTrue(boardId: Long) {
116+
val board = boardRepository.findByIdOrNull(boardId)
117+
?: throw StageException("Board not found, boardId=${boardId}", HttpStatus.NOT_FOUND.value())
118+
119+
board.changeBoardFilter()
120+
121+
boardRepository.save(board)
122+
}
123+
124+
@Transactional
125+
fun commentFilteredTrue(commentId: Long) {
126+
val comment = commentRepository.findByIdOrNull(commentId)
127+
?: throw StageException("Comment not found, commentId=${commentId}", HttpStatus.NOT_FOUND.value())
128+
129+
comment.changeIsFiltered()
130+
131+
commentRepository.save(comment)
132+
}
119133
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package gogo.gogostage.domain.community.root.application
33
import gogo.gogostage.domain.community.root.application.dto.*
44
import gogo.gogostage.domain.community.root.persistence.SortType
55
import gogo.gogostage.domain.game.persistence.GameCategory
6+
import gogo.gogostage.global.internal.student.stub.StudentByIdStub
67

78
interface CommunityService {
89
fun writeCommunityBoard(stageId: Long, writeCommunityBoardDto: WriteCommunityBoardDto)
9-
fun getStageBoard(stageId: Long, page: Int, size: Int, category: GameCategory?, sort: SortType): GetCommunityBoardResDto
10-
fun getStageBoardInfo(boardId: Long): GetCommunityBoardInfoResDto
10+
fun getStageBoard(stageId: Long, page: Int, size: Int, category: GameCategory?, sort: SortType, isFiltered: Boolean, student: StudentByIdStub): GetCommunityBoardResDto
11+
fun getStageBoardInfo(boardId: Long, isFiltered: Boolean, student: StudentByIdStub): GetCommunityBoardInfoResDto
1112
fun likeStageBoard(boardId: Long): LikeResDto
1213
fun writeBoardComment(boardId: Long, writeBoardCommentDto: WriteBoardCommentReqDto): WriteBoardCommentResDto
1314
fun likeBoardComment(commentId: Long): LikeResDto

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

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ package gogo.gogostage.domain.community.root.application
33
import gogo.gogostage.domain.community.board.application.BoardProcessor
44
import gogo.gogostage.domain.community.board.application.BoardReader
55
import gogo.gogostage.domain.community.root.application.dto.*
6+
import gogo.gogostage.domain.community.root.event.BoardCreateEvent
7+
import gogo.gogostage.domain.community.root.event.CommentCreateEvent
68
import gogo.gogostage.domain.community.root.persistence.SortType
79
import gogo.gogostage.domain.game.persistence.GameCategory
810
import gogo.gogostage.domain.stage.root.application.StageValidator
9-
import gogo.gogostage.global.cache.CacheConstant
11+
import gogo.gogostage.global.internal.student.stub.StudentByIdStub
1012
import gogo.gogostage.global.util.UserContextUtil
11-
import org.springframework.cache.annotation.CacheEvict
12-
import org.springframework.cache.annotation.Cacheable
13+
import org.springframework.context.ApplicationEventPublisher
1314
import org.springframework.stereotype.Service
1415
import org.springframework.transaction.annotation.Transactional
16+
import java.util.*
1517

1618
@Service
1719
class CommunityServiceImpl(
@@ -21,41 +23,42 @@ class CommunityServiceImpl(
2123
private val communityProcessor: CommunityProcessor,
2224
private val communityValidator: CommunityValidator,
2325
private val stageValidator: StageValidator,
24-
private val boardReader: BoardReader
26+
private val boardReader: BoardReader,
27+
private val applicationEventPublisher: ApplicationEventPublisher,
2528
): CommunityService {
2629

2730
@Transactional
2831
override fun writeCommunityBoard(stageId: Long, writeCommunityBoardDto: WriteCommunityBoardDto) {
2932
val student = userUtil.getCurrentStudent()
3033
stageValidator.validStage(student, stageId)
3134
val community = communityReader.readByStageIdAndGameCategory(stageId, writeCommunityBoardDto.gameCategory)
32-
boardProcessor.saveCommunityBoard(community, student.studentId, writeCommunityBoardDto)
35+
val board = boardProcessor.saveCommunityBoard(community, student.studentId, writeCommunityBoardDto)
3336

34-
// 추후 욕설 필터링 요청 처리 필요
37+
applicationEventPublisher.publishEvent(
38+
BoardCreateEvent(
39+
id = UUID.randomUUID().toString(),
40+
boardId = board.id,
41+
content = board.title + " " + board.content
42+
)
43+
)
3544
}
3645

3746
@Transactional(readOnly = true)
38-
override fun getStageBoard(stageId: Long, page: Int, size: Int, category: GameCategory?, sort: SortType): GetCommunityBoardResDto {
39-
val student = userUtil.getCurrentStudent()
47+
override fun getStageBoard(stageId: Long, page: Int, size: Int, category: GameCategory?, sort: SortType, isFiltered: Boolean, student: StudentByIdStub): GetCommunityBoardResDto {
4048
stageValidator.validStage(student, stageId)
4149
communityValidator.validPageAndSize(page, size)
42-
val isActiveProfanityFilter = student.isActiveProfanityFilter
43-
return communityReader.readBoards(isActiveProfanityFilter, stageId, page, size, category, sort)
50+
return communityReader.readBoards(isFiltered, stageId, page, size, category, sort)
4451
}
4552

4653
@Transactional(readOnly = true)
47-
@Cacheable(value = [CacheConstant.COMMUNITY_INFO_CACHE_VALUE], key = "#boardId", cacheManager = "cacheManager")
48-
override fun getStageBoardInfo(boardId: Long): GetCommunityBoardInfoResDto {
49-
val student = userUtil.getCurrentStudent()
54+
override fun getStageBoardInfo(boardId: Long, isFiltered: Boolean, student: StudentByIdStub): GetCommunityBoardInfoResDto {
5055
val board = boardReader.read(boardId)
5156
stageValidator.validStage(student, board.community.stage.id)
5257
stageValidator.validProfanityFilter(student, board)
53-
val isActiveProfanityFilter = student.isActiveProfanityFilter
54-
return communityReader.readBoardInfo(isActiveProfanityFilter, board, student)
58+
return communityReader.readBoardInfo(isFiltered, board, student)
5559
}
5660

5761
@Transactional
58-
@CacheEvict(value = [CacheConstant.COMMUNITY_INFO_CACHE_VALUE], key = "#boardId", cacheManager = "cacheManager")
5962
override fun likeStageBoard(boardId: Long): LikeResDto {
6063
val student = userUtil.getCurrentStudent()
6164
val board = communityReader.readBoardByBoardIdForWrite(boardId)
@@ -64,13 +67,21 @@ class CommunityServiceImpl(
6467
}
6568

6669
@Transactional
67-
@CacheEvict(value = [CacheConstant.COMMUNITY_INFO_CACHE_VALUE], key = "#boardId", cacheManager = "cacheManager")
6870
override fun writeBoardComment(boardId: Long, writeBoardCommentDto: WriteBoardCommentReqDto): WriteBoardCommentResDto {
6971
val student = userUtil.getCurrentStudent()
7072
val board = communityReader.readBoardByBoardId(boardId)
7173
stageValidator.validStage(student, board.community.stage.id)
72-
// 욕설 필터링 필요
73-
return communityProcessor.saveBoardComment(student, writeBoardCommentDto, board)
74+
val writeBoardCommentResDto = communityProcessor.saveBoardComment(student, writeBoardCommentDto, board)
75+
76+
applicationEventPublisher.publishEvent(
77+
CommentCreateEvent(
78+
id = UUID.randomUUID().toString(),
79+
commentId = writeBoardCommentResDto.commentId,
80+
content = writeBoardCommentResDto.content
81+
)
82+
)
83+
84+
return writeBoardCommentResDto
7485
}
7586

7687
@Transactional

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ data class BoardDto(
3838
val createdAt: LocalDateTime,
3939
val stageType: StageType,
4040
val commentCount: Int,
41-
val author: AuthorDto
42-
)
43-
44-
data class AuthorDto(
45-
val studentId: Long,
46-
val name: String,
47-
val classNumber: Int,
48-
val studentNumber: Int
4941
)
5042

5143
data class GetCommunityBoardInfoResDto(
@@ -57,10 +49,8 @@ data class GetCommunityBoardInfoResDto(
5749
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
5850
val createdAt: LocalDateTime,
5951
val stage: StageDto,
60-
val author: AuthorDto,
6152
val commentCount: Int,
6253
val comment: List<CommentDto>
63-
6454
)
6555

6656
data class StageDto(
@@ -75,7 +65,6 @@ data class CommentDto(
7565
val createdAt: LocalDateTime,
7666
val likeCount: Int,
7767
val isLiked: Boolean,
78-
val author: AuthorDto
7968
)
8069

8170
data class LikeResDto(
@@ -94,5 +83,4 @@ data class WriteBoardCommentResDto(
9483
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
9584
val createdAt: LocalDateTime,
9685
val likeCount: Int,
97-
val author: AuthorDto,
98-
)
86+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package gogo.gogostage.domain.community.root.application.listener
2+
3+
import gogo.gogostage.domain.community.root.event.BoardCreateEvent
4+
import gogo.gogostage.domain.community.root.event.CommentCreateEvent
5+
import gogo.gogostage.global.kafka.publisher.StagePublisher
6+
import org.slf4j.LoggerFactory
7+
import org.springframework.stereotype.Component
8+
import org.springframework.transaction.event.TransactionPhase
9+
import org.springframework.transaction.event.TransactionalEventListener
10+
11+
@Component
12+
class CommunityApplicationEventListener(
13+
private val stagePublisher: StagePublisher,
14+
) {
15+
16+
private val log = LoggerFactory.getLogger(this::class.java.simpleName)
17+
18+
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
19+
fun boardCreate(event: BoardCreateEvent) {
20+
with(event) {
21+
log.info("published create board application event: {}", id)
22+
stagePublisher.publishBoardCreateEvent(event)
23+
}
24+
}
25+
26+
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
27+
fun commentCreate(event: CommentCreateEvent) {
28+
with(event) {
29+
log.info("published create comment application event: {}", id)
30+
stagePublisher.publishCommentCreateEvent(event)
31+
}
32+
}
33+
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package gogo.gogostage.domain.community.root.event
2+
3+
data class BoardCreateEvent(
4+
val id: String,
5+
val boardId: Long,
6+
val content: String
7+
)

0 commit comments

Comments
 (0)