Skip to content

Commit

Permalink
Merge pull request #10 from DDD-Community/feature/POLABO-108
Browse files Browse the repository at this point in the history
Feature/polabo 108 : 폴라로이드 최신순 정렬, 보드 생성 가능 여부 조회 개발
  • Loading branch information
dldmsql authored Jul 19, 2024
2 parents 358ef3f + 2a925b9 commit 5f053da
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ class BoardController(
""")
@GetMapping("/total-count")
fun getTotalCount() = ApplicationResponse.ok(this.boardService.getTotalCount())

@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 @@ -9,4 +9,5 @@ interface BoardJooqRepository {
fun insertOne(request: BoardCreateRequest): ByteArray?
fun selectOneById(id: UUID) : Array<out Record6<String?, Long?, String?, String?, LocalDateTime?, ByteArray?>>
fun selectTotalCount(): Long
fun selectTodayTotalCount(): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class BoardJooqRepositoryImpl(
jBoard.ID.eq(UuidConverter.uuidToByteArray(id)).and(jBoard.YN.eq(1))
.and(jBoard.ACTIVEYN.eq(1))
)
.orderBy(jPolaroid.CREATED_AT.desc())
.fetchArray()

}
Expand All @@ -67,4 +68,18 @@ class BoardJooqRepositoryImpl(
.where(jBoard.YN.eq(1).and(jBoard.ACTIVEYN.eq(1)))
.fetchOne(0, Long::class.java) ?: 0
}

override fun selectTodayTotalCount(): Long {
val jBoard = Board.BOARD
return this.dslContext
.selectCount()
.from(jBoard)
.where(
jBoard.CREATED_AT.greaterOrEqual(DateConverter.convertToKst(LocalDateTime.now().withHour(0).withMinute(0).withSecond(0)))
.and(jBoard.CREATED_AT.lessThan(DateConverter.convertToKst(LocalDateTime.now().withHour(23).withMinute(59).withSecond(59)))
.and(jBoard.YN.eq(1))
.and(jBoard.ACTIVEYN.eq(1))
))
.fetchOne(0, Long::class.java) ?: 0L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import com.ddd.sonnypolabobe.domain.board.repository.BoardJooqRepository
import com.ddd.sonnypolabobe.domain.polaroid.controller.dto.PolaroidGetResponse
import com.ddd.sonnypolabobe.global.util.S3Util
import com.ddd.sonnypolabobe.global.util.UuidConverter
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import java.util.*

@Service
class BoardService(
private val boardJooqRepository: BoardJooqRepository,
private val s3Util: S3Util
private val s3Util: S3Util,
@Value("\${limit.count}")
private val limit: Int
) {
fun create(request: BoardCreateRequest): UUID? {
return this.boardJooqRepository.insertOne(request)?.let { UuidConverter.byteArrayToUUID(it) }
Expand All @@ -38,5 +41,10 @@ class BoardService(
}

fun getTotalCount(): Long = this.boardJooqRepository.selectTotalCount()
fun createAvailable(): Long {
return this.boardJooqRepository.selectTodayTotalCount().let {
if (it > limit) 0 else limit - it
}
}

}

0 comments on commit 5f053da

Please sign in to comment.