generated from pricelees/issue-pr-template
[#18] 코드 정리 및 일부 컨벤션 통일 #19
@ -19,7 +19,7 @@ class ThemeService(
|
|||||||
private val themeRepository: ThemeRepository
|
private val themeRepository: ThemeRepository
|
||||||
) {
|
) {
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
fun findThemeById(id: Long): ThemeEntity = themeRepository.findByIdOrNull(id)
|
fun findById(id: Long): ThemeEntity = themeRepository.findByIdOrNull(id)
|
||||||
?: throw RoomescapeException(
|
?: throw RoomescapeException(
|
||||||
ErrorType.THEME_NOT_FOUND,
|
ErrorType.THEME_NOT_FOUND,
|
||||||
"[themeId: $id]",
|
"[themeId: $id]",
|
||||||
@ -27,22 +27,22 @@ class ThemeService(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
fun findAllThemes(): ThemesResponse = themeRepository.findAll()
|
fun findAll(): ThemesResponse = themeRepository.findAll()
|
||||||
.toResponse()
|
.toResponse()
|
||||||
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
fun getMostReservedThemesByCount(count: Int): ThemesResponse {
|
fun findMostReservedThemes(count: Int): ThemesResponse {
|
||||||
val today = LocalDate.now()
|
val today = LocalDate.now()
|
||||||
val startDate = today.minusDays(7)
|
val startDate = today.minusDays(7)
|
||||||
val endDate = today.minusDays(1)
|
val endDate = today.minusDays(1)
|
||||||
|
|
||||||
return themeRepository.findTopNThemeBetweenStartDateAndEndDate(startDate, endDate, count)
|
return themeRepository.findPopularThemes(startDate, endDate, count)
|
||||||
.toResponse()
|
.toResponse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
fun save(request: ThemeRequest): ThemeResponse {
|
fun create(request: ThemeRequest): ThemeResponse {
|
||||||
if (themeRepository.existsByName(request.name)) {
|
if (themeRepository.existsByName(request.name)) {
|
||||||
throw RoomescapeException(
|
throw RoomescapeException(
|
||||||
ErrorType.THEME_DUPLICATED,
|
ErrorType.THEME_DUPLICATED,
|
||||||
|
|||||||
@ -23,11 +23,11 @@ interface ThemeAPI {
|
|||||||
@LoginRequired
|
@LoginRequired
|
||||||
@Operation(summary = "모든 테마 조회", description = "모든 테마를 조회합니다.", tags = ["로그인이 필요한 API"])
|
@Operation(summary = "모든 테마 조회", description = "모든 테마를 조회합니다.", tags = ["로그인이 필요한 API"])
|
||||||
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
|
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
|
||||||
fun getAllThemes(): ResponseEntity<CommonApiResponse<ThemesResponse>>
|
fun findAll(): ResponseEntity<CommonApiResponse<ThemesResponse>>
|
||||||
|
|
||||||
@Operation(summary = "가장 많이 예약된 테마 조회")
|
@Operation(summary = "가장 많이 예약된 테마 조회")
|
||||||
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
|
@ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true))
|
||||||
fun getMostReservedThemes(
|
fun findMostReservedThemes(
|
||||||
@RequestParam(defaultValue = "10") @Parameter(description = "최대로 조회할 테마 갯수") count: Int
|
@RequestParam(defaultValue = "10") @Parameter(description = "최대로 조회할 테마 갯수") count: Int
|
||||||
): ResponseEntity<CommonApiResponse<ThemesResponse>>
|
): ResponseEntity<CommonApiResponse<ThemesResponse>>
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ interface ThemeAPI {
|
|||||||
@ApiResponses(
|
@ApiResponses(
|
||||||
ApiResponse(responseCode = "201", description = "성공", useReturnTypeSchema = true),
|
ApiResponse(responseCode = "201", description = "성공", useReturnTypeSchema = true),
|
||||||
)
|
)
|
||||||
fun saveTheme(
|
fun create(
|
||||||
@Valid @RequestBody request: ThemeRequest,
|
@Valid @RequestBody request: ThemeRequest,
|
||||||
): ResponseEntity<CommonApiResponse<ThemeResponse>>
|
): ResponseEntity<CommonApiResponse<ThemeResponse>>
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ interface ThemeAPI {
|
|||||||
@ApiResponses(
|
@ApiResponses(
|
||||||
ApiResponse(responseCode = "204", description = "성공", useReturnTypeSchema = true),
|
ApiResponse(responseCode = "204", description = "성공", useReturnTypeSchema = true),
|
||||||
)
|
)
|
||||||
fun removeTheme(
|
fun deleteById(
|
||||||
@PathVariable id: Long
|
@PathVariable id: Long
|
||||||
): ResponseEntity<CommonApiResponse<Unit>>
|
): ResponseEntity<CommonApiResponse<Unit>>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,9 @@ interface ThemeRepository : JpaRepository<ThemeEntity, Long> {
|
|||||||
GROUP BY r.theme.id
|
GROUP BY r.theme.id
|
||||||
ORDER BY COUNT(r.theme.id) DESC, t.id ASC
|
ORDER BY COUNT(r.theme.id) DESC, t.id ASC
|
||||||
LIMIT :limit
|
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
|
fun existsByName(name: String): Boolean
|
||||||
|
|
||||||
|
|||||||
@ -15,33 +15,33 @@ class ThemeController(
|
|||||||
) : ThemeAPI {
|
) : ThemeAPI {
|
||||||
|
|
||||||
@GetMapping("/themes")
|
@GetMapping("/themes")
|
||||||
override fun getAllThemes(): ResponseEntity<CommonApiResponse<ThemesResponse>> {
|
override fun findAll(): ResponseEntity<CommonApiResponse<ThemesResponse>> {
|
||||||
val response: ThemesResponse = themeService.findAllThemes()
|
val response: ThemesResponse = themeService.findAll()
|
||||||
|
|
||||||
return ResponseEntity.ok(CommonApiResponse(response))
|
return ResponseEntity.ok(CommonApiResponse(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/themes/most-reserved-last-week")
|
@GetMapping("/themes/most-reserved-last-week")
|
||||||
override fun getMostReservedThemes(
|
override fun findMostReservedThemes(
|
||||||
@RequestParam(defaultValue = "10") @Parameter(description = "최대로 조회할 테마 갯수") count: Int
|
@RequestParam(defaultValue = "10") @Parameter(description = "최대로 조회할 테마 갯수") count: Int
|
||||||
): ResponseEntity<CommonApiResponse<ThemesResponse>> {
|
): ResponseEntity<CommonApiResponse<ThemesResponse>> {
|
||||||
val response: ThemesResponse = themeService.getMostReservedThemesByCount(count)
|
val response: ThemesResponse = themeService.findMostReservedThemes(count)
|
||||||
|
|
||||||
return ResponseEntity.ok(CommonApiResponse(response))
|
return ResponseEntity.ok(CommonApiResponse(response))
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/themes")
|
@PostMapping("/themes")
|
||||||
override fun saveTheme(
|
override fun create(
|
||||||
@RequestBody @Valid request: ThemeRequest
|
@RequestBody @Valid request: ThemeRequest
|
||||||
): ResponseEntity<CommonApiResponse<ThemeResponse>> {
|
): ResponseEntity<CommonApiResponse<ThemeResponse>> {
|
||||||
val themeResponse: ThemeResponse = themeService.save(request)
|
val themeResponse: ThemeResponse = themeService.create(request)
|
||||||
|
|
||||||
return ResponseEntity.created(URI.create("/themes/${themeResponse.id}"))
|
return ResponseEntity.created(URI.create("/themes/${themeResponse.id}"))
|
||||||
.body(CommonApiResponse(themeResponse))
|
.body(CommonApiResponse(themeResponse))
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/themes/{id}")
|
@DeleteMapping("/themes/{id}")
|
||||||
override fun removeTheme(
|
override fun deleteById(
|
||||||
@PathVariable id: Long
|
@PathVariable id: Long
|
||||||
): ResponseEntity<CommonApiResponse<Unit>> {
|
): ResponseEntity<CommonApiResponse<Unit>> {
|
||||||
themeService.deleteById(id)
|
themeService.deleteById(id)
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class ThemeServiceTest : FunSpec({
|
|||||||
} returns null
|
} returns null
|
||||||
|
|
||||||
val exception = shouldThrow<RoomescapeException> {
|
val exception = shouldThrow<RoomescapeException> {
|
||||||
themeService.findThemeById(themeId)
|
themeService.findById(themeId)
|
||||||
}
|
}
|
||||||
|
|
||||||
exception.errorType shouldBe ErrorType.THEME_NOT_FOUND
|
exception.errorType shouldBe ErrorType.THEME_NOT_FOUND
|
||||||
@ -51,7 +51,7 @@ class ThemeServiceTest : FunSpec({
|
|||||||
themeRepository.findAll()
|
themeRepository.findAll()
|
||||||
} returns themes
|
} returns themes
|
||||||
|
|
||||||
assertSoftly(themeService.findAllThemes()) {
|
assertSoftly(themeService.findAll()) {
|
||||||
this.themes.size shouldBe themes.size
|
this.themes.size shouldBe themes.size
|
||||||
this.themes[0].name shouldBe "t1"
|
this.themes[0].name shouldBe "t1"
|
||||||
this.themes[1].name shouldBe "t2"
|
this.themes[1].name shouldBe "t2"
|
||||||
@ -68,7 +68,7 @@ class ThemeServiceTest : FunSpec({
|
|||||||
} returns true
|
} returns true
|
||||||
|
|
||||||
val exception = shouldThrow<RoomescapeException> {
|
val exception = shouldThrow<RoomescapeException> {
|
||||||
themeService.save(ThemeRequest(
|
themeService.create(ThemeRequest(
|
||||||
name = name,
|
name = name,
|
||||||
description = "Description",
|
description = "Description",
|
||||||
thumbnail = "http://example.com/thumbnail.jpg"
|
thumbnail = "http://example.com/thumbnail.jpg"
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class ThemeRepositoryTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("지난 10일간 예약 수가 가장 많은 테마 5개를 조회한다.") {
|
test("지난 10일간 예약 수가 가장 많은 테마 5개를 조회한다.") {
|
||||||
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
|
themeRepository.findPopularThemes(
|
||||||
LocalDate.now().minusDays(10),
|
LocalDate.now().minusDays(10),
|
||||||
LocalDate.now().minusDays(1),
|
LocalDate.now().minusDays(1),
|
||||||
5
|
5
|
||||||
@ -41,7 +41,7 @@ class ThemeRepositoryTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("8일 전부터 5일 전까지 예약 수가 가장 많은 테마 3개를 조회한다.") {
|
test("8일 전부터 5일 전까지 예약 수가 가장 많은 테마 3개를 조회한다.") {
|
||||||
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
|
themeRepository.findPopularThemes(
|
||||||
LocalDate.now().minusDays(8),
|
LocalDate.now().minusDays(8),
|
||||||
LocalDate.now().minusDays(5),
|
LocalDate.now().minusDays(5),
|
||||||
3
|
3
|
||||||
@ -61,7 +61,7 @@ class ThemeRepositoryTest(
|
|||||||
date = LocalDate.now().minusDays(5),
|
date = LocalDate.now().minusDays(5),
|
||||||
)
|
)
|
||||||
|
|
||||||
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
|
themeRepository.findPopularThemes(
|
||||||
LocalDate.now().minusDays(6),
|
LocalDate.now().minusDays(6),
|
||||||
LocalDate.now().minusDays(4),
|
LocalDate.now().minusDays(4),
|
||||||
5
|
5
|
||||||
@ -74,7 +74,7 @@ class ThemeRepositoryTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("입력된 갯수보다 조회된 갯수가 작으면, 조회된 갯수만큼 반환한다.") {
|
test("입력된 갯수보다 조회된 갯수가 작으면, 조회된 갯수만큼 반환한다.") {
|
||||||
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
|
themeRepository.findPopularThemes(
|
||||||
LocalDate.now().minusDays(10),
|
LocalDate.now().minusDays(10),
|
||||||
LocalDate.now().minusDays(6),
|
LocalDate.now().minusDays(6),
|
||||||
10
|
10
|
||||||
@ -84,7 +84,7 @@ class ThemeRepositoryTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("입력된 갯수보다 조회된 갯수가 많으면, 입력된 갯수만큼 반환한다.") {
|
test("입력된 갯수보다 조회된 갯수가 많으면, 입력된 갯수만큼 반환한다.") {
|
||||||
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
|
themeRepository.findPopularThemes(
|
||||||
LocalDate.now().minusDays(10),
|
LocalDate.now().minusDays(10),
|
||||||
LocalDate.now().minusDays(1),
|
LocalDate.now().minusDays(1),
|
||||||
15
|
15
|
||||||
@ -94,7 +94,7 @@ class ThemeRepositoryTest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("입력된 날짜 범위에 예약된 테마가 없을 경우 빈 리스트를 반환한다.") {
|
test("입력된 날짜 범위에 예약된 테마가 없을 경우 빈 리스트를 반환한다.") {
|
||||||
themeRepository.findTopNThemeBetweenStartDateAndEndDate(
|
themeRepository.findPopularThemes(
|
||||||
LocalDate.now().plusDays(1),
|
LocalDate.now().plusDays(1),
|
||||||
LocalDate.now().plusDays(10),
|
LocalDate.now().plusDays(10),
|
||||||
5
|
5
|
||||||
|
|||||||
@ -201,7 +201,7 @@ class ThemeControllerTest(mockMvc: MockMvc) : RoomescapeApiTest() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
every {
|
every {
|
||||||
themeService.save(request)
|
themeService.create(request)
|
||||||
} returns ThemeResponse(
|
} returns ThemeResponse(
|
||||||
id = theme.id!!,
|
id = theme.id!!,
|
||||||
name = theme.name,
|
name = theme.name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user