Skip to content

Commit

Permalink
refactor: 카드 텍스트, 이미지 합치기
Browse files Browse the repository at this point in the history
  • Loading branch information
xxoznge committed Oct 2, 2024
1 parent 02c8675 commit a11b937
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<CardCreateResponse> 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<CardImageUploadResponse> 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));
}

/* 오늘의 따봉도치 랭킹 조회 */
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/* 카드 삭제 */
Expand Down

This file was deleted.

0 comments on commit a11b937

Please sign in to comment.