Skip to content

Commit

Permalink
Merge pull request #46 from 9oormthonUniv-seoultech/refactor/#45
Browse files Browse the repository at this point in the history
refactor: 이미지 조회할 때, Presigned URL 발급
  • Loading branch information
Jeongh00 authored Oct 30, 2024
2 parents d8f2926 + f44e0a5 commit baaee76
Show file tree
Hide file tree
Showing 26 changed files with 190 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.config;
package com.pocket.core.config;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.exception;
package com.pocket.core.exception.file;

import com.pocket.core.exception.common.BaseErrorCode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.exception;
package com.pocket.core.exception.file;

import com.pocket.core.exception.common.BaseErrorCode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.exception;
package com.pocket.core.exception.file;

import com.pocket.core.exception.common.BaseErrorCode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.exception;
package com.pocket.core.exception.file;

import com.pocket.core.exception.common.ApiResponse;
import com.pocket.core.exception.common.BaseErrorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.exception;
package com.pocket.core.exception.file;

import com.pocket.core.exception.common.BaseErrorCode;
import lombok.Getter;
Expand Down
25 changes: 0 additions & 25 deletions core/src/main/java/com/pocket/core/image/S3TestController.java

This file was deleted.

81 changes: 0 additions & 81 deletions core/src/main/java/com/pocket/core/image/service/AwsS3Service.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.dto;
package com.pocket.domain.dto.file;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.core.image.dto;
package com.pocket.domain.dto.file;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public record ReviewGetResponseDto(
int reviewCount,
List<ReviewPreviewDto> reviews
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.port.file;

public interface FileDownloadPort {

String getDownloadPresignedUrl(String filePath);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.file;

import com.pocket.domain.dto.file.PresignedUrlResponse;

public interface FileUploadPort {

PresignedUrlResponse getUploadPresignedUrl(String prefix, String fileName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.pocket.domain.dto.album.AlbumRegisterRequestDto;
import com.pocket.domain.dto.album.AlbumRegisterResponseDto;
import com.pocket.domain.port.album.AlbumRegisterPort;
import com.pocket.domain.usecase.image.AlbumRegisterUseCase;
import com.pocket.domain.usecase.album.AlbumRegisterUseCase;
import lombok.RequiredArgsConstructor;

@DomainService
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pocket.domain.service.file;


import com.pocket.domain.dto.file.PresignedUrlResponse;
import com.pocket.domain.port.file.FileDownloadPort;
import com.pocket.domain.port.file.FileUploadPort;
import com.pocket.domain.usecase.file.FileDownloadUseCase;
import com.pocket.domain.usecase.file.FileUploadUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class FileService implements FileUploadUseCase {

private final FileUploadPort fileUploadPort;

@Override
public PresignedUrlResponse getUploadPresignedUrl(String prefix, String fileName) {
return fileUploadPort.getUploadPresignedUrl(prefix, fileName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

import com.pocket.core.aop.annotation.DomainService;
import com.pocket.domain.dto.review.*;
import com.pocket.domain.port.file.FileDownloadPort;
import com.pocket.domain.port.review.*;
import com.pocket.domain.usecase.review.*;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.stream.Collectors;

@DomainService
@RequiredArgsConstructor
Expand All @@ -25,6 +27,7 @@ public class ReviewService implements ReviewRegisterUseCase, ReviewGet6ImagesUse
private final ReviewGetBoothFeaturePort reviewGetBoothFeaturePort;
private final ReviewGetPhotoFeaturePort reviewGetPhotoFeaturePort;
private final ReviewGetAllPort reviewGetAllPort;
private final FileDownloadPort fileDownloadPort;

@Override
public ReviewRegisterResponseDto registerReviewResponse(ReviewRegisterRequestDto reviewRegisterRequestDto, String name) {
Expand All @@ -33,17 +36,44 @@ public ReviewRegisterResponseDto registerReviewResponse(ReviewRegisterRequestDto

@Override
public ReviewGet6ImagesResponseDto get6Images(Long photoboothId) {
return reviewGet6ImagesPort.get6Images(photoboothId);
ReviewGet6ImagesResponseDto response = reviewGet6ImagesPort.get6Images(photoboothId);

List<String> presignedUrls = response.filePaths().stream()
.map(fileDownloadPort::getDownloadPresignedUrl)
.collect(Collectors.toList());

return new ReviewGet6ImagesResponseDto(presignedUrls, response.totalImageCount());
}

@Override
public ReviewGetResponseDto getRecentReview(Long photoboothId) {
return reviewGetRecentPort.getRecentReview(photoboothId);
ReviewGetResponseDto response = reviewGetRecentPort.getRecentReview(photoboothId);

List<ReviewPreviewDto> reviewPreviewsWithPresignedUrls = response.reviews().stream().map(review -> {
String presignedUrl = review.imageUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(review.imageUrl());
return new ReviewPreviewDto(
review.photoboothId(),
review.name(),
review.year(),
review.month(),
review.date(),
review.contents(),
review.features(),
presignedUrl,
review.imageCount()
);
}).collect(Collectors.toList());

return new ReviewGetResponseDto(response.reviewCount(), reviewPreviewsWithPresignedUrls);
}

@Override
public List<String> getAllImages(Long photoboothId, Pageable pageable) {
return reviewGetAllImagesPort.getAllImages(photoboothId, pageable);
List<String> rawImagePaths = reviewGetAllImagesPort.getAllImages(photoboothId, pageable);

return rawImagePaths.stream()
.map(fileDownloadPort::getDownloadPresignedUrl)
.collect(Collectors.toList());
}

@Override
Expand All @@ -68,6 +98,23 @@ public List<PhotoFeatureDto> getPhotoFeatures() {

@Override
public ReviewGetResponseDto getAllReviews(Long photoboothId, Pageable pageable) {
return reviewGetAllPort.getAllReviews(photoboothId, pageable);
ReviewGetResponseDto response = reviewGetAllPort.getAllReviews(photoboothId, pageable);

List<ReviewPreviewDto> reviewPreviewsWithPresignedUrls = response.reviews().stream().map(review -> {
String presignedUrl = review.imageUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(review.imageUrl());
return new ReviewPreviewDto(
review.photoboothId(),
review.name(),
review.year(),
review.month(),
review.date(),
review.contents(),
review.features(),
presignedUrl,
review.imageCount()
);
}).collect(Collectors.toList());

return new ReviewGetResponseDto(response.reviewCount(), reviewPreviewsWithPresignedUrls);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.domain.usecase.image;
package com.pocket.domain.usecase.album;

import com.pocket.domain.dto.album.AlbumRegisterRequestDto;
import com.pocket.domain.dto.album.AlbumRegisterResponseDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.usecase.file;

public interface FileDownloadUseCase {

String getDownloadPresignedUrl(String filePath);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.usecase.file;

import com.pocket.domain.dto.file.PresignedUrlResponse;

public interface FileUploadUseCase {

PresignedUrlResponse getUploadPresignedUrl(String prefix, String fileName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.pocket.domain.dto.album.AlbumRegisterRequestDto;
import com.pocket.domain.dto.album.AlbumRegisterResponseDto;
import com.pocket.domain.dto.user.UserInfoDTO;
import com.pocket.domain.usecase.image.AlbumRegisterUseCase;
import com.pocket.domain.usecase.album.AlbumRegisterUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.pocket.inbounds.file.presentation;

import com.pocket.core.exception.common.ApplicationResponse;
import com.pocket.core.image.dto.PresignedUrlRequest;
import com.pocket.core.image.dto.PresignedUrlResponse;
import com.pocket.core.image.service.FileService;
import com.pocket.domain.dto.file.PresignedUrlRequest;
import com.pocket.domain.dto.file.PresignedUrlResponse;
import com.pocket.domain.service.file.FileService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.nimbusds.oauth2.sdk.ErrorResponse;
import com.pocket.core.exception.common.ApplicationResponse;
import com.pocket.core.image.dto.PresignedUrlRequest;
import com.pocket.core.image.dto.PresignedUrlResponse;
import com.pocket.domain.dto.file.PresignedUrlRequest;
import com.pocket.domain.dto.file.PresignedUrlResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.pocket.inbounds.user.response;

import com.pocket.domain.dto.user.UserInfoDTO;

public record UserResponse(
String name,
String email,
Expand Down
Loading

0 comments on commit baaee76

Please sign in to comment.