[ADD] MinIO 파일 삭제 로직 추가 및 컨트롤러 설명 수정

main
bjkim 9 months ago
parent ba5dde3281
commit 01f92b25bc

@ -79,7 +79,7 @@ public class MinioAttachmentController {
return ResponseEntity.ok(page);
}
@Operation(summary = "첨부파일 삭제")
@Operation(summary = "첨부파일 삭제 (MinIO 포함)")
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(
@Parameter(description = "첨부파일 ID", required = true)

@ -2,6 +2,7 @@ package kr.re.etri.autoflow.service;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.RemoveObjectArgs;
import jakarta.transaction.Transactional;
import kr.re.etri.autoflow.entity.MinioAttachmentEntity;
import kr.re.etri.autoflow.payload.request.BaseSearchRequest;
@ -229,12 +230,31 @@ public class MinioAttachmentService {
/**
*
*/
@Transactional
public boolean delete(Long id) {
if (!minioAttachmentRepository.existsById(id)) {
Optional<MinioAttachmentEntity> attachmentOpt = minioAttachmentRepository.findById(id);
if (attachmentOpt.isEmpty()) {
return false;
}
MinioAttachmentEntity attachment = attachmentOpt.get();
try {
// MinIO 파일 삭제
minioClient.removeObject(
RemoveObjectArgs.builder()
.bucket(bucketName)
.object(attachment.getStoragePath())
.build()
);
// DB에서 삭제
minioAttachmentRepository.deleteById(id);
return true;
} catch (Exception e) {
log.error("MinIO 파일 삭제 실패: " + attachment.getStoragePath(), e);
return false;
}
}
/**

Loading…
Cancel
Save