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

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

Merged
merged 7 commits into from
Jun 18, 2024
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 @@ -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 All @@ -28,11 +28,6 @@ class Board (
@Column(name = "board_category")
val boardCategory: BoardCategory,

@ElementCollection
@CollectionTable(name = "file_urls", joinColumns = [JoinColumn(name = "board_id")])
@Column(name = "file_urls")
val fileUrls: MutableList<String> = ArrayList(),

@ManyToOne
@JoinColumn(name = "author_id")
val author: User,
Expand All @@ -44,5 +39,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 @@ -6,7 +6,7 @@ import team.themoment.gsmNetworking.domain.comment.dto.AuthorDto
import team.themoment.gsmNetworking.domain.comment.dto.CommentListDto
import java.time.LocalDateTime

data class BoardInfoDto (
data class BoardInfoDto(
val id: Long,
val title: String,
val content: String,
Expand All @@ -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 All @@ -15,6 +15,5 @@ data class BoardListDto (
val commentCount: Int,
val likeCount: Int,
val isLike: Boolean,
val isPinned: Boolean,
val fileUrlsDto: FileUrlsDto
val isPinned: Boolean
)
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?
)

This file was deleted.

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 @@ -46,14 +45,13 @@ class BoardCustomRepositoryImpl(
board.comments.size(),
board.likes.size(),
likeCase(user),
board.isPinned,
board.fileUrls
board.isPinned
)
)
.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 +66,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 @@ -85,14 +85,13 @@ class BoardCustomRepositoryImpl(
board.comments.size(),
board.likes.size(),
likeCase(user),
board.isPinned,
board.fileUrls
board.isPinned
)
)
.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 @@ -139,4 +138,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