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

4차 MVP 개발 #35

Merged
merged 2 commits into from
Sep 14, 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
48 changes: 24 additions & 24 deletions .github/workflows/healthCheck.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: "[운영] 헬스체크"

on:
schedule:
- cron: "0 0 */3 * *"

jobs:
healthcheck:
runs-on: ubuntu-latest
steps:
- name: API Health Check
id: health_check
uses: jtalk/url-health-check-action@v3
with:
url: ${{ secrets.BASE_URI_PROD }}
max-attempts: 3
retry-delay: 1s

- name: Discord Webhook Action
if: always()
uses: tsickert/[email protected]
with:
webhook-url: ${{ secrets.WEBHOOK_URL }}
content: ${{ job.status }}
#name: "[운영] 헬스체크"
#
#on:
# schedule:
# - cron: "0 0 */3 * *"
#
#jobs:
# healthcheck:
# runs-on: ubuntu-latest
# steps:
# - name: API Health Check
# id: health_check
# uses: jtalk/url-health-check-action@v3
# with:
# url: ${{ secrets.BASE_URI_PROD }}
# max-attempts: 3
# retry-delay: 1s
#
# - name: Discord Webhook Action
# if: always()
# uses: tsickert/[email protected]
# with:
# webhook-url: ${{ secrets.WEBHOOK_URL }}
# content: ${{ job.status }}
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)
}


}
Loading