created call api in 2 steps

This commit is contained in:
rajesh
2024-08-26 11:44:52 +05:30
parent b6692e206d
commit 1b9ddc30fa
23 changed files with 254 additions and 126 deletions

View File

@@ -1,5 +1,16 @@
package net.gepafin.tendermanagement.dao;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.DocumentEntity;
@@ -10,17 +21,6 @@ import net.gepafin.tendermanagement.service.AmazonS3Service;
import net.gepafin.tendermanagement.util.Utils;
import net.gepafin.tendermanagement.web.rest.api.errors.ResourceNotFoundException;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class DocumentDao {
@@ -34,15 +34,6 @@ public class DocumentDao {
@Autowired
private CallDao callDao;
@Value("${aws.s3.bucket.name}")
private String bucketName;
@Value("${aws.s3.url.folder}")
private String s3Folder;
@Value("${aws.s3.url}")
private String s3Url;
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, DocumentTypeEnum fileType) {
List<DocumentEntity> documentEntities = new ArrayList<>();
@@ -65,16 +56,15 @@ public class DocumentDao {
.map(callDao::convertToDocumentResponseBean)
.collect(Collectors.toList());
}
public Void deleteFile(Long documentId){
DocumentEntity documentEntity= documentRepository.findById(documentId);
if(documentEntity==null){
new ResourceNotFoundException(Status.VALIDATION_ERROR, Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND));
}
String fileName= Utils.extractFileName(documentEntity.getFilePath());
try {
amazonS3Service.delete(bucketName, fileName);
documentRepository.delete(documentEntity);
}catch (Exception e){}
return null;
}
public void deleteFile(Long documentId) {
DocumentEntity documentEntity = documentRepository.findById(documentId)
.orElseThrow(() -> new ResourceNotFoundException(Status.VALIDATION_ERROR,
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
String fileName = Utils.extractFileName(documentEntity.getFilePath());
amazonS3Service.delete(fileName);
documentRepository.delete(documentEntity);
}
}