Skip to content

Commit

Permalink
Merge pull request #44 from Mile-Writings/feat/#43
Browse files Browse the repository at this point in the history
#43 [feat] S3 모듈 구현 - presignedUrl
  • Loading branch information
sohyundoh authored Jan 10, 2024
2 parents 2bbb26d + 6f609dc commit 93f467e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 33 deletions.
31 changes: 0 additions & 31 deletions module-api/src/main/java/com/mile/controller/TestController.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mile.controller.external;

import com.mile.aws.utils.PreSignedUrlResponse;
import com.mile.aws.utils.S3BucketDirectory;
import com.mile.aws.utils.S3Service;
import com.mile.dto.SuccessResponse;
import com.mile.exception.message.SuccessMessage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class S3Controller implements S3ControllerSwagger {
private final S3Service s3Service;

@GetMapping("/image/upload")
@Override
public SuccessResponse<PreSignedUrlResponse> getPreSignedUrl() {
return SuccessResponse.of(SuccessMessage.PRESIGNED_URL_GET_SUCCESS, s3Service.getUploadPreSignedUrl(S3BucketDirectory.POST_PREFIX));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mile.controller.external;

import com.mile.aws.utils.PreSignedUrlResponse;
import com.mile.dto.SuccessResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "Image - PreSigned Url", description = "이미지 업로드 할 Url 받기")
public interface S3ControllerSwagger {

@Operation(summary = "이미지 업로드 presigned url")
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "이미지를 업로드할 url이 발행되었습니다."),
@ApiResponse(responseCode = "500", description = "S3 PRESIGNED URL을 받아오기에 실패했습니다.")
}
)
SuccessResponse<PreSignedUrlResponse> getPreSignedUrl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public enum ErrorMessage {
/*
Internal Server Error
*/
IMAGE_UPLOAD_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "S3 버킷에 이미지를 업로드하는 데 실패했습니다."),
IMAGE_UPLOAD_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "S3 버킷에 이미지를 업로드에 실패했습니다."),
PRESIGNED_URL_GET_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "S3 PRESIGNED URL을 받아오기에 실패했습니다."),
IMAGE_DELETE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "S3 버킷으로부터 이미지를 삭제하는 데 실패했습니다."),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류입니다.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public enum SuccessMessage {
CURIOUS_DELETE_SUCCESS(HttpStatus.OK.value(), "궁금해요 삭제가 완료되었습니다."),
WRITER_AUTHENTIACTE_SUCCESS(HttpStatus.OK.value(), "게시글 권한이 확인되었습니다."),
POST_PUT_SUCCESS(HttpStatus.OK.value(), "글 수정이 완료되었습니다."),
PRESIGNED_URL_GET_SUCCESS(HttpStatus.OK.value(), "이미지를 업로드할 url이 발행되었습니다."),
POST_DELETE_SUCCESS(HttpStatus.OK.value(), "글 삭제가 완료되었습니다."),

/*
201 CREATED
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public PreSignedUrlResponse getUploadPreSignedUrl(final S3BucketDirectory prefix
String url = preSigner.presignPutObject(preSignedUrlRequest).url().toString();
return PreSignedUrlResponse.of(fileName, url);
} catch (RuntimeException e) {
throw new MileException(ErrorMessage.IMAGE_UPLOAD_ERROR);
throw new MileException(ErrorMessage.PRESIGNED_URL_GET_ERROR);
}
}

Expand Down

0 comments on commit 93f467e

Please sign in to comment.