From 0ef47b7f94f7b3fecda44d89ba129bb87e8284b2 Mon Sep 17 00:00:00 2001 From: pricelees Date: Wed, 17 Sep 2025 10:39:13 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=85=8C=EB=A7=88=20DTO=20?= =?UTF-8?q?=EB=B0=8F=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=EB=B3=80=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/roomescape/theme/docs/ThemeApi.kt | 15 +++--- .../theme/web/AdminThemeController.kt | 27 +++++----- .../roomescape/theme/web/AdminThemeDto.kt | 49 +++---------------- .../web/{PublicThemeDto.kt => ThemeDto.kt} | 0 4 files changed, 24 insertions(+), 67 deletions(-) rename src/main/kotlin/roomescape/theme/web/{PublicThemeDto.kt => ThemeDto.kt} (100%) diff --git a/src/main/kotlin/roomescape/theme/docs/ThemeApi.kt b/src/main/kotlin/roomescape/theme/docs/ThemeApi.kt index e0d8db6f..a542842c 100644 --- a/src/main/kotlin/roomescape/theme/docs/ThemeApi.kt +++ b/src/main/kotlin/roomescape/theme/docs/ThemeApi.kt @@ -16,11 +16,11 @@ import roomescape.common.dto.response.CommonApiResponse import roomescape.theme.web.* @Tag(name = "5. 관리자 테마 API", description = "관리자 페이지에서 테마를 조회 / 추가 / 삭제할 때 사용합니다.") -interface HQAdminThemeAPI { +interface AdminThemeAPI { @AdminOnly(type = AdminType.HQ, privilege = Privilege.READ_SUMMARY) @Operation(summary = "모든 테마 조회", description = "관리자 페이지에서 요약된 테마 목록을 조회합니다.", tags = ["관리자 로그인이 필요한 API"]) @ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true)) - fun findAdminThemes(): ResponseEntity> + fun getAdminThemeSummaries(): ResponseEntity> @AdminOnly(type = AdminType.HQ, privilege = Privilege.READ_DETAIL) @Operation(summary = "테마 상세 조회", description = "해당 테마의 상세 정보를 조회합니다.", tags = ["관리자 로그인이 필요한 API"]) @@ -42,24 +42,21 @@ interface HQAdminThemeAPI { @ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true)) fun updateTheme( @PathVariable id: Long, - @Valid @RequestBody themeUpdateRequest: ThemeUpdateRequest + @Valid @RequestBody request: ThemeUpdateRequest ): ResponseEntity> -} -interface StoreAdminThemeAPI { - @AdminOnly(type = AdminType.STORE, privilege = Privilege.READ_SUMMARY) + @AdminOnly(privilege = Privilege.READ_SUMMARY) @Operation(summary = "테마 조회", description = "현재 open 상태인 모든 테마 ID + 이름 조회", tags = ["관리자 로그인이 필요한 API"]) @ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true)) - fun findActiveThemes(): ResponseEntity> + fun getActiveThemes(): ResponseEntity> } interface PublicThemeAPI { @Public @Operation(summary = "입력된 모든 ID에 대한 테마 조회") @ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true)) - fun findThemesByIds(request: ThemeIdListRequest): ResponseEntity> + fun findThemeInfosByIds(request: ThemeIdListRequest): ResponseEntity> - @Public @Operation(summary = "입력된 테마 ID에 대한 정보 조회") @ApiResponses(ApiResponse(responseCode = "200", description = "성공", useReturnTypeSchema = true)) fun findThemeInfoById(@PathVariable id: Long): ResponseEntity> diff --git a/src/main/kotlin/roomescape/theme/web/AdminThemeController.kt b/src/main/kotlin/roomescape/theme/web/AdminThemeController.kt index e0412600..b79004a2 100644 --- a/src/main/kotlin/roomescape/theme/web/AdminThemeController.kt +++ b/src/main/kotlin/roomescape/theme/web/AdminThemeController.kt @@ -1,19 +1,20 @@ package roomescape.theme.web +import jakarta.validation.Valid import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* import roomescape.common.dto.response.CommonApiResponse import roomescape.theme.business.ThemeService -import roomescape.theme.docs.HQAdminThemeAPI -import roomescape.theme.docs.StoreAdminThemeAPI +import roomescape.theme.docs.AdminThemeAPI import java.net.URI @RestController -class HQAdminThemeController( +class AdminThemeController( private val themeService: ThemeService, -) : HQAdminThemeAPI { +) : AdminThemeAPI { + @GetMapping("/admin/themes") - override fun findAdminThemes(): ResponseEntity> { + override fun getAdminThemeSummaries(): ResponseEntity> { val response = themeService.findAdminThemes() return ResponseEntity.ok(CommonApiResponse(response)) @@ -27,7 +28,9 @@ class HQAdminThemeController( } @PostMapping("/admin/themes") - override fun createTheme(themeCreateRequest: ThemeCreateRequest): ResponseEntity> { + override fun createTheme( + @Valid @RequestBody themeCreateRequest: ThemeCreateRequest + ): ResponseEntity> { val response = themeService.createTheme(themeCreateRequest) return ResponseEntity.created(URI.create("/admin/themes/${response.id}")) @@ -44,21 +47,15 @@ class HQAdminThemeController( @PatchMapping("/admin/themes/{id}") override fun updateTheme( @PathVariable id: Long, - themeUpdateRequest: ThemeUpdateRequest + @Valid @RequestBody request: ThemeUpdateRequest ): ResponseEntity> { - themeService.updateTheme(id, themeUpdateRequest) + themeService.updateTheme(id, request) return ResponseEntity.ok().build() } -} - -@RestController -class StoreAdminController( - private val themeService: ThemeService -) : StoreAdminThemeAPI { @GetMapping("/admin/themes/active") - override fun findActiveThemes(): ResponseEntity> { + override fun getActiveThemes(): ResponseEntity> { val response = themeService.findActiveThemes() return ResponseEntity.ok(CommonApiResponse(response)) diff --git a/src/main/kotlin/roomescape/theme/web/AdminThemeDto.kt b/src/main/kotlin/roomescape/theme/web/AdminThemeDto.kt index ef6d0cf2..9b6be3ac 100644 --- a/src/main/kotlin/roomescape/theme/web/AdminThemeDto.kt +++ b/src/main/kotlin/roomescape/theme/web/AdminThemeDto.kt @@ -1,18 +1,8 @@ package roomescape.theme.web -import roomescape.common.dto.OperatorInfo +import roomescape.common.dto.AuditInfo import roomescape.theme.infrastructure.persistence.Difficulty import roomescape.theme.infrastructure.persistence.ThemeEntity -import java.time.LocalDateTime - -/** - * Theme API DTO - * - * Structure: - * - HQ Admin DTO: 본사 관리자가 사용하는 테마 관련 DTO들 - * - Store Admin DTO: 매장 관리자가 사용하는 테마 관련 DTO들 - */ - // ======================================== // HQ Admin DTO (본사) @@ -103,48 +93,21 @@ fun List.toAdminThemeSummaryListResponse() = AdminThemeSummaryListR ) data class AdminThemeDetailResponse( - val id: Long, - val name: String, - val description: String, - val thumbnailUrl: String, - val difficulty: Difficulty, - val price: Int, - val minParticipants: Short, - val maxParticipants: Short, - val availableMinutes: Short, - val expectedMinutesFrom: Short, - val expectedMinutesTo: Short, + val theme: ThemeInfoResponse, val isActive: Boolean, - val createdAt: LocalDateTime, - val createdBy: OperatorInfo, - val updatedAt: LocalDateTime, - val updatedBy: OperatorInfo, + val audit: AuditInfo ) -fun ThemeEntity.toAdminThemeDetailResponse(createdBy: OperatorInfo, updatedBy: OperatorInfo) = +fun ThemeEntity.toAdminThemeDetailResponse(audit: AuditInfo) = AdminThemeDetailResponse( - id = this.id, - name = this.name, - description = this.description, - thumbnailUrl = this.thumbnailUrl, - difficulty = this.difficulty, - price = this.price, - minParticipants = this.minParticipants, - maxParticipants = this.maxParticipants, - availableMinutes = this.availableMinutes, - expectedMinutesFrom = this.expectedMinutesFrom, - expectedMinutesTo = this.expectedMinutesTo, + theme = this.toInfoResponse(), isActive = this.isActive, - createdAt = this.createdAt, - createdBy = createdBy, - updatedAt = this.updatedAt, - updatedBy = updatedBy + audit = audit ) // ======================================== // Store Admin DTO // ======================================== - data class SimpleActiveThemeResponse( val id: Long, val name: String diff --git a/src/main/kotlin/roomescape/theme/web/PublicThemeDto.kt b/src/main/kotlin/roomescape/theme/web/ThemeDto.kt similarity index 100% rename from src/main/kotlin/roomescape/theme/web/PublicThemeDto.kt rename to src/main/kotlin/roomescape/theme/web/ThemeDto.kt