Files
sodalive-backend-spring-boot/src/main/kotlin/kr/co/vividnext/sodalive/event/EventController.kt
2023-08-06 22:18:45 +09:00

57 lines
2.5 KiB
Kotlin

package kr.co.vividnext.sodalive.event
import kr.co.vividnext.sodalive.common.ApiResponse
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
@RestController
@RequestMapping("/event")
class EventController(private val service: EventService) {
@GetMapping
fun getEventList() = ApiResponse.ok(service.getEventList())
@GetMapping("/popup")
fun getEventPopup() = ApiResponse.ok(service.getEventPopup())
@PostMapping
@PreAuthorize("hasRole('ADMIN')")
fun createEvent(
@RequestParam("thumbnail") thumbnail: MultipartFile,
@RequestParam(value = "detail", required = false) detail: MultipartFile? = null,
@RequestParam(value = "popup", required = false) popup: MultipartFile? = null,
@RequestParam(value = "link", required = false) link: String? = null,
@RequestParam(value = "title", required = false) title: String? = null,
@RequestParam(value = "isPopup") isPopup: Boolean
) = ApiResponse.ok(
service.save(thumbnail, detail, popup, link, title, isPopup),
"등록되었습니다."
)
@PutMapping
@PreAuthorize("hasRole('ADMIN')")
fun updateEvent(
@RequestParam(value = "id") id: Long,
@RequestParam(value = "thumbnail", required = false) thumbnail: MultipartFile? = null,
@RequestParam(value = "detail", required = false) detail: MultipartFile? = null,
@RequestParam(value = "popup", required = false) popup: MultipartFile? = null,
@RequestParam(value = "link", required = false) link: String? = null,
@RequestParam(value = "title", required = false) title: String? = null,
@RequestParam(value = "isPopup", required = false) isPopup: Boolean? = null
) = ApiResponse.ok(
service.update(id, thumbnail, detail, popup, link, title, isPopup),
"수정되었습니다."
)
@DeleteMapping("/{id}")
@PreAuthorize("hasRole('ADMIN')")
fun deleteEvent(@PathVariable id: Long) = ApiResponse.ok(service.delete(id), "삭제되었습니다.")
}