refactor: theme 패키지에서의 메서드 컨벤션 수정

This commit is contained in:
이상진 2025-07-22 13:40:04 +09:00
parent 201e11af86
commit 7ec2621c67
7 changed files with 27 additions and 28 deletions

View File

@ -19,7 +19,7 @@ class ThemeService(
private val themeRepository: ThemeRepository
) {
@Transactional(readOnly = true)
fun findThemeById(id: Long): ThemeEntity = themeRepository.findByIdOrNull(id)
fun findById(id: Long): ThemeEntity = themeRepository.findByIdOrNull(id)
?: throw RoomescapeException(
ErrorType.THEME_NOT_FOUND,
"[themeId: $id]",
@ -27,22 +27,22 @@ class ThemeService(
)
@Transactional(readOnly = true)
fun findAllThemes(): ThemesResponse = themeRepository.findAll()
fun findAll(): ThemesResponse = themeRepository.findAll()
.toResponse()
@Transactional(readOnly = true)
fun getMostReservedThemesByCount(count: Int): ThemesResponse {
fun findMostReservedThemes(count: Int): ThemesResponse {
val today = LocalDate.now()
val startDate = today.minusDays(7)
val endDate = today.minusDays(1)
return themeRepository.findTopNThemeBetweenStartDateAndEndDate(startDate, endDate, count)
return themeRepository.findPopularThemes(startDate, endDate, count)
.toResponse()
}
@Transactional
fun save(request: ThemeRequest): ThemeResponse {
fun create(request: ThemeRequest): ThemeResponse {
if (themeRepository.existsByName(request.name)) {
throw RoomescapeException(
ErrorType.THEME_DUPLICATED,

View File

@ -23,11 +23,11 @@ interface ThemeAPI {
@LoginRequired
@Operation(summary = "모든 테마 조회", description = "모든 테마를 조회합니다.", tags = ["로그인이 필요한 API"])
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
fun getAllThemes(): ResponseEntity<CommonApiResponse<ThemesResponse>>
fun findAll(): ResponseEntity<CommonApiResponse<ThemesResponse>>
@Operation(summary = "가장 많이 예약된 테마 조회")
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
fun getMostReservedThemes(
fun findMostReservedThemes(
@RequestParam(defaultValue = "10") @Parameter(description = "최대로 조회할 테마 갯수") count: Int
): ResponseEntity<CommonApiResponse<ThemesResponse>>
@ -36,7 +36,7 @@ interface ThemeAPI {
@ApiResponses(
ApiResponse(responseCode = "201", description = "성공", useReturnTypeSchema = true),
)
fun saveTheme(
fun create(
@Valid @RequestBody request: ThemeRequest,
): ResponseEntity<CommonApiResponse<ThemeResponse>>
@ -45,7 +45,7 @@ interface ThemeAPI {
@ApiResponses(
ApiResponse(responseCode = "204", description = "성공", useReturnTypeSchema = true),
)
fun removeTheme(
fun deleteById(
@PathVariable id: Long
): ResponseEntity<CommonApiResponse<Unit>>
}

View File

@ -14,10 +14,9 @@ interface ThemeRepository : JpaRepository<ThemeEntity, Long> {
GROUP BY r.theme.id
ORDER BY COUNT(r.theme.id) DESC, t.id ASC
LIMIT :limit
"""
)
fun findTopNThemeBetweenStartDateAndEndDate(startDate: LocalDate, endDate: LocalDate, limit: Int): List<ThemeEntity>
fun findPopularThemes(startDate: LocalDate, endDate: LocalDate, limit: Int): List<ThemeEntity>
fun existsByName(name: String): Boolean

View File

@ -15,33 +15,33 @@ class ThemeController(
) : ThemeAPI {
@GetMapping("/themes")
override fun getAllThemes(): ResponseEntity<CommonApiResponse<ThemesResponse>> {
val response: ThemesResponse = themeService.findAllThemes()
override fun findAll(): ResponseEntity<CommonApiResponse<ThemesResponse>> {
val response: ThemesResponse = themeService.findAll()
return ResponseEntity.ok(CommonApiResponse(response))
}
@GetMapping("/themes/most-reserved-last-week")
override fun getMostReservedThemes(
override fun findMostReservedThemes(
@RequestParam(defaultValue = "10") @Parameter(description = "최대로 조회할 테마 갯수") count: Int
): ResponseEntity<CommonApiResponse<ThemesResponse>> {
val response: ThemesResponse = themeService.getMostReservedThemesByCount(count)
val response: ThemesResponse = themeService.findMostReservedThemes(count)
return ResponseEntity.ok(CommonApiResponse(response))
}
@PostMapping("/themes")
override fun saveTheme(
override fun create(
@RequestBody @Valid request: ThemeRequest
): ResponseEntity<CommonApiResponse<ThemeResponse>> {
val themeResponse: ThemeResponse = themeService.save(request)
val themeResponse: ThemeResponse = themeService.create(request)
return ResponseEntity.created(URI.create("/themes/${themeResponse.id}"))
.body(CommonApiResponse(themeResponse))
}
@DeleteMapping("/themes/{id}")
override fun removeTheme(
override fun deleteById(
@PathVariable id: Long
): ResponseEntity<CommonApiResponse<Unit>> {
themeService.deleteById(id)

View File

@ -37,7 +37,7 @@ class ThemeServiceTest : FunSpec({
} returns null
val exception = shouldThrow<RoomescapeException> {
themeService.findThemeById(themeId)
themeService.findById(themeId)
}
exception.errorType shouldBe ErrorType.THEME_NOT_FOUND
@ -51,7 +51,7 @@ class ThemeServiceTest : FunSpec({
themeRepository.findAll()
} returns themes
assertSoftly(themeService.findAllThemes()) {
assertSoftly(themeService.findAll()) {
this.themes.size shouldBe themes.size
this.themes[0].name shouldBe "t1"
this.themes[1].name shouldBe "t2"
@ -68,7 +68,7 @@ class ThemeServiceTest : FunSpec({
} returns true
val exception = shouldThrow<RoomescapeException> {
themeService.save(ThemeRequest(
themeService.create(ThemeRequest(
name = name,
description = "Description",
thumbnail = "http://example.com/thumbnail.jpg"

View File

@ -28,7 +28,7 @@ class ThemeRepositoryTest(
}
test("지난 10일간 예약 수가 가장 많은 테마 5개를 조회한다.") {
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
themeRepository.findPopularThemes(
LocalDate.now().minusDays(10),
LocalDate.now().minusDays(1),
5
@ -41,7 +41,7 @@ class ThemeRepositoryTest(
}
test("8일 전부터 5일 전까지 예약 수가 가장 많은 테마 3개를 조회한다.") {
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
themeRepository.findPopularThemes(
LocalDate.now().minusDays(8),
LocalDate.now().minusDays(5),
3
@ -61,7 +61,7 @@ class ThemeRepositoryTest(
date = LocalDate.now().minusDays(5),
)
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
themeRepository.findPopularThemes(
LocalDate.now().minusDays(6),
LocalDate.now().minusDays(4),
5
@ -74,7 +74,7 @@ class ThemeRepositoryTest(
}
test("입력된 갯수보다 조회된 갯수가 작으면, 조회된 갯수만큼 반환한다.") {
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
themeRepository.findPopularThemes(
LocalDate.now().minusDays(10),
LocalDate.now().minusDays(6),
10
@ -84,7 +84,7 @@ class ThemeRepositoryTest(
}
test("입력된 갯수보다 조회된 갯수가 많으면, 입력된 갯수만큼 반환한다.") {
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
themeRepository.findPopularThemes(
LocalDate.now().minusDays(10),
LocalDate.now().minusDays(1),
15
@ -94,7 +94,7 @@ class ThemeRepositoryTest(
}
test("입력된 날짜 범위에 예약된 테마가 없을 경우 빈 리스트를 반환한다.") {
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
themeRepository.findPopularThemes(
LocalDate.now().plusDays(1),
LocalDate.now().plusDays(10),
5

View File

@ -201,7 +201,7 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
)
every {
themeService.save(request)
themeService.create(request)
} returns ThemeResponse(
id = theme.id!!,
name = theme.name,