From 1700972af747abb007bf2f58920586d9797bac91 Mon Sep 17 00:00:00 2001 From: dldmsql Date: Mon, 24 Apr 2023 21:36:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#118=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=BB=A8=EB=B2=84=ED=8C=85=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 응답 데이터로 컨버팅 시, 정규표현식을 통해 문장에 대한 검증과 200자 이내 슬라이싱 처리 --- .../jhouse_server/domain/board/dto/BoardReqDto.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/example/jhouse_server/domain/board/dto/BoardReqDto.kt b/src/main/kotlin/com/example/jhouse_server/domain/board/dto/BoardReqDto.kt index 118036e2..fa3f614f 100644 --- a/src/main/kotlin/com/example/jhouse_server/domain/board/dto/BoardReqDto.kt +++ b/src/main/kotlin/com/example/jhouse_server/domain/board/dto/BoardReqDto.kt @@ -4,7 +4,9 @@ import com.example.jhouse_server.domain.board.entity.Board import com.example.jhouse_server.domain.board.entity.BoardCategory import com.example.jhouse_server.domain.comment.dto.CommentResDto import java.sql.Timestamp -import java.util.Date +import java.util.* +import java.util.regex.Matcher +import java.util.regex.Pattern import javax.validation.constraints.NotNull import kotlin.streams.toList @@ -62,13 +64,18 @@ data class BoardResOneDto( ) fun toListDto(board : Board) : BoardResDto { - val oneLineContent = if(board.content.length >= 50) board.content.substring(0 until 50) else board.content// 50자 슬라이싱 + val oneLineContent = sliceContentWithRegex(board.content) return BoardResDto(board.id, board.title, board.boardCode.code, oneLineContent, board.user.nickName, Timestamp.valueOf(board.createdAt), board.imageUrls[0], board.comment.size, board.category.name, board.prefixCategory.name) } fun toDto(board: Board) : BoardResOneDto { return BoardResOneDto(board.id, board.title, board.boardCode.code, board.user.nickName, Timestamp.valueOf(board.createdAt), board.imageUrls, board.love.size, board.category.name, board.prefixCategory.name, board.comment.size, board.comment.stream().map { com.example.jhouse_server.domain.comment.dto.toDto(it) }.toList()) } +fun sliceContentWithRegex(content : String) : String { + val pattern = Regex("^[a-zA-Z가-힣].*[.!?]$") + val validatedString = pattern.find(content)?.value ?: "" + return validatedString.take(200) +} data class CodeResDto( val code: String, From c59bf72818aa8b6fd76e19044b170472475df309 Mon Sep 17 00:00:00 2001 From: dldmsql Date: Mon, 24 Apr 2023 21:40:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#118=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=BB=A8=EB=B2=84=ED=8C=85=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 테스트코드에서 검증 조건을 51자에서 201자로 수정 --- .../jhouse_server/domain/board/service/BoardServiceImplTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImplTest.kt b/src/test/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImplTest.kt index 7883ec91..4d98fbac 100644 --- a/src/test/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImplTest.kt +++ b/src/test/kotlin/com/example/jhouse_server/domain/board/service/BoardServiceImplTest.kt @@ -210,7 +210,7 @@ internal class BoardServiceImplTest @Autowired constructor( // when val res = boardService.getBoardAll(category, pageable) // then - assertThat(res.content[0].oneLineContent.length).isLessThan(51) + assertThat(res.content[0].oneLineContent.length).isLessThan(201) } @Test @DisplayName("게시글 조회_삭제된 게시글 미노출")