From 2e3ba86ab32b98e717e28f6428caead91d119d97 Mon Sep 17 00:00:00 2001 From: minjoon-98 <4kmj54321@gmail.com> Date: Tue, 9 Jul 2024 17:23:24 +0900 Subject: [PATCH] chore : AWS S3 debug log --- .../ongjong/namanmoo/controller/ChallengeController.java | 6 ++++++ .../ongjong/namanmoo/controller/MemberController.java | 8 ++++++++ .../global/exception/handler/GlobalExceptionHandler.java | 3 ++- src/main/java/ongjong/namanmoo/service/AwsS3Service.java | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/ongjong/namanmoo/controller/ChallengeController.java b/src/main/java/ongjong/namanmoo/controller/ChallengeController.java index b167e1f..6cbc9d7 100644 --- a/src/main/java/ongjong/namanmoo/controller/ChallengeController.java +++ b/src/main/java/ongjong/namanmoo/controller/ChallengeController.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Data; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import ongjong.namanmoo.global.security.util.DateUtil; import ongjong.namanmoo.domain.Member; import ongjong.namanmoo.domain.answer.Answer; @@ -27,6 +28,7 @@ import java.util.*; import java.util.stream.Collectors; +@Slf4j @RestController @RequiredArgsConstructor @RequestMapping("/challenges") @@ -145,6 +147,7 @@ public ResponseEntity>> savePhotoAnswer( @ModelAttribute PhotoAnswerRequest photoAnswerRequest) throws Exception { // @RequestPart("challengeId") Long challengeId, // @RequestPart("answer") MultipartFile answerFile) throws Exception { + log.debug("PhotoAnswerRequest received: {}", photoAnswerRequest); Long challengeId = photoAnswerRequest.getChallengeId(); MultipartFile answerFile = photoAnswerRequest.getAnswer(); @@ -164,14 +167,17 @@ public ResponseEntity>> savePhotoAnswer( // S3에 파일 업로드 String uploadImageUrl = awsS3Service.uploadFile(answerFile); + log.debug("Uploaded image URL: {}", uploadImageUrl); // Answer 객체 수정 및 저장 Optional optionalAnswer = answerService.findAnswerByChallengeAndMember(challenge, member); if (optionalAnswer.isPresent()) { Answer answer = optionalAnswer.get(); + log.debug("Answer found: {}", answer); answer.setAnswerContent(uploadImageUrl); answer.setModifiedDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss"))); answerService.saveAnswer(answer); + log.debug("Answer saved: {}", answer); // Map 형태로 답변 URL 반환 Map responseData = new HashMap<>(); diff --git a/src/main/java/ongjong/namanmoo/controller/MemberController.java b/src/main/java/ongjong/namanmoo/controller/MemberController.java index 7071264..e443d12 100644 --- a/src/main/java/ongjong/namanmoo/controller/MemberController.java +++ b/src/main/java/ongjong/namanmoo/controller/MemberController.java @@ -2,6 +2,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import ongjong.namanmoo.dto.member.LoginRequestDto; import ongjong.namanmoo.dto.member.MemberInfoDto; import ongjong.namanmoo.dto.member.MemberSignUpDto; @@ -19,6 +20,7 @@ import java.util.HashMap; import java.util.Map; +@Slf4j @RestController @RequiredArgsConstructor public class MemberController { @@ -55,18 +57,24 @@ public ResponseEntity>> duplicate(@Valid @Reque @PostMapping("/users") @ResponseStatus(HttpStatus.OK) public ApiResponse updateBasicInfo(@RequestPart("userInfo") MemberUpdateDto memberUpdateDto) throws Exception { + log.debug("Received MemberUpdateDto: {}", memberUpdateDto); String uploadImageUrl = null; // 파일을 전송했을 경우에만 S3 파일 업로드 수행 if (memberUpdateDto.userImg().isPresent() && !memberUpdateDto.userImg().get().isEmpty()) { + log.debug("Uploading file to S3..."); uploadImageUrl = awsS3Service.uploadFile(memberUpdateDto.userImg().get()); + log.debug("File uploaded to S3: {}", uploadImageUrl); } + log.debug("Updating member information..."); memberService.update(memberUpdateDto); + log.debug("Member information updated."); // MemberService의 update 메소드에서 imagePath를 갱신해야 합니다. MemberInfoDto info = memberService.getMyInfo(); + log.debug("Member info retrieved: {}", info); return new ApiResponse<>("200", "Update User Info Success", info); } diff --git a/src/main/java/ongjong/namanmoo/global/exception/handler/GlobalExceptionHandler.java b/src/main/java/ongjong/namanmoo/global/exception/handler/GlobalExceptionHandler.java index aef454b..7419aa3 100644 --- a/src/main/java/ongjong/namanmoo/global/exception/handler/GlobalExceptionHandler.java +++ b/src/main/java/ongjong/namanmoo/global/exception/handler/GlobalExceptionHandler.java @@ -32,7 +32,8 @@ public ResponseEntity> handleIllegalStateException(IllegalSt @ExceptionHandler(Exception.class) public ResponseEntity> handleException(Exception ex, WebRequest request) { - ApiResponse response = new ApiResponse<>("500", "Internal Server Error", null); + ex.printStackTrace(); // 콘솔에 예외의 스택 트레이스를 출력합니다. + ApiResponse response = new ApiResponse<>("500", "Internal Server Error: " + ex.getMessage(), null); return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); } diff --git a/src/main/java/ongjong/namanmoo/service/AwsS3Service.java b/src/main/java/ongjong/namanmoo/service/AwsS3Service.java index 0082cd2..81d5acd 100644 --- a/src/main/java/ongjong/namanmoo/service/AwsS3Service.java +++ b/src/main/java/ongjong/namanmoo/service/AwsS3Service.java @@ -31,12 +31,16 @@ public class AwsS3Service { private String bucket; public String uploadFile(MultipartFile multipartFile) throws IOException { + log.debug("Converting MultipartFile to File..."); File uploadFile = convertFile(multipartFile) .orElseThrow(() -> new IllegalArgumentException("MultipartFile -> File convert fail")); String fileName = generateFileName(uploadFile); + log.debug("Uploading file to S3: {}", fileName); String uploadImageUrl = uploadFileToS3(uploadFile, fileName); + log.debug("File uploaded to S3: {}", uploadImageUrl); + removeNewFile(uploadFile); return uploadImageUrl; }