diff --git a/src/main/java/capstone/bookdiary/controller/ImageController.java b/src/main/java/capstone/bookdiary/controller/ImageController.java index f6651f3..07e9097 100644 --- a/src/main/java/capstone/bookdiary/controller/ImageController.java +++ b/src/main/java/capstone/bookdiary/controller/ImageController.java @@ -8,6 +8,8 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -27,4 +29,11 @@ private ResponseEntity> generateImage(@Valid @RequestBody Im .ok() .body(imageService.generateImage(imageRequestDto)); } + @DeleteMapping("/image/{imageId}") + @Operation(summary = "이미지 삭제", description = "해당 스크랩의 이미지를 삭제합니다.") + private ResponseEntity> deleteImage(@PathVariable Long imageId){ + return ResponseEntity + .ok() + .body(imageService.deleteImage(imageId)); + }; } diff --git a/src/main/java/capstone/bookdiary/service/ImageService.java b/src/main/java/capstone/bookdiary/service/ImageService.java index a7cd256..819d258 100644 --- a/src/main/java/capstone/bookdiary/service/ImageService.java +++ b/src/main/java/capstone/bookdiary/service/ImageService.java @@ -14,6 +14,7 @@ import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -48,4 +49,15 @@ public Map generateImage(ImageRequestDto imageRequestDto) { return response; } } + + @Transactional + public Map deleteImage(Long imageId) { + Image image = imageRepository.findById(imageId) + .orElseThrow(DataNotFoundException::new); + imageRepository.delete(image); + + Map response = new HashMap<>(); + response.put("delete", "ok"); + return response; + } }