From a11b9371ad92f76ada1f5937c2f3ec465e3b38eb Mon Sep 17 00:00:00 2001 From: xxoznge <20201049@sungshin.ac.kr> Date: Wed, 2 Oct 2024 15:43:43 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=B9=B4=EB=93=9C=20=ED=85=8D?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8,=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=ED=95=A9?= =?UTF-8?q?=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../card/controller/CardController.java | 15 +++-------- .../dto/response/CardImageUploadResponse.java | 9 ------- .../domain/card/service/CardService.java | 25 ++++++------------- .../dto/response/UserImageUploadResponse.java | 6 ----- 4 files changed, 11 insertions(+), 44 deletions(-) delete mode 100644 src/main/java/com/ddabong/ddabongdotchiBE/domain/card/dto/response/CardImageUploadResponse.java delete mode 100644 src/main/java/com/ddabong/ddabongdotchiBE/domain/user/dto/response/UserImageUploadResponse.java diff --git a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java b/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java index eaf1020..ff42743 100644 --- a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java +++ b/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/controller/CardController.java @@ -7,7 +7,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestPart; @@ -17,7 +16,6 @@ import com.ddabong.ddabongdotchiBE.domain.card.dto.request.CardCreateRequest; import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardCreateResponse; import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardDetailGetResponse; -import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardImageUploadResponse; import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardSummaryGetResponse; import com.ddabong.ddabongdotchiBE.domain.card.entity.CardStatus; import com.ddabong.ddabongdotchiBE.domain.card.entity.FortuneType; @@ -41,20 +39,13 @@ public class CardController { private final CardQueryService cardQueryService; /* 카드 작성 */ - @PostMapping(value = "/create", consumes = "application/json") + @PostMapping(value = "", consumes = "multipart/form-data") public ApiResponse createCard( @UserResolver User authUser, - @RequestBody @Valid CardCreateRequest request - ) { - return ApiResponse.onSuccess(cardService.createCard(authUser, request)); - } - - @PostMapping(value = "/{cardId}/uploadImage", consumes = "multipart/form-data") - public ApiResponse uploadCardImage( - @PathVariable Long cardId, + @RequestPart(value = "request") @Valid CardCreateRequest request, @RequestPart(name = "cardImage") MultipartFile file ) { - return ApiResponse.onSuccess(cardService.uploadCardImage(cardId, file)); + return ApiResponse.onSuccess(cardService.createCard(authUser, request, file)); } /* 오늘의 따봉도치 랭킹 조회 */ diff --git a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/dto/response/CardImageUploadResponse.java b/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/dto/response/CardImageUploadResponse.java deleted file mode 100644 index 6943197..0000000 --- a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/dto/response/CardImageUploadResponse.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ddabong.ddabongdotchiBE.domain.card.dto.response; - -import lombok.Builder; - -@Builder -public record CardImageUploadResponse( - String imageUrl -) { -} diff --git a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/service/CardService.java b/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/service/CardService.java index 4d6330b..7fae483 100644 --- a/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/service/CardService.java +++ b/src/main/java/com/ddabong/ddabongdotchiBE/domain/card/service/CardService.java @@ -6,7 +6,6 @@ import com.ddabong.ddabongdotchiBE.domain.card.dto.request.CardCreateRequest; import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardCreateResponse; -import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardImageUploadResponse; import com.ddabong.ddabongdotchiBE.domain.card.entity.Card; import com.ddabong.ddabongdotchiBE.domain.card.exception.CardErrorCode; import com.ddabong.ddabongdotchiBE.domain.card.exception.CardExceptionHandler; @@ -26,25 +25,17 @@ public class CardService { private final CardRepository cardRepository; private final S3Service s3Service; - // 카드 텍스트 생성 - public CardCreateResponse createCard(User authUser, CardCreateRequest request) { - Card card = request.toEntity(authUser); - card = cardRepository.save(card); - return CardCreateResponse.from(card); - } - - // 카드 이미지 업로드 - public CardImageUploadResponse uploadCardImage(Long cardId, MultipartFile file) { - Card card = cardRepository.findById(cardId) - .orElseThrow(() -> new IllegalArgumentException("[ERROR] 해당 카드가 존재하지 않습니다.")); - + /* 카드 작성 */ + public CardCreateResponse createCard( + User authUser, + CardCreateRequest request, + MultipartFile file + ) { String imageUrl = s3Service.uploadImage(file); + final Card card = cardRepository.save(request.toEntity(authUser)); card.setImageUrl(imageUrl); cardRepository.save(card); - - return CardImageUploadResponse.builder() - .imageUrl(imageUrl) - .build(); + return CardCreateResponse.from(card); } /* 카드 삭제 */ diff --git a/src/main/java/com/ddabong/ddabongdotchiBE/domain/user/dto/response/UserImageUploadResponse.java b/src/main/java/com/ddabong/ddabongdotchiBE/domain/user/dto/response/UserImageUploadResponse.java deleted file mode 100644 index a0e7ac5..0000000 --- a/src/main/java/com/ddabong/ddabongdotchiBE/domain/user/dto/response/UserImageUploadResponse.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.ddabong.ddabongdotchiBE.domain.user.dto.response; - -public record UserImageUploadResponse( - String imageUrl -) { -}