Create S3Client bean
This commit is contained in:
7
.env.example
Normal file
7
.env.example
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
DATABASE_URL=jdbc:postgresql://postgres:5432/db
|
||||||
|
DATABASE_PASSWORD=password
|
||||||
|
DATABASE_USERNAME=user
|
||||||
|
|
||||||
|
S3_ENDPOINT=http://s3:9000
|
||||||
|
S3_ACCESS_KEY=minioadmin
|
||||||
|
S3_SECRET_KEY=minioadmin
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -31,3 +31,5 @@ build/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
.env
|
||||||
|
|||||||
7
pom.xml
7
pom.xml
@ -31,6 +31,7 @@
|
|||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
|
|
||||||
<modelmapper.version>3.2.4</modelmapper.version>
|
<modelmapper.version>3.2.4</modelmapper.version>
|
||||||
|
<spring-dotenv.version>4.0.0</spring-dotenv.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -81,6 +82,12 @@
|
|||||||
<artifactId>s3</artifactId>
|
<artifactId>s3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.paulschwarz</groupId>
|
||||||
|
<artifactId>spring-dotenv</artifactId>
|
||||||
|
<version>${spring-dotenv.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
|
|||||||
@ -0,0 +1,31 @@
|
|||||||
|
package com.bivashy.backend.composer.config;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
|
||||||
|
import software.amazon.awssdk.regions.Region;
|
||||||
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class StorageS3Config {
|
||||||
|
@Value("${spring.s3.endpoint}")
|
||||||
|
private String endpoint;
|
||||||
|
@Value("${spring.s3.access-key}")
|
||||||
|
private String accessKey;
|
||||||
|
@Value("${spring.s3.secret-key}")
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public S3Client s3Client() {
|
||||||
|
return S3Client.builder()
|
||||||
|
.endpointOverride(URI.create(endpoint))
|
||||||
|
.region(Region.US_WEST_1)
|
||||||
|
.credentialsProvider(() -> AwsBasicCredentials.create(accessKey, secretKey))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package com.bivashy.backend.composer.dto;
|
||||||
|
|
||||||
|
public class ErrorResponse {
|
||||||
|
private final int status;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
public ErrorResponse(int status, String message) {
|
||||||
|
this.status = status;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package com.bivashy.backend.composer.exception;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
|
||||||
|
import com.bivashy.backend.composer.dto.ErrorResponse;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||||
|
|
||||||
|
@ExceptionHandler(DataIntegrityViolationException.class)
|
||||||
|
public ResponseEntity<ErrorResponse> handleDataIntegrityViolation(DataIntegrityViolationException ex) {
|
||||||
|
ErrorResponse error = new ErrorResponse(
|
||||||
|
HttpStatus.CONFLICT.value(),
|
||||||
|
"Conflict: " + ex.getMostSpecificCause().getMessage());
|
||||||
|
logger.error("SQL create conflict", ex);
|
||||||
|
return ResponseEntity.status(HttpStatus.CONFLICT).body(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,9 +3,14 @@ spring:
|
|||||||
name: composer
|
name: composer
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
password: password
|
username: ${DATABASE_USERNAME}
|
||||||
url: jdbc:postgresql://postgres:5432/db
|
password: ${DATABASE_PASSWORD}
|
||||||
username: user
|
url: ${DATABASE_URL}
|
||||||
|
s3:
|
||||||
|
endpoint: ${S3_ENDPOINT}
|
||||||
|
access-key: ${S3_ACCESS_KEY}
|
||||||
|
secret-key: ${S3_SECRET_KEY}
|
||||||
|
bucket: ${S3_BUCKET}
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
|
|||||||
Reference in New Issue
Block a user