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 #129

Merged
merged 3 commits into from
Apr 23, 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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sonarqube {
property("sonar.test.inclusions", "**/*Test.kt")
property("sonar.exclusions", "**/test/**, **/resources/**, **/docs/**, **/*Application*.kt, **/global/**, **/dto/**, **/*Exception*.kt, **/*ErrorCode*.kt, **/*Category*.kt, **/admin/**, **/*RepositoryImpl.kt" )
property("sonar.java.coveragePlugin", "jacoco")
property("sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/reports/jacoco/html/jacocoTestReport.xml")
property("sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/customJacocoReportDir/test/jacocoTestReport.xml")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ 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자 슬라이싱
return BoardResDto(board.id, board.title, board.code, oneLineContent, board.user.nickName, Timestamp.valueOf(board.createdAt), board.imageUrls[0], board.comment.size, board.category.name, board.prefixCategory.name)
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.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())
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())
}

data class CodeResDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import javax.persistence.*
)
class Board(
var title: String,
var code: String,
@Column(length = Int.MAX_VALUE)
var content : String,
@Convert(converter = BoardCategoryConverter::class)
var category : BoardCategory,
@Column(length = Int.MAX_VALUE)
@Convert(converter = BoardImageUrlConverter::class) // 이미지 url ","로 슬라이싱
var imageUrls : List<String>,
@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -30,9 +31,11 @@ class Board(
@Convert(converter = PrefixCategoryConverter::class)
var prefixCategory : PrefixCategory,
var fixed : Boolean = false,
@OneToOne @JoinColumn(name = "id")
var boardCode: BoardCode,
@LastModifiedDate
@Column(updatable = true)
var fixedAt : LocalDateTime? = null,
var fixedAt : LocalDateTime = LocalDateTime.now(),
var useYn : Boolean = true,
@OneToMany(mappedBy = "board", cascade = [CascadeType.ALL], orphanRemoval = true)
var love : MutableList<Love> = mutableListOf(),
Expand All @@ -44,14 +47,14 @@ class Board(

fun updateEntity(
title: String,
code: String,
code: BoardCode,
content: String,
category: String,
imageUrls: List<String>,
prefixCategory: String
) : Board {
this.title = title
this.code = code
this.boardCode = code
this.content = content
this.category = BoardCategory.values().firstOrNull { it.name == category }
?: throw ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.jhouse_server.domain.board.entity

import com.example.jhouse_server.global.entity.BaseEntity
import javax.persistence.*

@Entity
@Table(
name = "board_code"
)
class BoardCode(
@Column(length = Int.MAX_VALUE)
var code: String,
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id : Long = 0L
) : BaseEntity() {

fun updateEntity(
code: String
) : BoardCode {
this.code = code
return this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.jhouse_server.domain.board.repository

import com.example.jhouse_server.domain.board.entity.BoardCode
import org.springframework.data.jpa.repository.JpaRepository

interface BoardCodeRepository : JpaRepository<BoardCode, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.example.jhouse_server.domain.board.service
import com.example.jhouse_server.domain.board.*
import com.example.jhouse_server.domain.board.entity.Board
import com.example.jhouse_server.domain.board.entity.BoardCategory
import com.example.jhouse_server.domain.board.entity.BoardCode
import com.example.jhouse_server.domain.board.repository.BoardCodeRepository
import com.example.jhouse_server.domain.board.repository.BoardRepository
import com.example.jhouse_server.domain.user.entity.Authority
import com.example.jhouse_server.domain.user.entity.User
Expand All @@ -20,15 +22,17 @@ import java.util.regex.Pattern
@Service
@Transactional(readOnly = true)
class BoardServiceImpl(
val boardRepository: BoardRepository
val boardRepository: BoardRepository,
val boardCodeRepository: BoardCodeRepository
): BoardService {

@Transactional
override fun createBoard(req: BoardReqDto, user: User): Long {
val content = getContent(req.code!!)
val fixed = if(req.prefixCategory == PrefixCategory.ADVERTISEMENT) req.fixed!! else false
val code = boardCodeRepository.save(BoardCode(req.code))
val board = Board(
req.title!!, req.code, content, req.category!!, req.imageUrls, user, req.prefixCategory!!, fixed
req.title!!, content, req.category!!, req.imageUrls, user, req.prefixCategory!!, fixed, code
)
return boardRepository.save(board).id
}
Expand All @@ -38,9 +42,11 @@ class BoardServiceImpl(
val board = boardRepository.findByIdOrThrow(boardId)
if (user != board.user) throw ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION)
val content = getContent(req.code!!)
var code = boardCodeRepository.findByIdOrThrow(board.boardCode.id)
code.updateEntity(req.code)
return board.updateEntity(
req.title!!,
req.code,
code,
content,
req.category!!,
req.imageUrls,
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(50)
assertThat(res.content[0].oneLineContent.length).isLessThan(51)
}
@Test
@DisplayName("게시글 조회_삭제된 게시글 미노출")
Expand Down