-
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.
Browse files
Browse the repository at this point in the history
feat: 사진 저장 API 구현
- Loading branch information
Showing
17 changed files
with
351 additions
and
5 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
35 changes: 35 additions & 0 deletions
35
photo-service/src/main/java/kr/mafoo/photo/config/NcpConfig.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,35 @@ | ||
package kr.mafoo.photo.config; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.client.builder.AwsClientBuilder; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class NcpConfig { | ||
|
||
@Value("${cloud.aws.credentials.access-key}") | ||
private String accessKey; | ||
|
||
@Value("${cloud.aws.credentials.secret-key}") | ||
private String secretKey; | ||
|
||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Value("${cloud.aws.s3.endpoint}") | ||
private String endPoint; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey,secretKey); | ||
return (AmazonS3Client) AmazonS3ClientBuilder.standard() | ||
.withCredentials(new AWSStaticCredentialsProvider(awsCreds)) | ||
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endPoint, region)) | ||
.build(); | ||
} | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
photo-service/src/main/java/kr/mafoo/photo/domain/BrandType.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,32 @@ | ||
package kr.mafoo.photo.domain; | ||
|
||
public enum BrandType { | ||
LIFE_FOUR_CUTS("https://api.life4cut.net/"), | ||
PHOTOISM("https://qr.seobuk.kr/"), | ||
HARU_FILM( "http://haru6.mx2.co.kr/"), | ||
DONT_LOOK_UP("https://x.dontlxxkup.kr/"), | ||
; | ||
|
||
private String urlFormat; | ||
|
||
private BrandType(String urlFormat) { | ||
this.urlFormat = urlFormat; | ||
} | ||
|
||
public String getUrlFormat() { | ||
return urlFormat; | ||
} | ||
|
||
public boolean matches(String qrUrl) { | ||
return qrUrl.startsWith(this.urlFormat); | ||
} | ||
|
||
public static BrandType matchBrandType(String qrUrl) { | ||
for (BrandType brandType : BrandType.values()) { | ||
if (brandType.matches(qrUrl)) { | ||
return brandType; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
photo-service/src/main/java/kr/mafoo/photo/exception/PhotoBrandNotExistsException.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,7 @@ | ||
package kr.mafoo.photo.exception; | ||
|
||
public class PhotoBrandNotExistsException extends DomainException { | ||
public PhotoBrandNotExistsException() { | ||
super(ErrorCode.PHOTO_BRAND_NOT_EXISTS); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
photo-service/src/main/java/kr/mafoo/photo/exception/PhotoQrUrlExpiredException.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,7 @@ | ||
package kr.mafoo.photo.exception; | ||
|
||
public class PhotoQrUrlExpiredException extends DomainException{ | ||
public PhotoQrUrlExpiredException() { | ||
super(ErrorCode.PHOTO_QR_URL_EXPIRED); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
photo-service/src/main/java/kr/mafoo/photo/exception/RedirectUriNotFoundException.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,7 @@ | ||
package kr.mafoo.photo.exception; | ||
|
||
public class RedirectUriNotFoundException extends DomainException { | ||
public RedirectUriNotFoundException() { | ||
super(ErrorCode.REDIRECT_URI_NOT_FOUND); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
photo-service/src/main/java/kr/mafoo/photo/service/ObjectStorageService.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,48 @@ | ||
package kr.mafoo.photo.service; | ||
|
||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
|
||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ObjectStorageService { | ||
|
||
private final AmazonS3Client amazonS3Client; | ||
|
||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucketName; | ||
|
||
public Mono<String> uploadFile(byte[] fileByte) { | ||
String keyName = "/" + UUID.randomUUID(); | ||
|
||
ObjectMetadata objectMetadata = new ObjectMetadata(); | ||
objectMetadata.setContentLength(fileByte.length); | ||
objectMetadata.setContentType("image/jpeg"); | ||
|
||
return Mono.fromCallable(() -> { | ||
try (InputStream inputStream = new ByteArrayInputStream(fileByte)) { | ||
amazonS3Client.putObject( | ||
new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata) | ||
.withCannedAcl(CannedAccessControlList.PublicRead)); | ||
|
||
return "https://kr.object.ncloudstorage.com/" + bucketName + "/" + keyName; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.