Skip to content

Commit

Permalink
refactor: presigned url 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
xxoznge committed Oct 15, 2024
1 parent 8da95c0 commit f2840ba
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ddabong.ddabongdotchiBE.domain.card.dto.request.CardCreateRequest;
import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardCreateResponse;
Expand Down Expand Up @@ -39,13 +38,12 @@ public class CardController {
private final CardQueryService cardQueryService;

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

/* 오늘의 따봉도치 랭킹 조회 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public record CardCreateRequest(
String title,
String mood,
String content,
String type
String type,
String imageUrl
) {

public Card toEntity(
Expand All @@ -23,6 +24,7 @@ public Card toEntity(
.mood(mood)
.content(content)
.type(FortuneType.valueOf(type))
.imageUrl(imageUrl)
.user(cardUser)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.ddabong.ddabongdotchiBE.domain.card.dto.request.CardCreateRequest;
import com.ddabong.ddabongdotchiBE.domain.card.dto.response.CardCreateResponse;
Expand All @@ -28,12 +27,9 @@ public class CardService {
/* 카드 작성 */
public CardCreateResponse createCard(
User authUser,
CardCreateRequest request,
MultipartFile file
CardCreateRequest request
) {
String imageUrl = s3Service.uploadImage(file);
final Card card = cardRepository.save(request.toEntity(authUser));
card.setImageUrl(imageUrl);
cardRepository.save(card);
return CardCreateResponse.from(card);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ public ApiResponse<List<String>> uploadImages(
public S3Response getPreSignedUrl(@RequestParam String fileName) {
return s3Service.getPreSignedUrl(fileName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.ddabong.ddabongdotchiBE.domain.global.ApiResponse;
import com.ddabong.ddabongdotchiBE.domain.s3.S3Service;
Expand Down Expand Up @@ -43,12 +42,11 @@ public class UserController {
private final UserQueryService userQueryService;
private final S3Service s3Service;

@PostMapping(value = "/join", consumes = "multipart/form-data")
@PostMapping(value = "/join")
public ApiResponse<UserJoinResponse> join(
@RequestPart(value = "request") @Valid UserJoinRequest request,
@RequestPart(name = "profileImage", required = false) MultipartFile file
@RequestPart(value = "request") @Valid UserJoinRequest request
) {
return ApiResponse.onSuccess(userService.join(request, file));
return ApiResponse.onSuccess(userService.join(request));
}

@GetMapping("/username")
Expand Down Expand Up @@ -85,12 +83,11 @@ public ApiResponse<List<MyCardGetResponse>> getMyCards(@UserResolver User user)
return ApiResponse.onSuccess(UserQueryService.getMyCard(user));
}

@PatchMapping(value = "/me", consumes = "multipart/form-data")
@PatchMapping(value = "/me")
public ApiResponse<UserUpdateResponse> updateMyUser(
@UserResolver User user,
@RequestPart @Valid UserUpdateRequest request,
@RequestPart(value = "profileImage", required = false) MultipartFile file) {
return ApiResponse.onSuccess(userService.updateMyUser(user, request, file));
@RequestPart @Valid UserUpdateRequest request) {
return ApiResponse.onSuccess(userService.updateMyUser(user, request));
}

@DeleteMapping("/me")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public record UserJoinRequest(
@Pattern(regexp = "^[가-힣]{2,7}$", message = "[ERROR] 닉네임은 한글로 2~7글자여야 합니다.")
String nickname,
String description,

String imageUrl
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public record UserUpdateRequest(
String nickname,
String description
String description,
String imageUrl
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public void deactivate() {
this.userStatus = UserStatus.INACTIVE;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public void updatePassword(String password) {
this.password = password == null ? this.password : password;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.ddabong.ddabongdotchiBE.domain.s3.S3Service;
import com.ddabong.ddabongdotchiBE.domain.user.dto.request.PasswordUpdateRequest;
Expand Down Expand Up @@ -33,13 +32,8 @@ public class UserService {
private final S3Service s3Service;
private final JwtUtil jwtUtil;

public UserJoinResponse join(UserJoinRequest request, MultipartFile file) {
String imageUrl = null;
if (file != null && !file.isEmpty()) {
imageUrl = s3Service.uploadImage(file);
}
public UserJoinResponse join(UserJoinRequest request) {
final User user = request.toEntity(passwordEncoder.encode(request.password()));
user.setImageUrl(imageUrl);
userRepository.save(user);
return UserJoinResponse.from(user);
}
Expand All @@ -54,12 +48,8 @@ public void updatePassword(User user, PasswordUpdateRequest request) {
user.updatePassword(encodedNewPassword);
}

public UserUpdateResponse updateMyUser(User user, UserUpdateRequest request, MultipartFile file) {
String imageUrl = null;
if (file != null && !file.isEmpty()) {
imageUrl = s3Service.uploadImage(file);
}
user.update(request.nickname(), request.description(), imageUrl);
public UserUpdateResponse updateMyUser(User user, UserUpdateRequest request) {
user.update(request.nickname(), request.description(), request.imageUrl());
return UserUpdateResponse.from(user);
}

Expand Down

0 comments on commit f2840ba

Please sign in to comment.