Skip to content

Commit

Permalink
Merge pull request #31 from DDD-Community/feature/POLABO-108
Browse files Browse the repository at this point in the history
feat(POLABO-128): 3차 mvp 개발
  • Loading branch information
dldmsql authored Sep 1, 2024
2 parents 28211f1 + cca8f30 commit 1456df1
Show file tree
Hide file tree
Showing 19 changed files with 319 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,46 @@ import java.util.UUID
class BoardController(
private val boardService: BoardService
) {
@Operation(summary = "보드 생성", description = """
@Operation(
summary = "보드 생성", description = """
보드를 생성합니다.
userId는 추후 회원가입 기능이 추가될 것을 대비한 것입니다. 지금은 null로 주세요.
userId 데이터는 백에서 채울 것입니다.!
""")
"""
)
@PostMapping
fun create(@RequestBody request : BoardCreateRequest)
: ApplicationResponse<UUID> {
val user = SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
fun create(@RequestBody request: BoardCreateRequest)
: ApplicationResponse<UUID> {
val user =
SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
request.userId = user.id
return ApplicationResponse.ok(this.boardService.create(request))
}

@Operation(summary = "보드 조회", description = """
@Tag(name = "1.1.0")
@Operation(
summary = "보드 조회", description = """
보드를 조회합니다.
""")
DTO 필드 수정했습니다. 폴라로이드에 닉네임 필드 추가
"""
)
@GetMapping("/{id}")
fun get(@PathVariable id : String)
= ApplicationResponse.ok(this.boardService.getById(id))
fun get(@PathVariable id: String) = ApplicationResponse.ok(this.boardService.getById(id))

@Operation(summary = "보드 누적 생성 수 조회", description = """
@Operation(
summary = "보드 누적 생성 수 조회", description = """
보드 누적 생성 수를 조회합니다.
""")
"""
)
@GetMapping("/total-count")
fun getTotalCount() = ApplicationResponse.ok(this.boardService.getTotalCount())

@Operation(summary = "오늘 생성 가능한 보드 수 조회", description = """
@Operation(
summary = "오늘 생성 가능한 보드 수 조회", description = """
오늘 생성 가능한 보드 수를 조회합니다.
""")
"""
)
@GetMapping("/create-available")
fun createAvailable() = ApplicationResponse.ok(this.boardService.createAvailable())
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,26 @@ import com.ddd.sonnypolabobe.domain.user.dto.UserDto
import com.ddd.sonnypolabobe.global.entity.PageDto
import com.ddd.sonnypolabobe.global.response.ApplicationResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/v1/my/boards")
class MyBoardController(private val myBoardService : MyBoardService) {
class MyBoardController(private val myBoardService: MyBoardService) {

@Operation(summary = "내 보드 목록 조회", description = """
@Operation(
summary = "내 보드 목록 조회", description = """
내 보드 목록을 조회합니다.
""")
"""
)
@GetMapping
fun getMyBoards(
@RequestParam(name = "page", defaultValue = "1") page : Int,
@RequestParam size : Int
) : ApplicationResponse<PageDto<MyBoardDto.Companion.PageListRes>> {
val user = SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
@RequestParam(name = "page", defaultValue = "1") page: Int,
@RequestParam size: Int
): ApplicationResponse<PageDto<MyBoardDto.Companion.PageListRes>> {
val user =
SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
return ApplicationResponse.ok(this.myBoardService.getMyBoards(user.id, page, size))
}

Expand All @@ -34,10 +38,11 @@ class MyBoardController(private val myBoardService : MyBoardService) {
)
@PutMapping("/{id}")
fun updateMyBoard(
@PathVariable id : String,
@RequestBody request : MyBoardDto.Companion.MBUpdateReq
) : ApplicationResponse<Nothing> {
val userId = SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
@PathVariable id: String,
@RequestBody request: MyBoardDto.Companion.MBUpdateReq
): ApplicationResponse<Nothing> {
val userId =
SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
this.myBoardService.updateMyBoard(id, request, userId.id)
return ApplicationResponse.ok()
}
Expand All @@ -50,10 +55,25 @@ class MyBoardController(private val myBoardService : MyBoardService) {
)
@DeleteMapping("/{id}")
fun deleteMyBoard(
@PathVariable id : String
) : ApplicationResponse<Nothing> {
val userId = SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
@PathVariable id: String
): ApplicationResponse<Nothing> {
val userId =
SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
this.myBoardService.deleteMyBoard(id, userId.id)
return ApplicationResponse.ok()
}

@Tag(name = "1.1.0")
@Operation(
summary = "내가 만든 보드 총 개수",
description = """
내가 만든 보드의 총 개수를 조회합니다.
"""
)
@GetMapping("/total-count")
fun getTotalCount(): ApplicationResponse<MyBoardDto.Companion.TotalCountRes> {
val userId =
SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
return ApplicationResponse.ok(this.myBoardService.getTotalCount(userId.id))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ddd.sonnypolabobe.domain.board.my.controller

import com.ddd.sonnypolabobe.domain.board.my.dto.MyBoardDto
import com.ddd.sonnypolabobe.domain.board.my.service.MyBoardService
import com.ddd.sonnypolabobe.domain.user.dto.UserDto
import com.ddd.sonnypolabobe.global.entity.PageDto
import com.ddd.sonnypolabobe.global.response.ApplicationResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.bind.annotation.*

@Tag(name = "1.1.0")
@RestController
@RequestMapping("/api/v2/my/boards")
class MyBoardV2Controller(private val myBoardService : MyBoardService) {

@Operation(summary = "내 보드 목록 조회 - v2", description = """
내 보드 목록을 조회합니다.
필터가 추가되었습니다.
""")
@GetMapping
fun getMyBoards(
@RequestParam(name = "page", defaultValue = "1") page : Int,
@RequestParam size : Int,
@RequestParam filter : Filter
) : ApplicationResponse<PageDto<MyBoardDto.Companion.PageListRes>> {
val user = SecurityContextHolder.getContext().authentication.principal as UserDto.Companion.Res
return ApplicationResponse.ok(this.myBoardService.getMyBoards(user.id, page, size, filter))
}

companion object {
enum class Filter {
OWNER, PARTICIPANT
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ class MyBoardDto {
val title: String,
@DateTimeFormat(pattern = "yyyy-MM-dd", iso = DateTimeFormat.ISO.DATE)
val createdAt: LocalDateTime,
val userId : Long?
val userId: Long?
)

data class TotalCountRes(
val totalCreateCount: Long,
val totalParticipantCount: Long
)

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.ddd.sonnypolabobe.domain.board.my.service

import com.ddd.sonnypolabobe.domain.board.my.controller.MyBoardV2Controller
import com.ddd.sonnypolabobe.domain.board.my.dto.MyBoardDto
import com.ddd.sonnypolabobe.domain.board.repository.BoardJooqRepository
import com.ddd.sonnypolabobe.domain.polaroid.repository.PolaroidJooqRepository
import com.ddd.sonnypolabobe.domain.polaroid.service.PolaroidService
import com.ddd.sonnypolabobe.global.entity.PageDto
import com.ddd.sonnypolabobe.global.util.UuidConverter
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class MyBoardService(private val boardJooqRepository: BoardJooqRepository) {
class MyBoardService(
private val boardJooqRepository: BoardJooqRepository,
) {
@Transactional
fun updateMyBoard(id: String, request: MyBoardDto.Companion.MBUpdateReq, userId: Long) {
val board = this.boardJooqRepository.findById(UuidConverter.stringToUUID(id))
?: throw IllegalArgumentException("해당 보드가 존재하지 않습니다.")
Expand All @@ -17,6 +24,7 @@ class MyBoardService(private val boardJooqRepository: BoardJooqRepository) {
this.boardJooqRepository.updateTitle(UuidConverter.stringToUUID(id), request.title)
}

@Transactional
fun deleteMyBoard(id: String, userId: Long) {
val board = this.boardJooqRepository.findById(UuidConverter.stringToUUID(id))
?: throw IllegalArgumentException("해당 보드가 존재하지 않습니다.")
Expand All @@ -26,10 +34,41 @@ class MyBoardService(private val boardJooqRepository: BoardJooqRepository) {
this.boardJooqRepository.delete(UuidConverter.stringToUUID(id))
}

@Transactional(readOnly = true)
fun getMyBoards(userId: Long, page: Int, size: Int): PageDto<MyBoardDto.Companion.PageListRes> {
val data = this.boardJooqRepository.findAllByUserId(userId, page-1, size)
val data = this.boardJooqRepository.findAllByUserId(userId, page - 1, size)
val totalCount = this.boardJooqRepository.selectTotalCountByUserId(userId)

return PageDto(data, totalCount, page, size)
}

@Transactional(readOnly = true)
fun getMyBoards(
userId: Long,
page: Int,
size: Int,
filter: MyBoardV2Controller.Companion.Filter
): PageDto<MyBoardDto.Companion.PageListRes> {
when (filter) {
MyBoardV2Controller.Companion.Filter.OWNER -> {
val data = this.boardJooqRepository.findAllByUserId(userId, page - 1, size)
val totalCount = this.boardJooqRepository.selectTotalCountByUserId(userId)
return PageDto(data, totalCount, page, size)
}

MyBoardV2Controller.Companion.Filter.PARTICIPANT -> {
val data = this.boardJooqRepository.findAllByParticipant(userId, page - 1, size)
val totalCount = this.boardJooqRepository.selectTotalCountByParticipant(userId)
return PageDto(data, totalCount, page, size)
}
}
}

@Transactional(readOnly = true)
fun getTotalCount(userId: Long): MyBoardDto.Companion.TotalCountRes {
return MyBoardDto.Companion.TotalCountRes(
totalCreateCount = this.boardJooqRepository.selectTotalCountByUserId(userId),
totalParticipantCount = this.boardJooqRepository.selectTotalCountByParticipant(userId)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardCreateRequest
import com.ddd.sonnypolabobe.domain.board.my.dto.MyBoardDto
import com.ddd.sonnypolabobe.jooq.polabo.tables.Board
import org.jooq.Record6
import org.jooq.Record7
import java.time.LocalDateTime
import java.util.*

interface BoardJooqRepository {
fun insertOne(request: BoardCreateRequest): ByteArray?
fun selectOneById(id: UUID) : Array<out Record6<String?, Long?, String?, String?, LocalDateTime?, Long?>>
fun selectOneById(id: UUID) : Array<out Record7<String?, Long?, String?, String?, LocalDateTime?, Long?, String?>>
fun selectTotalCount(): Long
fun selectTodayTotalCount(): Long
fun findById(id: UUID): MyBoardDto.Companion.GetOneRes?
fun updateTitle(id: UUID, title: String)
fun delete(id: UUID)
fun findAllByUserId(userId: Long, page: Int, size: Int): List<MyBoardDto.Companion.PageListRes>
fun selectTotalCountByUserId(userId: Long): Long
fun findAllByParticipant(
userId: Long,
page: Int,
size: Int
): List<MyBoardDto.Companion.PageListRes>

fun selectTotalCountByParticipant(userId: Long): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.ddd.sonnypolabobe.jooq.polabo.tables.Board
import com.ddd.sonnypolabobe.jooq.polabo.tables.Polaroid
import org.jooq.DSLContext
import org.jooq.Record6
import org.jooq.Record7
import org.springframework.stereotype.Repository
import java.time.LocalDateTime
import java.util.*
Expand All @@ -36,7 +37,7 @@ class BoardJooqRepositoryImpl(
return if (result == 1) id else null
}

override fun selectOneById(id: UUID): Array<out Record6<String?, Long?, String?, String?, LocalDateTime?, Long?>> {
override fun selectOneById(id: UUID): Array<out Record7<String?, Long?, String?, String?, LocalDateTime?, Long?, String?>> {
val jBoard = Board.BOARD
val jPolaroid = Polaroid.POLAROID
return this.dslContext
Expand All @@ -46,7 +47,8 @@ class BoardJooqRepositoryImpl(
jPolaroid.IMAGE_KEY,
jPolaroid.ONE_LINE_MESSAGE,
jPolaroid.CREATED_AT,
jPolaroid.USER_ID
jPolaroid.USER_ID,
jPolaroid.NICKNAME
)
.from(jBoard)
.leftJoin(jPolaroid).on(
Expand Down Expand Up @@ -149,4 +151,44 @@ class BoardJooqRepositoryImpl(
.where(jBoard.USER_ID.eq(userId).and(jBoard.YN.eq(1)).and(jBoard.ACTIVEYN.eq(1)))
.fetchOne(0, Long::class.java) ?: 0L
}

override fun findAllByParticipant(
userId: Long,
page: Int,
size: Int
): List<MyBoardDto.Companion.PageListRes> {
val jBoard = Board.BOARD
val jPolaroid = Polaroid.POLAROID
val data = this.dslContext.select(
jBoard.ID,
jBoard.TITLE,
jBoard.CREATED_AT
)
.from(jBoard)
.innerJoin(jPolaroid).on(
jBoard.ID.eq(jPolaroid.BOARD_ID).and(jPolaroid.USER_ID.eq(userId))
.and(jPolaroid.YN.eq(1)).and(jPolaroid.ACTIVEYN.eq(1))
)

return data.map {
MyBoardDto.Companion.PageListRes(
id = UuidConverter.byteArrayToUUID(it.get("id", ByteArray::class.java)!!),
title = it.get("title", String::class.java)!!,
createdAt = it.get("created_at", LocalDateTime::class.java)!!,
)
}
}

override fun selectTotalCountByParticipant(userId: Long): Long {
val jBoard = Board.BOARD
val jPolaroid = Polaroid.POLAROID
return this.dslContext
.selectCount()
.from(jBoard)
.innerJoin(jPolaroid).on(
jBoard.ID.eq(jPolaroid.BOARD_ID).and(jPolaroid.USER_ID.eq(userId))
.and(jPolaroid.YN.eq(1)).and(jPolaroid.ACTIVEYN.eq(1))
)
.fetchOne(0, Long::class.java) ?: 0L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class BoardService(
@Value("\${limit.count}")
private val limit: Int
) {
fun create(request: BoardCreateRequest): UUID = this.boardJooqRepository.insertOne(request)?.let { UuidConverter.byteArrayToUUID(it) }
?: throw ApplicationException(CustomErrorCode.BOARD_CREATED_FAILED)
fun create(request: BoardCreateRequest): UUID =
this.boardJooqRepository.insertOne(request)?.let { UuidConverter.byteArrayToUUID(it) }
?: throw ApplicationException(CustomErrorCode.BOARD_CREATED_FAILED)

fun getById(id: String): List<BoardGetResponse> {
return id.run {
val queryResult = boardJooqRepository.selectOneById(UuidConverter.stringToUUID(this@run))
val queryResult =
boardJooqRepository.selectOneById(UuidConverter.stringToUUID(this@run))
val groupByTitle = queryResult.groupBy { it.value1() }
groupByTitle.map { entry ->
val title = entry.key
Expand All @@ -33,7 +35,8 @@ class BoardService(
id = it.value2() ?: 0L,
imageUrl = it.value3()?.let { it1 -> s3Util.getImgUrl(it1) } ?: "",
oneLineMessage = it.value4() ?: "폴라보와의 추억 한 줄",
userId = it.value6() ?: 0L
userId = it.value6() ?: 0L,
nickname = it.value7() ?: ""
)
}.filter { it.id != 0L }
BoardGetResponse(title = title ?: "", items = polaroids)
Expand Down
Loading

0 comments on commit 1456df1

Please sign in to comment.