Skip to content

Commit

Permalink
feat: 4차 MVP 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
dldmsql committed Sep 14, 2024
1 parent c90397b commit deb0510
Show file tree
Hide file tree
Showing 22 changed files with 238 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@ class BoardController(
"""
)
@PostMapping
fun create(@RequestBody request: BoardCreateRequest)
: ApplicationResponse<UUID> {
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))
}

@Tag(name = "1.2.0")
@Tag(name = "1.3.0")
@Operation(
summary = "보드 조회", description = """
보드를 조회합니다.
DTO 필드 수정했습니다. 폴라로이드에 닉네임 필드 추가
DTO 필드 수정했습니다. 스티커 리스트 추가했습니다.
"""
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.ddd.sonnypolabobe.domain.board.controller.dto

import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse
import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidGetResponse
import io.swagger.v3.oas.annotations.media.Schema

data class BoardGetResponse(
@Schema(description = "제목", example = "쏘니의 보드")
val title: String,
@Schema(description = "작성자", example = "작성자입니다.")
val items: List<PolaroidGetResponse>
@Schema(description = "폴라로이드")
val items: List<PolaroidGetResponse>,
@Schema(description = "스티커 리스트")
val stickers : List<StickerGetResponse>?
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ddd.sonnypolabobe.domain.board.repository

import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardCreateRequest
import com.ddd.sonnypolabobe.domain.board.my.dto.MyBoardDto
import com.ddd.sonnypolabobe.domain.board.repository.vo.BoardGetOneVo
import com.ddd.sonnypolabobe.domain.user.dto.GenderType
import com.ddd.sonnypolabobe.jooq.polabo.tables.Board
import org.jooq.Record6
Expand All @@ -12,7 +13,7 @@ import java.util.*

interface BoardJooqRepository {
fun insertOne(request: BoardCreateRequest): ByteArray?
fun selectOneById(id: UUID) : Array<out Record7<String?, Long?, String?, String?, LocalDateTime?, Long?, String?>>
fun selectOneById(id: UUID) : List<BoardGetOneVo>
fun selectTotalCount(): Long
fun selectTodayTotalCount(): Long
fun findById(id: UUID): MyBoardDto.Companion.GetOneRes?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package com.ddd.sonnypolabobe.domain.board.repository
import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardCreateRequest
import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardGetResponse
import com.ddd.sonnypolabobe.domain.board.my.dto.MyBoardDto
import com.ddd.sonnypolabobe.domain.board.repository.vo.BoardGetOneVo
import com.ddd.sonnypolabobe.domain.user.dto.GenderType
import com.ddd.sonnypolabobe.global.util.DateConverter
import com.ddd.sonnypolabobe.global.util.UuidConverter
import com.ddd.sonnypolabobe.global.util.UuidGenerator
import com.ddd.sonnypolabobe.jooq.polabo.enums.UserGender
import com.ddd.sonnypolabobe.jooq.polabo.tables.Board
import com.ddd.sonnypolabobe.jooq.polabo.tables.BoardSticker
import com.ddd.sonnypolabobe.jooq.polabo.tables.Polaroid
import com.ddd.sonnypolabobe.jooq.polabo.tables.User
import org.jooq.*
Expand Down Expand Up @@ -43,18 +45,21 @@ class BoardJooqRepositoryImpl(
return if (result == 1) id else null
}

override fun selectOneById(id: UUID): Array<out Record7<String?, Long?, String?, String?, LocalDateTime?, Long?, String?>> {
override fun selectOneById(id: UUID): List<BoardGetOneVo> {
val jBoard = Board.BOARD
val jPolaroid = Polaroid.POLAROID

return this.dslContext
.select(
jBoard.ID.convertFrom { it?.let{UuidConverter.byteArrayToUUID(it) } },
jBoard.TITLE,
jPolaroid.ID,
jPolaroid.ID.`as`(BoardGetOneVo::polaroidId.name),
jPolaroid.IMAGE_KEY,
jPolaroid.ONE_LINE_MESSAGE,
jPolaroid.CREATED_AT,
jPolaroid.USER_ID,
jPolaroid.NICKNAME
jPolaroid.NICKNAME,
jPolaroid.OPTIONS
)
.from(jBoard)
.leftJoin(jPolaroid).on(
Expand All @@ -66,7 +71,7 @@ class BoardJooqRepositoryImpl(
.and(jBoard.ACTIVEYN.eq(1))
)
.orderBy(jPolaroid.CREATED_AT.desc())
.fetchArray()
.fetchInto(BoardGetOneVo::class.java)

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ddd.sonnypolabobe.domain.board.repository.vo

import java.time.LocalDateTime
import java.util.UUID

data class BoardGetOneVo(
val id: UUID?,
val title: String?,
val polaroidId : Long?,
val imageKey : String?,
val oneLineMessage: String?,
val createdAt: LocalDateTime?,
val userId : Long?,
val nickName: String?,
val options: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@ package com.ddd.sonnypolabobe.domain.board.service
import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardCreateRequest
import com.ddd.sonnypolabobe.domain.board.controller.dto.BoardGetResponse
import com.ddd.sonnypolabobe.domain.board.repository.BoardJooqRepository
import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse
import com.ddd.sonnypolabobe.domain.board.sticker.repository.BoardStickerRepository
import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidGetResponse
import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption
import com.ddd.sonnypolabobe.domain.user.dto.UserDto
import com.ddd.sonnypolabobe.global.exception.ApplicationException
import com.ddd.sonnypolabobe.global.exception.CustomErrorCode
import com.ddd.sonnypolabobe.global.security.AuthenticatedMember
import com.ddd.sonnypolabobe.global.util.S3Util
import com.ddd.sonnypolabobe.global.util.UuidConverter
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.util.*
import javax.swing.text.html.HTML.Tag.U

@Service
class BoardService(
private val boardJooqRepository: BoardJooqRepository,
private val boardStickerRepository: BoardStickerRepository,
private val s3Util: S3Util,
@Value("\${limit.count}")
private val limit: Int
Expand All @@ -29,22 +36,24 @@ class BoardService(
return id.run {
val queryResult =
boardJooqRepository.selectOneById(UuidConverter.stringToUUID(this@run))
val groupByTitle = queryResult.groupBy { it.value1() }
val stickers = boardStickerRepository.findByBoardId(UuidConverter.stringToUUID(id))
val groupByTitle = queryResult.groupBy { it.title }
groupByTitle.map { entry ->
val title = entry.key
val polaroids = entry.value.map {
PolaroidGetResponse(
id = it.value2() ?: 0L,
imageUrl = it.value3()?.let { it1 -> s3Util.getImgUrl(it1) } ?: "",
oneLineMessage = it.value4() ?: "폴라보와의 추억 한 줄",
userId = it.value6() ?: 0L,
nickname = it.value7() ?: "",
isMine = it.value6() == user?.id?.toLong(),
createdAt = it.value5()
id = it.polaroidId ?: 0L,
imageUrl = it.imageKey?.let { it1 -> s3Util.getImgUrl(it1) } ?: "",
oneLineMessage = it.oneLineMessage ?: "폴라보와의 추억 한 줄",
userId = it.userId ?: 0L,
nickname = it.nickName ?: "",
isMine = it.userId == user?.id?.toLong(),
createdAt = it.createdAt,
options = it.options?.let{ ObjectMapper().readValue(it, object : TypeReference<Map<PolaroidOption, String>>() {})}

)
}.filter { it.id != 0L }
BoardGetResponse(title = title ?: "", items = polaroids)
}.filter { it.id != 0L }.distinctBy { it.id }
BoardGetResponse(title = title ?: "", items = polaroids, stickers = stickers)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ddd.sonnypolabobe.domain.board.sticker.controller

import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest
import com.ddd.sonnypolabobe.domain.board.sticker.service.StickerService
import com.ddd.sonnypolabobe.global.response.ApplicationResponse
import com.ddd.sonnypolabobe.global.security.JwtUtil
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/v1/boards/sticker")
class BoardStickerController(
private val jwtUtil: JwtUtil,
private val stickerService: StickerService
) {

@Tag(name = "1.3.0")
@GetMapping("/recent")
fun getRecentList( @RequestHeader("Authorization") token: String?)
: ApplicationResponse<List<String>> {
val user = token?.let { this.jwtUtil.getAuthenticatedMemberFromToken(it) }
return ApplicationResponse.ok(this.stickerService.getByUserId(user?.id?.toLong()))
}

@Tag(name = "1.3.0")
@PostMapping
fun createStickerToBoard(
@RequestHeader("Authorization") token: String?,
@RequestBody req : StickerCreateRequest
) : ApplicationResponse<Nothing> {
val user = token?.let { this.jwtUtil.getAuthenticatedMemberFromToken(it) }
this.stickerService.create(req, user?.id?.toLong())
return ApplicationResponse.ok()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ddd.sonnypolabobe.domain.board.sticker.dto

data class StickerCreateRequest(
val boardId : String,
val stickerId: String,
val x : String,
val y : String,
val scale: String,
val rotate: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ddd.sonnypolabobe.domain.board.sticker.dto

data class StickerGetResponse(
val id : String,
val x : String,
val y : String,
val scale: String,
val rotate : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ddd.sonnypolabobe.domain.board.sticker.repository

import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest
import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse
import java.util.*

interface BoardStickerRepository {
fun findByUserId(id: Long) : List<String>
fun insertOne(req: StickerCreateRequest, userId: Long?)
fun findByBoardId(stringToUUID: UUID): List<StickerGetResponse>?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.ddd.sonnypolabobe.domain.board.sticker.repository

import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest
import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerGetResponse
import com.ddd.sonnypolabobe.global.util.DateConverter
import com.ddd.sonnypolabobe.global.util.UuidConverter
import com.ddd.sonnypolabobe.jooq.polabo.tables.BoardSticker
import org.jooq.DSLContext
import org.springframework.stereotype.Repository
import java.time.LocalDateTime
import java.util.*

@Repository
class BoardStickerRepositoryImpl(
private val dslContext: DSLContext
) : BoardStickerRepository {
override fun findByUserId(userId: Long): List<String> {
val jSticker = BoardSticker.BOARD_STICKER
return this.dslContext.selectDistinct(jSticker.STICKER_ID)
.from(jSticker)
.where(jSticker.USER_ID.eq(userId))
.orderBy(jSticker.CREATED_AT.desc())
.fetchInto(String::class.java)
}

override fun insertOne(req: StickerCreateRequest, userId: Long?) {
val jSticker = BoardSticker.BOARD_STICKER
this.dslContext.insertInto(jSticker)
.columns(
jSticker.STICKER_ID,
jSticker.BOARD_ID,
jSticker.USER_ID,
jSticker.X,
jSticker.Y,
jSticker.SCALE,
jSticker.ROTATE,
jSticker.CREATED_AT
).values(
req.stickerId,
UuidConverter.uuidToByteArray(UuidConverter.stringToUUID(req.boardId)),
userId,
req.x,
req.y,
req.scale,
req.rotate,
DateConverter.convertToKst(LocalDateTime.now())
).execute()
}

override fun findByBoardId(stringToUUID: UUID): List<StickerGetResponse>? {
val jSticker = BoardSticker.BOARD_STICKER
return this.dslContext.select(
jSticker.ID,
jSticker.X,
jSticker.Y,
jSticker.SCALE,
jSticker.ROTATE
)
.from(jSticker)
.where(jSticker.BOARD_ID.eq(UuidConverter.uuidToByteArray(stringToUUID)))
.fetchInto(StickerGetResponse::class.java)
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ddd.sonnypolabobe.domain.board.sticker.service

import com.ddd.sonnypolabobe.domain.board.sticker.dto.StickerCreateRequest
import com.ddd.sonnypolabobe.domain.board.sticker.repository.BoardStickerRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class StickerService(
private val boardStickerRepository: BoardStickerRepository
) {
@Transactional(readOnly = true)
fun getByUserId(id: Long?): List<String>
= id?.let { this.boardStickerRepository.findByUserId(id) } ?: emptyList()

@Transactional
fun create(req: StickerCreateRequest, userId: Long?) {
this.boardStickerRepository.insertOne(req, userId)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ddd.sonnypolabobe.domain.polaroid.controller

import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidCreateRequest
import com.ddd.sonnypolabobe.domain.polaroid.enumerate.PolaroidOption
import com.ddd.sonnypolabobe.domain.polaroid.service.PolaroidService
import com.ddd.sonnypolabobe.global.response.ApplicationResponse
import com.ddd.sonnypolabobe.global.security.JwtUtil
Expand All @@ -9,7 +10,7 @@ import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.*

@Tag(name = "1.1.0")
@Tag(name = "1.3.0")
@RestController
@RequestMapping("/api/v2/boards/{boardId}/polaroids")
class BoardPolaroidV2Controller(
Expand All @@ -21,7 +22,9 @@ class BoardPolaroidV2Controller(
summary = "폴라로이드 생성", description = """
폴라로이드를 생성합니다.
작성자 닉네임이 추가되었습니다.
옵션을 추가했습니다.
enum에 따라 옵션을 선택해주세요.
"""
)
@PostMapping
Expand Down
Loading

0 comments on commit deb0510

Please sign in to comment.