Browse Source

feat : file 코드 옮기기

feature/renewal/common
qkr7828 7 months ago
parent
commit
38edd568a3
  1. 32
      app/kac-app/src/main/java/kr/co/palnet/kac/app/config/FileConfig.java
  2. 40
      app/kac-app/src/main/resources/application.properties
  3. 79
      web/api-common/src/main/java/kr/co/palnet/kac/api/v1/common/file/controller/ComFileController.java
  4. 87
      web/api-common/src/main/java/kr/co/palnet/kac/api/v1/common/file/service/ComFileService.java

32
app/kac-app/src/main/java/kr/co/palnet/kac/app/config/FileConfig.java

@ -0,0 +1,32 @@
package kr.co.palnet.kac.app.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
@Configuration
public class FileConfig {
@Value("${cloud.aws.credentials.accessKey}")
private String accessKey;
@Value("${cloud.aws.credentials.secretKey}")
private String accessSecret;
@Value("${cloud.aws.region.static}")
private String region;
@Bean
public AmazonS3 s3Client() {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, accessSecret);
return AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region).build();
}
}

40
app/kac-app/src/main/resources/application.properties

@ -0,0 +1,40 @@
###### GP 데이터 데이터 저장 설정 #######
gp.remove.time = 5
gp.insert.count = 1000
gp.end.time= 1
####### Naver 주소변화 API 값 #############
naver.api.id=5md90yszqj
naver.api.key=uCJci6Ixm4DN7hUGtSrjKh6NU6z0SOKq9idpkLat
naver.api.url=https://naveropenapi.apigw.ntruss.com/map-reversegeocode/v2/gc
### 일출/일몰 ###
external.sunriseset.url=http://apis.data.go.kr/B090041/openapi/service/RiseSetInfoService
#external.sunriseset.key=b%2FStm6AMT3EwXc5kOvwnjK%2FPB57Ay1WzkIGVx5WaMt0MyRt3TEPgcJ%2Fur45GrnVOZKs2sfIWKUX3BTl8eYwVFw%3D%3D
#external.sunriseset.key=b/Stm6AMT3EwXc5kOvwnjK/PB57Ay1WzkIGVx5WaMt0MyRt3TEPgcJ/ur45GrnVOZKs2sfIWKUX3BTl8eYwVFw==
external.sunriseset.key=r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D
#external.sunriseset.key=r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4/45y0uVNw6BaYbgpKmL+LUDFVTfIYUmEe4K/aniEjdV9mg5t82Q==
### TS ###
external.ts.url=http://121.137.95.45:8170
external.ts.return.uri=/api/external/laanc/vc/callback
### Token key ######
spring.jwt.secret=jwtsecretkey
spring.jwt.prefix=palnet
### Weather key ###
weather.api.url = http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst
weather.api.key = =r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D
### AWS S3 ####
#cloud.aws.credentials.accessKey=AKIAW75VMZKFTMBRXK4I
cloud.aws.credentials.accessKey=AKIAW75VMZKFTMBRXK4I
cloud.aws.credentials.secretKey=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
cloud.aws.stack.auto=false
cloud.aws.s3.bucket=palnet-file
cloud.aws.region.static=ap-northeast-2
cloud.aws.s3.bucket.url=https://s3.ap-northeast-2.amazonaws.com/palnet-file

79
web/api-common/src/main/java/kr/co/palnet/kac/api/v1/common/file/controller/ComFileController.java

