package kr.co.vividnext.sodalive.notice import kr.co.vividnext.sodalive.common.ApiResponse import org.springframework.data.domain.Pageable 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.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/notice") class ServiceNoticeController(private val service: ServiceNoticeService) { @PostMapping @PreAuthorize("hasRole('ADMIN')") fun createNotice(@RequestBody request: CreateNoticeRequest) = ApiResponse.ok( service.save(request), "등록되었습니다." ) @PutMapping @PreAuthorize("hasRole('ADMIN')") fun updateNotice(@RequestBody request: UpdateNoticeRequest) = ApiResponse.ok( service.update(request), "수정되었습니다." ) @DeleteMapping("/{id}") @PreAuthorize("hasRole('ADMIN')") fun deleteCan(@PathVariable id: Long) = ApiResponse.ok(service.delete(id), "삭제되었습니다.") @GetMapping fun getNoticeList(pageable: Pageable, timezone: String) = ApiResponse.ok(service.getNoticeList(pageable, timezone)) }