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 5f89fd7 commit 02c8675
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 15 deletions.
1 change: 0 additions & 1 deletion .platform/nginx/nginx.conf → .platform/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ http {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 0;
}

access_log /var/log/nginx/access.log main;
Expand Down
2 changes: 0 additions & 2 deletions .platform/nginx/conf.d/proxy.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 @@ -16,6 +17,7 @@
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 @@ -39,13 +41,20 @@ public class CardController {
private final CardQueryService cardQueryService;

/* 카드 작성 */
@PostMapping(value = "", consumes = "multipart/form-data")
@PostMapping(value = "/create", consumes = "application/json")
public ApiResponse<CardCreateResponse> createCard(
@UserResolver User authUser,
@RequestPart(value = "request") @Valid CardCreateRequest request,
@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(name = "cardImage") MultipartFile file
) {
return ApiResponse.onSuccess(cardService.createCard(authUser, request, file));
return ApiResponse.onSuccess(cardService.uploadCardImage(cardId, file));
}

/* 오늘의 따봉도치 랭킹 조회 */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ddabong.ddabongdotchiBE.domain.card.dto.response;

import lombok.Builder;

@Builder
public record CardImageUploadResponse(
String imageUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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 @@ -25,17 +26,25 @@ public class CardService {
private final CardRepository cardRepository;
private final S3Service s3Service;

/* 카드 작성 */
public CardCreateResponse createCard(
User authUser,
CardCreateRequest request,
MultipartFile file
) {
// 카드 텍스트 생성
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] 해당 카드가 존재하지 않습니다."));

String imageUrl = s3Service.uploadImage(file);
final Card card = cardRepository.save(request.toEntity(authUser));
card.setImageUrl(imageUrl);
cardRepository.save(card);
return CardCreateResponse.from(card);

return CardImageUploadResponse.builder()
.imageUrl(imageUrl)
.build();
}

/* 카드 삭제 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.web.multipart.MultipartFile;

import com.ddabong.ddabongdotchiBE.domain.global.ApiResponse;
import com.ddabong.ddabongdotchiBE.domain.s3.S3Service;
import com.ddabong.ddabongdotchiBE.domain.user.annotation.UserResolver;
import com.ddabong.ddabongdotchiBE.domain.user.dto.request.PasswordUpdateRequest;
import com.ddabong.ddabongdotchiBE.domain.user.dto.request.UserJoinRequest;
Expand All @@ -40,6 +41,7 @@ public class UserController {

private final UserService userService;
private final UserQueryService userQueryService;
private final S3Service s3Service;

@PostMapping(value = "/join", consumes = "multipart/form-data")
public ApiResponse<UserJoinResponse> join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public record UserJoinRequest(
@NotBlank(message = "[ERROR] 닉네임 입력은 필수입니다.")
@Pattern(regexp = "^[가-힣]{2,7}$", message = "[ERROR] 닉네임은 한글로 2~7글자여야 합니다.")
String nickname,
String description
String description,

String imageUrl
) {

public User toEntity(String encodedPassword) {
Expand All @@ -28,6 +30,7 @@ public User toEntity(String encodedPassword) {
.password(encodedPassword)
.nickname(nickname)
.description(description)
.imageUrl(imageUrl)
.roleType(RoleType.USER)
.userStatus(UserStatus.ACTIVE)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ddabong.ddabongdotchiBE.domain.user.dto.response;

public record UserImageUploadResponse(
String imageUrl
) {
}

0 comments on commit 02c8675

Please sign in to comment.