Skip to content

Commit

Permalink
고정된 게시글 이슈 & 파일 업로드 기능 적용 (#174)
Browse files Browse the repository at this point in the history
* feature: board file upload

* refactor: 불필요한 import 제거

* fix: conflict 해결후에 빌드 실패 해결

* 고정 게시글 관련 이슈 해결 (#169)

* fix: 고정 게시글 관련 이슈들을 해결

* refactor: 메서드로 분리

* fix: 게시글 파일 업로드 문제 해결

* 게시글 파일 조회 문제 해결 및 게시글 파일 삭제 api 추가

* remove: 사용하지 않는 dto 제거

* refactor: 게시글 수정시 로직 변경, 파일 업로드 변경

* refactor: 개행 추가

* refactor: 파일 끝 개행
  • Loading branch information
hajeu authored Jun 21, 2024
1 parent 6bf5a40 commit 50ef192
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package team.themoment.gsmNetworking.domain.board.controller
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
Expand All @@ -13,10 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import team.themoment.gsmNetworking.common.manager.AuthenticatedUserManager
import team.themoment.gsmNetworking.domain.board.domain.BoardCategory
import team.themoment.gsmNetworking.domain.board.dto.BoardInfoDto
import team.themoment.gsmNetworking.domain.board.dto.BoardListDto
import team.themoment.gsmNetworking.domain.board.dto.BoardSaveDto
import team.themoment.gsmNetworking.domain.board.dto.BoardUpdateDto
import team.themoment.gsmNetworking.domain.board.dto.*
import team.themoment.gsmNetworking.domain.board.service.*
import javax.validation.Valid
import javax.validation.constraints.Max
Expand Down Expand Up @@ -72,5 +70,4 @@ class BoardController (
updatePinStatusUseCase.updatePinStatus(boardId)
return ResponseEntity.ok().build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import javax.persistence.FetchType.*

@Entity
@Table(name = "board")
class Board (
class Board(

override val id: Long = 0,

Expand Down Expand Up @@ -44,5 +44,5 @@ class Board (
val likes: MutableList<Like> = ArrayList(),

@Column(name = "is_pinned")
var isPinned: Boolean = false
var isPinned: Boolean = false,
): BaseIdTimestampEntity();
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package team.themoment.gsmNetworking.domain.board.domain

import team.themoment.gsmNetworking.common.domain.BaseIdTimestampEntity
import javax.persistence.Entity
import javax.persistence.JoinColumn
import javax.persistence.ManyToOne
import javax.persistence.Table

@Entity
@Table(name = "file")
class File (
val fileUrl: String,

@ManyToOne
@JoinColumn(name = "board_id")
val board: Board,
): BaseIdTimestampEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ data class BoardInfoDto (
val likeCount: Int,
val isLike: Boolean,
val isPinned: Boolean,
val fileUrls: List<String>
val fileList: List<FileInfoDto>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import team.themoment.gsmNetworking.domain.board.domain.BoardCategory
import team.themoment.gsmNetworking.domain.comment.dto.AuthorDto
import java.time.LocalDateTime

data class BoardListDto (
data class BoardListDto(
val id: Long,
val title: String,
val boardCategory: BoardCategory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ data class BoardSaveDto (
@field:Min(1)
@field:Max(30)
val popupExp: Int?,
val files: List<MultipartFile>
val files: List<MultipartFile>?
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.themoment.gsmNetworking.domain.board.dto

import io.micrometer.core.lang.Nullable
import org.springframework.web.multipart.MultipartFile
import team.themoment.gsmNetworking.domain.board.domain.BoardCategory
import javax.persistence.EnumType
import javax.persistence.Enumerated
Expand All @@ -15,5 +16,10 @@ data class BoardUpdateDto (
val content: String,
@field:NotNull
@Enumerated(EnumType.STRING)
val boardCategory: BoardCategory
val boardCategory: BoardCategory,
@field:Nullable
@field:Min(1)
@field:Max(30)
val popupExp: Int?,
val files: List<MultipartFile>?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package team.themoment.gsmNetworking.domain.board.dto

data class FileInfoDto (
val id: Long?,
val fileUrls: String?
)
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package team.themoment.gsmNetworking.domain.board.repository

import com.querydsl.core.types.ExpressionUtils
import com.querydsl.core.types.Projections
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.jpa.JPAExpressions
import com.querydsl.jpa.impl.JPAQueryFactory
import team.themoment.gsmNetworking.domain.board.domain.BoardCategory
import team.themoment.gsmNetworking.domain.board.domain.QBoard
import team.themoment.gsmNetworking.domain.board.domain.QBoard.board
import team.themoment.gsmNetworking.domain.board.dto.BoardListDto
import team.themoment.gsmNetworking.domain.comment.dto.AuthorDto
import team.themoment.gsmNetworking.domain.like.domain.QLike
import team.themoment.gsmNetworking.domain.like.domain.QLike.like
import team.themoment.gsmNetworking.domain.user.domain.User

Expand All @@ -29,6 +26,8 @@ class BoardCustomRepositoryImpl(

val pinnedIds = pinnedPosts.map { it.id }

val overridePageSize = overridePageSize(pageSize, pinnedPosts.size.toLong())

val otherPosts = queryFactory.select(
Projections.constructor(
BoardListDto::class.java,
Expand All @@ -53,7 +52,7 @@ class BoardCustomRepositoryImpl(
.from(board)
.where(eqCategory(boardCategory), board.id.lt(cursorId), board.isPinned.isFalse, board.id.notIn(pinnedIds))
.orderBy(board.id.desc())
.limit(pageSize)
.limit(overridePageSize)
.fetch()

return pinnedPosts + otherPosts
Expand All @@ -68,6 +67,8 @@ class BoardCustomRepositoryImpl(

val pinnedIds = pinnedPosts.map { it.id }

val overridePageSize = overridePageSize(pageSize, pinnedPosts.size.toLong())

val otherPosts = queryFactory.select(
Projections.constructor(
BoardListDto::class.java,
Expand All @@ -92,7 +93,7 @@ class BoardCustomRepositoryImpl(
.from(board)
.orderBy(board.id.desc())
.where(eqCategory(boardCategory), board.isPinned.isFalse, board.id.notIn(pinnedIds))
.limit(pageSize)
.limit(overridePageSize)
.fetch()

return pinnedPosts + otherPosts
Expand Down Expand Up @@ -140,4 +141,7 @@ class BoardCustomRepositoryImpl(

}

private fun overridePageSize(pageSize: Long, pinnedPostsSize: Long): Long {
return pageSize - pinnedPostsSize
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package team.themoment.gsmNetworking.domain.board.repository

import org.springframework.data.jpa.repository.JpaRepository
import team.themoment.gsmNetworking.domain.board.domain.Board
import team.themoment.gsmNetworking.domain.board.domain.File

interface FileRepository : JpaRepository<File, Long>{

fun findFilesByBoard(board: Board): List<File>

fun deleteAllByBoard(board: Board)
}
Loading

0 comments on commit 50ef192

Please sign in to comment.