From 3e4f26fe1eea67223c735e546623385fbd4a7ca2 Mon Sep 17 00:00:00 2001 From: ikjunoh Date: Wed, 31 Jul 2024 17:15:38 +0900 Subject: [PATCH] =?UTF-8?q?chore=20:=20jpa=20=EC=9D=98=EC=A1=B4=EC=84=B1?= =?UTF-8?q?=20=EC=84=A4=EC=B9=98=20=ED=9B=84=20=EA=B0=84=EB=8B=A8=ED=95=9C?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20(CC-83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + build.gradle | 8 ++++++ .../java/ai/softeer/caecae/S3Controller.java | 2 +- .../caecae/global/config/S3Config.java | 2 +- .../caecae/global/utils/S3Service.java | 5 ++-- .../caecae/user/domain/entity/User.java | 17 +++++++++++++ src/main/resources/application-dev.yml | 1 + src/main/resources/application-prod.yml | 6 +++++ src/main/resources/application.yml | 23 ++++++++++++++--- .../caecae/CaecaeApplicationTests.java | 25 +++++++++---------- 10 files changed, 69 insertions(+), 21 deletions(-) create mode 100644 src/main/java/ai/softeer/caecae/user/domain/entity/User.java create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application-prod.yml diff --git a/.gitignore b/.gitignore index d116d18..325468d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ HELP.md +.DS_Store .gradle build/ !gradle/wrapper/gradle-wrapper.jar diff --git a/build.gradle b/build.gradle index 5f85e5e..cdb77cf 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,14 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + // DB + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + runtimeOnly 'com.mysql:mysql-connector-j' + + // AWS Parameter Store + implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.1.0") + implementation 'io.awspring.cloud:spring-cloud-aws-starter-parameter-store' + // AWS SDK for S3 implementation 'com.amazonaws:aws-java-sdk-s3:1.12.503' diff --git a/src/main/java/ai/softeer/caecae/S3Controller.java b/src/main/java/ai/softeer/caecae/S3Controller.java index 821cd4f..6833827 100644 --- a/src/main/java/ai/softeer/caecae/S3Controller.java +++ b/src/main/java/ai/softeer/caecae/S3Controller.java @@ -12,7 +12,7 @@ public class S3Controller { private final S3Service s3Service; - @PostMapping("api/s3") + @PostMapping("/api/s3") public String upload(@RequestParam("file") MultipartFile file) { String filePath = s3Service.uploadFile(file); return filePath +"created!"; diff --git a/src/main/java/ai/softeer/caecae/global/config/S3Config.java b/src/main/java/ai/softeer/caecae/global/config/S3Config.java index 6d78437..fd2b11a 100644 --- a/src/main/java/ai/softeer/caecae/global/config/S3Config.java +++ b/src/main/java/ai/softeer/caecae/global/config/S3Config.java @@ -12,7 +12,7 @@ @RequiredArgsConstructor public class S3Config { - @Value("${cloud.aws.region.static}") + @Value("${spring.region.static}") private String region; @Bean diff --git a/src/main/java/ai/softeer/caecae/global/utils/S3Service.java b/src/main/java/ai/softeer/caecae/global/utils/S3Service.java index 69a4595..2177b9b 100644 --- a/src/main/java/ai/softeer/caecae/global/utils/S3Service.java +++ b/src/main/java/ai/softeer/caecae/global/utils/S3Service.java @@ -21,7 +21,7 @@ public class S3Service { private final AmazonS3 amazonS3; - @Value("${cloud.aws.s3.bucket}") + @Value("${spring.s3.bucket}") private String bucket; /** @@ -38,8 +38,7 @@ public String uploadFile(MultipartFile file) { String filePath; // 파일 업로드 try (InputStream inputStream = file.getInputStream()) { - amazonS3.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata) - .withCannedAcl(CannedAccessControlList.PublicRead)); + amazonS3.putObject(new PutObjectRequest(bucket, fileName, inputStream, objectMetadata)); // 올린 오브젝트에 대한 s3 url filePath = amazonS3.getUrl(bucket, fileName).toString(); } catch (IOException e) { diff --git a/src/main/java/ai/softeer/caecae/user/domain/entity/User.java b/src/main/java/ai/softeer/caecae/user/domain/entity/User.java new file mode 100644 index 0000000..5683eef --- /dev/null +++ b/src/main/java/ai/softeer/caecae/user/domain/entity/User.java @@ -0,0 +1,17 @@ +package ai.softeer.caecae.user.domain.entity; + + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private Integer phone; +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..4287ca8 --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..9982393 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,6 @@ +config: + type: aws-parameterstore:/config/caecae/ + +spring: + config: + import: ${config.type} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 532b17b..7327f1e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,21 @@ spring: - profiles: - include: - - s3 + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + url: ${DB_URL} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + + jpa: + hibernate: + ddl-auto: create + properties: + hibernate: + show_sql: true + format_sql: true + database-platform: org.hibernate.dialect.MySQLDialect + open-in-view: false + + s3: + bucket: ${S3_BUCKET} + region: + static: ${REGION} \ No newline at end of file diff --git a/src/test/java/ai/softeer/caecae/CaecaeApplicationTests.java b/src/test/java/ai/softeer/caecae/CaecaeApplicationTests.java index 6c89729..0ad7d26 100644 --- a/src/test/java/ai/softeer/caecae/CaecaeApplicationTests.java +++ b/src/test/java/ai/softeer/caecae/CaecaeApplicationTests.java @@ -1,13 +1,12 @@ -//package ai.softeer.caecae; -// -//import org.junit.jupiter.api.Test; -//import org.springframework.boot.test.context.SpringBootTest; -// -//@SpringBootTest -//class CaecaeApplicationTests { -// -// @Test -// void contextLoads() { -// } -// -//} +package ai.softeer.caecae; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +class CaecaeApplicationTests { + + @Test + void contextLoads() { + } + +}