728x90
이슈 수정
Controller
@PutMapping("/{id}")
fun edit(
authUser: AuthUser,
@PathVariable id: Long,
@RequestBody request: IssueRequest,
) = issueService.edit(authUser.userId, id, request)
Service
@Transactional
fun edit(userId: Long, id: Long, request: IssueRequest): IssueResponse {
val issue = issueRepository.findByIdOrNull(id) ?: throw NotFoundException("이슈가 존재하지 않습니다.")
return with(issue) {
summary = request.summary
description = request.description
this.userId = userId
type = request.type
priority = request.priority
status = request.status
IssueResponse(issueRepository.save(this))
}
}
- 변경 감지 기능을 사용해서, 수정할 수도 있지만 직접적으로 변수를 수정해서 save를 호출할 수도 있다
이슈 삭제
Controller
@DeleteMapping("/{id}")
@ResponseStatus(NO_CONTENT)
fun delete(
authUser: AuthUser,
@PathVariable id: Long,
) {
issueService.delete(id)
}
- @ResponseStatus 어노테이션을 통해 응답할 status 값과, 아무런 컨텐츠도 내려주지 않게 동작할 수 있다.
Service
@Transactional
fun delete(id: Long) {
issueRepository.deleteById(id)
}
728x90
'실무 프로젝트로 배우는 Kotlin & Spring > 이슈 관리 서비스 개발하기' 카테고리의 다른 글
| 코멘트 수정/ 코멘트 삭제 (0) | 2022.11.27 |
|---|---|
| 코멘트 등록 (0) | 2022.11.27 |
| 이슈 목록 조회/ 이슈 상세 조회 (0) | 2022.11.27 |
| 이슈 등록 (0) | 2022.11.27 |
| 공통 에러 처리 (0) | 2022.11.26 |