Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main <- develop #131

Merged
merged 3 commits into from
Apr 24, 2023
Merged
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 @@ -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

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("게시글 조회_삭제된 게시글 미노출")
Expand Down