package roomescape.theme.web import io.swagger.v3.oas.annotations.Parameter 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.ThemeAPI import java.net.URI @RestController class ThemeController( private val themeService: ThemeService ) : ThemeAPI { @GetMapping("/themes") override fun findThemes(): ResponseEntity> { val response: ThemeRetrieveListResponse = themeService.findThemes() return ResponseEntity.ok(CommonApiResponse(response)) } @GetMapping("/themes/most-reserved-last-week") override fun findMostReservedThemes( @RequestParam(defaultValue = "10") @Parameter(description = "최대로 조회할 테마 갯수") count: Int ): ResponseEntity> { val response: ThemeRetrieveListResponse = themeService.findMostReservedThemes(count) return ResponseEntity.ok(CommonApiResponse(response)) } @PostMapping("/themes") override fun createTheme( @RequestBody @Valid request: ThemeCreateRequest ): ResponseEntity> { val themeResponse: ThemeCreateResponse = themeService.createTheme(request) return ResponseEntity.created(URI.create("/themes/${themeResponse.id}")) .body(CommonApiResponse(themeResponse)) } @DeleteMapping("/themes/{id}") override fun deleteTheme( @PathVariable id: Long ): ResponseEntity> { themeService.deleteTheme(id) return ResponseEntity.noContent().build() } }