Skip to content

Commit

Permalink
feat: delete image
Browse files Browse the repository at this point in the history
  • Loading branch information
Relaxed-Mind committed Dec 12, 2023
1 parent 24437a1 commit 9a0d01e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,4 +29,11 @@ private ResponseEntity<Map<String, Object>> generateImage(@Valid @RequestBody Im
.ok()
.body(imageService.generateImage(imageRequestDto));
}
@DeleteMapping("/image/{imageId}")
@Operation(summary = "이미지 삭제", description = "해당 스크랩의 이미지를 삭제합니다.")
private ResponseEntity<Map<String, Object>> deleteImage(@PathVariable Long imageId){
return ResponseEntity
.ok()
.body(imageService.deleteImage(imageId));
};
}
12 changes: 12 additions & 0 deletions src/main/java/capstone/bookdiary/service/ImageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -48,4 +49,15 @@ public Map<String, Object> generateImage(ImageRequestDto imageRequestDto) {
return response;
}
}

@Transactional
public Map<String, Object> deleteImage(Long imageId) {
Image image = imageRepository.findById(imageId)
.orElseThrow(DataNotFoundException::new);
imageRepository.delete(image);

Map<String, Object> response = new HashMap<>();
response.put("delete", "ok");
return response;
}
}

0 comments on commit 9a0d01e

Please sign in to comment.