diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java index 48c7adbef..f7a5e1686 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/CommentService.java @@ -24,6 +24,7 @@ import com.zzang.chongdae.offeringmember.exception.OfferingMemberErrorCode; import com.zzang.chongdae.offeringmember.repository.OfferingMemberRepository; import com.zzang.chongdae.offeringmember.repository.entity.OfferingMemberEntity; +import com.zzang.chongdae.storage.service.StorageService; import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; @@ -39,6 +40,7 @@ public class CommentService { private final CommentRepository commentRepository; private final OfferingRepository offeringRepository; private final OfferingMemberRepository offeringMemberRepository; + private final StorageService storageService; @WriterDatabase public Long saveComment(CommentSaveRequest request, MemberEntity member) { @@ -91,9 +93,10 @@ public CommentRoomInfoResponse getCommentRoomInfo(Long offeringId, MemberEntity OfferingMemberEntity offeringMember = offeringMemberRepository.findByOfferingIdAndMember(offeringId, member) .orElseThrow(() -> new MarketException(OfferingMemberErrorCode.NOT_FOUND)); if (offeringRepository.existsById(offeringId)) { - return new CommentRoomInfoResponse(offeringMember.getOffering(), offeringMember.getMember()); + return new CommentRoomInfoResponse(offeringMember.getOffering(), offeringMember.getMember(), + storageService.getResourceHost()); } - return new CommentRoomInfoResponse(offeringMember); + return new CommentRoomInfoResponse(offeringMember, storageService.getResourceHost()); } @WriterDatabase diff --git a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomInfoResponse.java b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomInfoResponse.java index ced8b75ff..fc2978acd 100644 --- a/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomInfoResponse.java +++ b/backend/src/main/java/com/zzang/chongdae/comment/service/dto/CommentRoomInfoResponse.java @@ -21,18 +21,18 @@ public record CommentRoomInfoResponse(CommentRoomStatus status, String title, boolean isProposer) { - public CommentRoomInfoResponse(OfferingEntity offering, MemberEntity member) { + public CommentRoomInfoResponse(OfferingEntity offering, MemberEntity member, String resourceHost) { this(offering.getRoomStatus(), - ViewMapper.toImage(offering.getRoomStatus()), + ViewMapper.toImage(offering.getRoomStatus(), resourceHost), ViewMapper.toButton(offering.getRoomStatus()), ViewMapper.toMessage(offering.getRoomStatus()), offering.getTitle(), offering.isProposedBy(member)); } - public CommentRoomInfoResponse(OfferingMemberEntity offeringMember) { + public CommentRoomInfoResponse(OfferingMemberEntity offeringMember, String resourceHost) { this(DELETED, - ViewMapper.toImage(DELETED), + ViewMapper.toImage(DELETED, resourceHost), ViewMapper.toButton(DELETED), ViewMapper.toMessage(DELETED), "삭제된 공동구매입니다.", @@ -41,11 +41,11 @@ public CommentRoomInfoResponse(OfferingMemberEntity offeringMember) { private enum ViewMapper { - DELETED_VIEW(DELETED, imageUrl("DELETED"), "삭제된 공고", "삭제된 공동구매입니다."), - GROUPING_VIEW(GROUPING, imageUrl("GROUPING"), "인원확정", "공동구매에 참여할 인원이\n모이면 인원을 확정하세요."), - BUYING_VIEW(BUYING, imageUrl("BUYING"), "구매확정", "총대가 물품 구매를 완료하면 확정하세요."), - TRADING_VIEW(TRADING, imageUrl("TRADING"), "거래확정", "총대가 참여자들과\n거래를 완료하면 확정하세요."), - DONE_VIEW(DONE, imageUrl("DONE"), "거래완료", "거래가 완료되었어요."); + DELETED_VIEW(DELETED, "DELETED", "삭제된 공고", "삭제된 공동구매입니다."), + GROUPING_VIEW(GROUPING, "GROUPING", "인원확정", "공동구매에 참여할 인원이\n모이면 인원을 확정하세요."), + BUYING_VIEW(BUYING, "BUYING", "구매확정", "총대가 물품 구매를 완료하면 확정하세요."), + TRADING_VIEW(TRADING, "TRADING", "거래확정", "총대가 참여자들과\n거래를 완료하면 확정하세요."), + DONE_VIEW(DONE, "DONE", "거래완료", "거래가 완료되었어요."); private final CommentRoomStatus roomStatus; private final String image; @@ -59,8 +59,8 @@ private enum ViewMapper { this.message = message; } - private static String toImage(CommentRoomStatus status) { - return findViewMapper(status).image; + private static String toImage(CommentRoomStatus status, String resourceHost) { + return "https://%s/common/%s.png".formatted(resourceHost, findViewMapper(status).image); } private static String toButton(CommentRoomStatus status) { @@ -77,10 +77,5 @@ private static ViewMapper findViewMapper(CommentRoomStatus status) { .findFirst() .orElseThrow(() -> new MarketException(OfferingErrorCode.INVALID_CONDITION)); } - - private static String imageUrl(String status) { - String imageUrlFormat = "https://d3a5rfnjdz82qu.cloudfront.net/chongdae-market/images/common/%s.png"; - return String.format(imageUrlFormat, status); - } } } diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java index e10d96dc7..4838d2f75 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/OfferingService.java @@ -208,6 +208,6 @@ private void validateInProgress(OfferingEntity offering) { public OfferingMetaResponse getOfferingMetaInfo(Long offeringId) { OfferingEntity offering = offeringRepository.findById(offeringId) .orElseThrow(() -> new MarketException(OfferingErrorCode.NOT_FOUND)); - return new OfferingMetaResponse(offering); + return new OfferingMetaResponse(offering, storageService.getResourceHost()); } } diff --git a/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingMetaResponse.java b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingMetaResponse.java index 5832acec1..c8712fcec 100644 --- a/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingMetaResponse.java +++ b/backend/src/main/java/com/zzang/chongdae/offering/service/dto/OfferingMetaResponse.java @@ -4,15 +4,15 @@ public record OfferingMetaResponse(String title, String thumbnailUrl) { - private static final String DEFAULT_THUMBNAIL_URL = "https://image.chongdae.site/common/no-image.png"; + private static final String DEFAULT_RESOURCE_FILE_NAME = "no-image.png"; - public OfferingMetaResponse(OfferingEntity offering) { - this(offering.getTitle(), getOrDefault(offering.getThumbnailUrl())); + public OfferingMetaResponse(OfferingEntity offering, String resourceHost) { + this(offering.getTitle(), getOrDefault(offering.getThumbnailUrl(), resourceHost)); } - private static String getOrDefault(String thumbnailUrl) { + private static String getOrDefault(String thumbnailUrl, String resourceHost) { if (thumbnailUrl == null) { - return DEFAULT_THUMBNAIL_URL; + return "https://%s/common/%s".formatted(resourceHost, DEFAULT_RESOURCE_FILE_NAME); } return thumbnailUrl; } diff --git a/backend/src/main/java/com/zzang/chongdae/storage/service/AmazonS3StorageService.java b/backend/src/main/java/com/zzang/chongdae/storage/service/AmazonS3StorageService.java index 51315835c..626d8e141 100644 --- a/backend/src/main/java/com/zzang/chongdae/storage/service/AmazonS3StorageService.java +++ b/backend/src/main/java/com/zzang/chongdae/storage/service/AmazonS3StorageService.java @@ -18,16 +18,16 @@ public class AmazonS3StorageService implements StorageService { private final AmazonS3 s3Client; - - @Value("${amazon.s3.bucket}") - private String bucketName; - @Value("${amazon.cloudfront.redirectUrl}") - private String redirectUrl; + @Value("${storage.resourceHost}") + private String resourceHost; - @Value("${amazon.cloudfront.storagePath}") + @Value("${storage.path}") private String storagePath; + @Value("${amazon.s3.bucket}") + private String bucketName; + @Override public String uploadFile(MultipartFile file) { try { @@ -54,9 +54,14 @@ private ObjectMetadata createMetadata(MultipartFile file) { private String createUri(String objectKey) { return UriComponentsBuilder.newInstance() .scheme("https") - .host(redirectUrl) + .host(resourceHost) .path("/" + objectKey) .build(false) .toString(); } + + @Override + public String getResourceHost() { + return resourceHost; + } } diff --git a/backend/src/main/java/com/zzang/chongdae/storage/service/LocalStorageService.java b/backend/src/main/java/com/zzang/chongdae/storage/service/LocalStorageService.java index 3f32605c5..596701bc6 100644 --- a/backend/src/main/java/com/zzang/chongdae/storage/service/LocalStorageService.java +++ b/backend/src/main/java/com/zzang/chongdae/storage/service/LocalStorageService.java @@ -19,17 +19,12 @@ public class LocalStorageService implements StorageService { private static final Set ALLOW_IMAGE_EXTENSIONS = Set.of("jpg", "jpeg", "png", "gif", "bmp", "svg"); - @Value("${storage.redirectUrl}") - private String redirectUrl; + @Value("${storage.resourceHost}") + private String resourceHost; @Value("${storage.path}") private String storagePath; - LocalStorageService(String redirectUrl, String storagePath) { - this.redirectUrl = redirectUrl; - this.storagePath = storagePath; - } - @Override public String uploadFile(MultipartFile file) { String extension = getFileExtension(file); @@ -67,9 +62,14 @@ private void validateFileExtension(String extension) { private String createUri(String objectKey) { return UriComponentsBuilder.newInstance() .scheme("https") - .host(redirectUrl) + .host(resourceHost) .path("/" + objectKey) .build(false) .toString(); } + + @Override + public String getResourceHost() { + return resourceHost; + } } diff --git a/backend/src/main/java/com/zzang/chongdae/storage/service/StorageService.java b/backend/src/main/java/com/zzang/chongdae/storage/service/StorageService.java index 4ead53728..a86d73917 100644 --- a/backend/src/main/java/com/zzang/chongdae/storage/service/StorageService.java +++ b/backend/src/main/java/com/zzang/chongdae/storage/service/StorageService.java @@ -5,4 +5,6 @@ public interface StorageService { String uploadFile(MultipartFile file); + + String getResourceHost(); } diff --git a/backend/src/main/resources/application-dev.yml b/backend/src/main/resources/application-dev.yml index db8e5b7cd..a135fa2f0 100644 --- a/backend/src/main/resources/application-dev.yml +++ b/backend/src/main/resources/application-dev.yml @@ -16,5 +16,5 @@ security: refresh-secret-key: ${JWT_REFRESH_SECRET_KEY} storage: - path: /uploads - redirectUrl: image.dev.chongdae.site \ No newline at end of file + path: ${STORAGE_PHYSICAL_PATH} + resourceHost: ${STORAGE_RESOURCE_HOST} diff --git a/backend/src/main/resources/application-prod.yml b/backend/src/main/resources/application-prod.yml index ae2396cca..e2b0a69e6 100644 --- a/backend/src/main/resources/application-prod.yml +++ b/backend/src/main/resources/application-prod.yml @@ -21,5 +21,5 @@ security: refresh-secret-key: ${JWT_REFRESH_SECRET_KEY} storage: - path: /uploads - redirectUrl: image.chongdae.site \ No newline at end of file + path: ${STORAGE_PHYSICAL_PATH} + resourceHost: ${STORAGE_RESOURCE_HOST} diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 9426d7333..cb5cf439b 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -6,3 +6,5 @@ SPRING_WRITER_DATASOURCE_USERNAME=[SPRING_WRITER_DATASOURCE_USERNAME] SPRING_WRITER_DATASOURCE_PASSWORD=[SPRING_WRITER_DATASOURCE_PASSWORD] JWT_ACCESS_SECRET_KEY=[JWT_ACCESS_SECRET_KEY] JWT_REFRESH_SECRET_KEY=[JWT_REFRESH_SECRET_KEY] +STORAGE_RESOURCE_HOST=[STORAGE_RESOURCE_HOST] +STORAGE_PHYSICAL_PATH=[STORAGE_PHYSICAL_PATH] diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 164854d5d..412a8a0dd 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -90,3 +90,7 @@ management: fcm: secret-key: path: /fcm/chongdaemarket-fcm-key.json + +storage: + path: /uploads + resourceHost: image.chongdae.site diff --git a/backend/src/test/java/com/zzang/chongdae/offering/util/FakeStorageService.java b/backend/src/test/java/com/zzang/chongdae/offering/util/FakeStorageService.java index b7b2994fc..39988ce9e 100644 --- a/backend/src/test/java/com/zzang/chongdae/offering/util/FakeStorageService.java +++ b/backend/src/test/java/com/zzang/chongdae/offering/util/FakeStorageService.java @@ -9,4 +9,9 @@ public class FakeStorageService implements StorageService { public String uploadFile(MultipartFile file) { return "https://upload-image-url.com/"; } + + @Override + public String getResourceHost() { + return "upload-image-url.com"; + } } diff --git a/backend/src/test/resources/application-test.yml b/backend/src/test/resources/application-test.yml index abe554500..f9b022538 100644 --- a/backend/src/test/resources/application-test.yml +++ b/backend/src/test/resources/application-test.yml @@ -23,7 +23,3 @@ security: fcm: secret-key: path: /fcm/chongdaemarket-fcm-key.json - -storage: - path: /uploads - redirectUrl: fake.image.chongdae.site \ No newline at end of file