-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from Team-BC-1/fix/edit-sell-image-upload
즉시 판매 및 판매 입찰에서 기프티콘 이미지를 받도록 수정
- Loading branch information
Showing
16 changed files
with
152 additions
and
20 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
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
6 changes: 3 additions & 3 deletions
6
src/main/java/bc1/gream/domain/sell/dto/request/SellBidRequestDto.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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package bc1.gream.domain.sell.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Builder | ||
public record SellBidRequestDto( | ||
@NotNull(message = "가격 필드는 비울 수 없습니다.") | ||
Long price, | ||
Integer period, | ||
@NotBlank(message = "기프티콘을 업로드해 주세요") | ||
String gifticonUrl | ||
@NotNull(message = "기프티콘을 업로드해 주세요") | ||
MultipartFile file | ||
) { | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/bc1/gream/domain/sell/dto/request/SellNowRequestDto.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package bc1.gream.domain.sell.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public record SellNowRequestDto( | ||
@NotNull(message = "가격 필드는 비울 수 없습니다.") | ||
Long price, | ||
@NotBlank(message = "기프티콘을 업로드해 주세요") | ||
String gifticonUrl | ||
@NotNull(message = "기프티콘을 업로드해 주세요") | ||
MultipartFile file | ||
) { | ||
|
||
} |
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
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 bc1.gream.infra.s3; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
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 S3Config { | ||
|
||
@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; | ||
|
||
@Bean | ||
public AmazonS3 amazonS3() { | ||
return AmazonS3ClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))) | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package bc1.gream.infra.s3; | ||
|
||
import bc1.gream.global.common.ResultCase; | ||
import bc1.gream.global.exception.GlobalException; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Slf4j(topic = "s3 image upload") | ||
@Service | ||
@RequiredArgsConstructor | ||
public class S3ImageService { | ||
|
||
private static final String gifticonDirectoryName = "gifticon/"; | ||
private final AmazonS3 amazonS3; | ||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucketName; | ||
|
||
@Transactional | ||
public String getUrlAfterUpload(MultipartFile image) { | ||
|
||
String originalName = image.getOriginalFilename(); | ||
String randomImageName = getRandomImageName(originalName); | ||
log.info("s3 upload name : {}", randomImageName); | ||
|
||
try { | ||
PutObjectRequest request = new PutObjectRequest( | ||
bucketName, | ||
randomImageName, | ||
image.getInputStream(), | ||
createObjectMetadata(originalName) | ||
) | ||
.withCannedAcl(CannedAccessControlList.PublicRead); | ||
amazonS3.putObject(request); | ||
} catch (IOException e) { | ||
throw new GlobalException(ResultCase.IMAGE_UPLOAD_FAIL); | ||
} | ||
|
||
String url = amazonS3.getUrl(bucketName, randomImageName).toString(); | ||
log.info("s3 url : {}", url); | ||
return url; | ||
} | ||
|
||
private String getRandomImageName(String originalName) { | ||
String random = UUID.randomUUID().toString(); | ||
return gifticonDirectoryName + random + '-' + originalName; | ||
} | ||
|
||
private ObjectMetadata createObjectMetadata(String originalName) { | ||
ObjectMetadata metadata = new ObjectMetadata(); | ||
String ext = originalName.substring(originalName.lastIndexOf(".")); | ||
metadata.setContentType("image/" + ext); | ||
return metadata; | ||
} | ||
} |
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
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