@ -0,0 +1,79 @@
//package kr.co.palnet.kac.api.v1.common.file.controller;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.io.ByteArrayResource;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.DeleteMapping;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.Parameter;
//import io.swagger.v3.oas.annotations.enums.ParameterIn;
//import io.swagger.v3.oas.annotations.media.Content;
//import io.swagger.v3.oas.annotations.tags.Tag;
//import kr.co.palnet.kac.api.v1.common.file.service.ComFileService;
//import lombok.RequiredArgsConstructor;
//
//@RestController
//@RequiredArgsConstructor
//@RequestMapping("/v1/com/file")
//@Tag(name = "file", description = "파일데이터 관련 API")
//public class ComFileController {
//
// private final ComFileService service;
//
// /**
// * 파일 업로드 기능
// * @param file
// * @return
// */
// @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
// @Operation(summary = "파일업로드")
// public ResponseEntity<String> uploadFile(
// @Parameter(
// description = "multipart/form-data 형식의 파일데이터를 input으로 받습니다. 이때 key 값은 file 입니다.",
// content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE)
// )@RequestParam(value = "file") MultipartFile file
// ) {
// return new ResponseEntity<>(service.uploadFile(file), HttpStatus.OK);
// }
//
// /**
// * 파일 다운로드 기능.
// * @param fileName
// * @return
// */
// @GetMapping("/download/{fileName}")
// @Operation(summary = "파일다운로드")
// @Parameter(name="fileName", description = "파일 명", in = ParameterIn.PATH, example = "파일명")
// public ResponseEntity<ByteArrayResource> downloadFile(@PathVariable String fileName) {
// byte[] data = service.downloadFile(fileName);
// ByteArrayResource resource = new ByteArrayResource(data);
// return ResponseEntity
// .ok()
// .contentLength(data.length)
// .header("Content-type", "application/octet-stream")
// .header("Content-disposition", "attachment; filename=\"" + fileName + "\"")
// .body(resource);
// }
//
// /**
// * 파일 삭제 기능.
// * @param fileName
// * @return
// */
// @DeleteMapping("/delete/{fileName}")
// @Operation(summary = "파일삭제")
// @Parameter(name="fileName", description = "파일 명", in = ParameterIn.PATH, example = "파일명")
// public ResponseEntity<String> deleteFile(@PathVariable String fileName) {
// return new ResponseEntity<>(service.deleteFile(fileName), HttpStatus.OK);
// }
//}

87
web/api-common/src/main/java/kr/co/palnet/kac/api/v1/common/file/service/ComFileService.java

@ -0,0 +1,87 @@
//package kr.co.palnet.kac.api.v1.common.file.service;
//
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//
//import org.apache.tomcat.util.http.fileupload.IOUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Service;
//import org.springframework.web.multipart.MultipartFile;
//
//import com.amazonaws.services.s3.AmazonS3;
//import com.amazonaws.services.s3.model.PutObjectRequest;
//import com.amazonaws.services.s3.model.S3Object;
//import com.amazonaws.services.s3.model.S3ObjectInputStream;
//
//import lombok.extern.slf4j.Slf4j;
//
//@Service
//@Slf4j
//public class ComFileService {
//
// @Value("${cloud.aws.s3.bucket}")
// private String bucketName;
//
// @Autowired
// private AmazonS3 s3Client;
//
// /**
// * 파일 업로드 기능.
// * @param file
// * @return
// */
// public String uploadFile(MultipartFile file) {
// File fileObj = convertMultiPartFileToFile(file);
// String fileName = System.currentTimeMillis() + "_" + file.getOriginalFilename();
// s3Client.putObject(new PutObjectRequest(bucketName, fileName, fileObj));
// fileObj.delete();
// return fileName;
// }
//
//
// /**
// * 파일 다운로드 기능. 아마존 S3에 있는 데이터 다운로드해주는 기능.
// * @param fileName
// * @return
// */
// public byte[] downloadFile(String fileName) {
// S3Object s3Object = s3Client.getObject(bucketName, fileName);
// S3ObjectInputStream inputStream = s3Object.getObjectContent();
// try {
// byte[] content = IOUtils.toByteArray(inputStream);
// return content;
// } catch (IOException e) {
// e.printStackTrace();
// }
// return null;
// }
//
//
// /**
// * 아마존 S3에 있는 데이터 삭제하는 기능.
// * @param fileName
// * @return
// */
// public String deleteFile(String fileName) {
// s3Client.deleteObject(bucketName, fileName);
// return fileName + " removed ...";
// }
//
//
// /**
// * MultipartFile로 받은 객체를 File 객체로 변환
// * @param file
// * @return
// */
// private File convertMultiPartFileToFile(MultipartFile file) {
// File convertedFile = new File(file.getOriginalFilename());
// try (FileOutputStream fos = new FileOutputStream(convertedFile)) {
// fos.write(file.getBytes());
// } catch (IOException e) {
// log.error("Error converting multipartFile to file", e);
// }
// return convertedFile;
// }
//}
Loading…
Cancel
Save