61 lines
2.1 KiB
Kotlin

package roomescape.theme.web
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import roomescape.common.dto.response.CommonApiResponse
import roomescape.theme.business.ThemeServiceV2
import roomescape.theme.docs.ThemeAPIV2
import java.net.URI
@RestController
class ThemeControllerV2(
private val themeService: ThemeServiceV2,
) : ThemeAPIV2 {
@GetMapping("/v2/themes")
override fun findUserThemes(): ResponseEntity<CommonApiResponse<ThemeRetrieveListResponseV2>> {
val response = themeService.findThemesForReservation()
return ResponseEntity.ok(CommonApiResponse(response))
}
@GetMapping("/admin/themes")
override fun findAdminThemes(): ResponseEntity<CommonApiResponse<AdminThemeSummaryRetrieveListResponse>> {
val response = themeService.findAdminThemes()
return ResponseEntity.ok(CommonApiResponse(response))
}
@GetMapping("/admin/themes/{id}")
override fun findAdminThemeDetail(@PathVariable id: Long): ResponseEntity<CommonApiResponse<AdminThemeDetailRetrieveResponse>> {
val response = themeService.findAdminThemeDetail(id)
return ResponseEntity.ok(CommonApiResponse(response))
}
@PostMapping("/admin/themes")
override fun createTheme(themeCreateRequestV2: ThemeCreateRequestV2): ResponseEntity<CommonApiResponse<ThemeCreateResponseV2>> {
val response = themeService.createTheme(themeCreateRequestV2)
return ResponseEntity.created(URI.create("/admin/themes/${response.id}"))
.body(CommonApiResponse(response))
}
@DeleteMapping("/admin/themes/{id}")
override fun deleteTheme(@PathVariable id: Long): ResponseEntity<CommonApiResponse<Unit>> {
themeService.deleteTheme(id)
return ResponseEntity.noContent().build()
}
@PatchMapping("/admin/themes/{id}")
override fun updateTheme(
@PathVariable id: Long,
themeUpdateRequest: ThemeUpdateRequest
): ResponseEntity<CommonApiResponse<Unit>> {
themeService.updateTheme(id, themeUpdateRequest)
return ResponseEntity.ok().build()
}
}