Skip to content

Commit

Permalink
chore : jpa 의존성 설치 후 간단한 테스트 (CC-83)
Browse files Browse the repository at this point in the history
  • Loading branch information
putdata committed Jul 31, 2024
1 parent 375d6c6 commit 3e4f26f
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
HELP.md
.DS_Store
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ai/softeer/caecae/S3Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@RequiredArgsConstructor
public class S3Config {

@Value("${cloud.aws.region.static}")
@Value("${spring.region.static}")
private String region;

@Bean
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/ai/softeer/caecae/global/utils/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class S3Service {
private final AmazonS3 amazonS3;

@Value("${cloud.aws.s3.bucket}")
@Value("${spring.s3.bucket}")
private String bucket;

/**
Expand All @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/ai/softeer/caecae/user/domain/entity/User.java
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
6 changes: 6 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config:
type: aws-parameterstore:/config/caecae/

spring:
config:
import: ${config.type}
23 changes: 20 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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}
25 changes: 12 additions & 13 deletions src/test/java/ai/softeer/caecae/CaecaeApplicationTests.java
Original file line number Diff line number Diff line change
@@ -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() {
}

}

0 comments on commit 3e4f26f

Please sign in to comment.