Skip to content

Commit

Permalink
fix: ncp 관련 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
EunjiShin committed Jul 16, 2024
1 parent 1802095 commit 0cf3fae
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 48 deletions.
5 changes: 2 additions & 3 deletions infrastructure/jpa/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ dependencies {
// spring
implementation("org.springframework.boot:spring-boot-starter-data-jpa:_")

runtimeOnly("com.mysql:mysql-connector-j")

// queryDSL
implementation("com.querydsl:querydsl-jpa:_:jakarta")
annotationProcessor("com.querydsl:querydsl-apt:_:jakarta")
Expand All @@ -13,9 +15,6 @@ dependencies {

// p6spy
implementation("com.github.gavlyukovskiy:p6spy-spring-boot-starter:_")

// h2 - DB (또는 도커) 세팅 후 사라질 예정,,
runtimeOnly("com.h2database:h2")
}

tasks.bootJar { enabled = false }
Expand Down
49 changes: 30 additions & 19 deletions infrastructure/jpa/src/main/resources/application-jpa.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:spot
username: sa
password:
datasource:
url: jdbc:mysql://mysql:3306/spot
username: test1234
password: test1234
driver-class-name: com.mysql.cj.jdbc.Driver

jpa:
database: h2
hibernate:
ddl-auto: create
database-platform: org.hibernate.dialect.H2Dialect
open-in-view: false
defer-datasource-initialization: true
jpa:
database: mysql
database-platform: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: update # 주의: 프로덕션 환경에서는 'validate' 사용 권장
properties:
hibernate:
use_sql_comments: true
defer-datasource-initialization: true

h2:
console:
enabled: true
path: /h2-console
sql:
init:
mode: never # 필요한 경우 'never'로 변경

server:
port: 8080

logging:
level:
org.hibernate.SQL: DEBUG
org.hibernate.type.descriptor.sql.BasicBinder: TRACE

decorator:
datasource:
p6spy:
enable-logging: true
datasource:
p6spy:
enable-logging: true

# 필요한 경우 추가 설정
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
public class ObjectStorageConfig {

private final ObjectStorageProperties objectStorageProperties;
private static final String ENDPOINT = "https://kr.object.ncloudstorage.com";
private static final String REGION = "kr-standard";

@Bean
public AmazonS3 getAmazonS3() {
return AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(
new EndpointConfiguration(
objectStorageProperties.endPoint(),
objectStorageProperties.region()))
.withEndpointConfiguration(new EndpointConfiguration(ENDPOINT, REGION))
.withCredentials(
new AWSStaticCredentialsProvider(
new BasicAWSCredentials(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@ public class FileNameGenerator {

private final TimeUsecase timeUsecase;

public String createReviewFileName(final Long userId, final ImageExtension fileExtension) {
public String createReviewFileName(
final Long userId, final ImageExtension fileExtension, final String folderName) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(folderName)
.append("/")
.append(MediaProperty.REVIEW)
.append("/user/")
.append("_user_")
.append(userId)
.append("/")
.append("_")
.append(timeUsecase.getNow())
.append("/")
.append(".")
.append(fileExtension.getValue());
return stringBuilder.toString();
}

public String createStadiumFileName(final StadiumSeatMediaExtension fileExtension) {
public String createStadiumFileName(
final StadiumSeatMediaExtension fileExtension, final String folderName) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(MediaProperty.STADIUM)
.append(folderName)
.append("/")
.append(MediaProperty.STADIUM)
.append("_")
.append(timeUsecase.getNow())
.append("/")
.append(".")
.append(fileExtension.getValue());
return stringBuilder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ public class PresignedUrlGenerator implements CreatePresignedUrlPort {
private final ReviewStorageProperties reviewStorageProperties;
private final StadiumStorageProperties stadiumStorageProperties;

private static final long EXPIRE_MS = 1000 * 60 * 2L;
private static final long EXPIRE_MS = 1000 * 60 * 5L;

@Override
public String forReview(final Long userId, PresignedUrlRequest request) {
isValidReviewMedia(request.getProperty(), request.getFileExtension());

final ImageExtension fileExtension = ImageExtension.from(request.getFileExtension());
final String fileName = fileNameGenerator.createReviewFileName(userId, fileExtension);
final String folderName = reviewStorageProperties.folderName();
final String fileName =
fileNameGenerator.createReviewFileName(userId, fileExtension, folderName);
final URL url = createPresignedUrl(reviewStorageProperties.bucketName(), fileName);

return url.toString();
Expand All @@ -63,7 +65,8 @@ public String forStadiumSeat(PresignedUrlRequest request) {

final StadiumSeatMediaExtension fileExtension =
StadiumSeatMediaExtension.from(request.getFileExtension());
final String fileName = fileNameGenerator.createStadiumFileName(fileExtension);
final String folderName = stadiumStorageProperties.folderName();
final String fileName = fileNameGenerator.createStadiumFileName(fileExtension, folderName);
final URL url = createPresignedUrl(stadiumStorageProperties.bucketName(), fileName);

return url.toString();
Expand All @@ -89,7 +92,6 @@ private GeneratePresignedUrlRequest createGeneratePreSignedUrlRequest(
GeneratePresignedUrlRequest generatePresignedUrlRequest =
new GeneratePresignedUrlRequest(bucket, fileName)
.withMethod(HttpMethod.PUT)
.withKey(fileName)
.withExpiration(createPreSignedUrlExpiration());

generatePresignedUrlRequest.addRequestParameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import org.springframework.boot.context.properties.ConfigurationProperties;

// FIXME: ncp 세팅 완료 후, applicaiton.yml 참고해서 prefix 추가
@ConfigurationProperties(prefix = "object-storage")
@ConfigurationProperties(prefix = "ncp.object-storage")
public record ObjectStorageProperties(
String accessKey, String secretKey, String region, String endPoint) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.springframework.boot.context.properties.ConfigurationProperties;

// FIXME: ncp 세팅 완료 후, applicaiton.yml 참고해서 prefix 추가
@ConfigurationProperties(prefix = "review-storage")
@ConfigurationProperties(prefix = "ncp.review-storage")
public record ReviewStorageProperties(String bucketName, String folderName) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.springframework.boot.context.properties.ConfigurationProperties;

// FIXME: ncp 세팅 완료 후, applicaiton.yml 참고해서 prefix 추가
@ConfigurationProperties(prefix = "stadium-storage")
@ConfigurationProperties(prefix = "ncp.stadium-storage")
public record StadiumStorageProperties(String bucketName, String folderName) {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
ncp:
object-storage:
access-key: ${NCP_OBJECT_STORAGE_ACCESS_KEY}
secret-key: ${NCP_OBJECT_STORAGE_SECRET_KEY}
region: kr-standard
end-point: https://kr.object.ncloudstorage.com
accessKey: ${NCP_OBJECT_STORAGE_ACCESS_KEY}
secretKey: ${NCP_OBJECT_STORAGE_SECRET_KEY}
review-storage:
bucket-name: spot-image-bucket
folder-name: review-images
bucketName: "spot-image-bucket"
folderName: "review-images"
stadium-storage:
bucket-name: spot-image-bucket
folder-name: stadium-images
bucketName: "spot-image-bucket"
folderName: "stadium-images"

0 comments on commit 0cf3fae

Please sign in to comment.