-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.env 파일은 환경변수 깃허브에 설정해 놓았습니다. 커밋하지 않았습니다.
- Loading branch information
1 parent
1400cd6
commit d29d402
Showing
7 changed files
with
164 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
BE/error/src/main/java/com/example/demo/config/EnvConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.demo.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.context.annotation.PropertySources; | ||
|
||
@Configuration | ||
@PropertySource("classpath:/.env") | ||
public class EnvConfig {} |
34 changes: 34 additions & 0 deletions
34
BE/error/src/main/java/com/example/demo/config/StorageConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.example.demo.config; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.regions.Regions; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@Configuration | ||
public class StorageConfig { | ||
|
||
@Value("${cloud.aws.credentials.accessKey}") | ||
private String accessKey; | ||
|
||
@Value("${SECRET_KEY}") | ||
private String secretKey; | ||
|
||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); | ||
|
||
return (AmazonS3Client) AmazonS3ClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | ||
.build(); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
BE/error/src/main/java/com/example/demo/image/application/service/ImageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.example.demo.image.application.service; | ||
|
||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.model.ListObjectsV2Request; | ||
import com.amazonaws.services.s3.model.ListObjectsV2Result; | ||
import com.amazonaws.services.s3.model.S3ObjectSummary; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class ImageService { | ||
|
||
private final AmazonS3Client amazonS3Client; | ||
|
||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucketName; | ||
|
||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
public List<Map<String, Object>> getFileList(String directory) { | ||
List<Map<String, Object>> fileList = new ArrayList<>(); | ||
|
||
ListObjectsV2Request listObjectsV2Request = new ListObjectsV2Request() | ||
.withBucketName(bucketName) | ||
.withPrefix(directory + "/"); | ||
|
||
ListObjectsV2Result result = amazonS3Client.listObjectsV2(listObjectsV2Request); | ||
List<S3ObjectSummary> objectSummaries = result.getObjectSummaries(); | ||
|
||
int id = 1; | ||
for (S3ObjectSummary objectSummary : objectSummaries) { | ||
String key = objectSummary.getKey(); | ||
if (!key.equals(directory + "/")) { | ||
Map<String, Object> fileInfo = new HashMap<>(); | ||
fileInfo.put("id", id++); | ||
fileInfo.put("url", "https://" + bucketName + ".s3." + region + ".amazonaws.com/" + key); | ||
fileList.add(fileInfo); | ||
} | ||
} | ||
|
||
Collections.shuffle(fileList); | ||
return fileList.size() > 16 ? fileList.subList(0, 16) : fileList; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
BE/error/src/main/java/com/example/demo/image/presentation/ImageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.demo.image.presentation; | ||
|
||
import com.example.demo.image.application.service.ImageService; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/images") | ||
public class ImageController { | ||
|
||
private final ImageService imageService; | ||
|
||
public ImageController(ImageService imageService) { | ||
this.imageService = imageService; | ||
} | ||
|
||
@GetMapping | ||
public List<Map<String, Object>> getProfileImages (){ | ||
List<Map<String, Object>> profileImageList = imageService.getFileList("styleganresult2"); | ||
return profileImageList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
spring: | ||
application: | ||
name: error | ||
|
||
jpa: | ||
properties: | ||
hibernate: | ||
format_sql: true | ||
dialect: org.hibernate.dialect.MySQLDialect | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: create | ||
|
||
logging: | ||
level: | ||
org: | ||
hibernate: | ||
type: | ||
descriptor: | ||
sql: | ||
BasicBinder: TRACE | ||
|
||
cloud: | ||
aws: | ||
region: | ||
static: ap-northeast-2 | ||
stack: | ||
auto: false | ||
credentials: | ||
accessKey: ${ACCESS_KEY} | ||
secretKey: ${SECRET_KEY} | ||
s3: | ||
bucket: zepimage0 |