Skip to content

Commit

Permalink
Merge pull request #110 from Leets-Official/fix/#109/프로필-수정시-파일-저장-로직-수정
Browse files Browse the repository at this point in the history
[fix] #110 프로필 수정시 파일 저장 로직 수정
  • Loading branch information
jwnnoh authored Apr 4, 2024
2 parents a5cc241 + ad3493a commit 288e6f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import org.example.weneedbe.domain.user.dto.response.mypage.*;
import org.example.weneedbe.domain.user.service.UserService;
import org.example.weneedbe.global.error.ErrorResponse;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "User MyPage Controller", description = "사용자의 마이페이지 관련 API입니다.")
@RestController
Expand Down Expand Up @@ -50,11 +48,10 @@ public ResponseEntity<BasicInfoResponse> getInfo(@RequestParam int size, @Reques
@ApiResponse(responseCode = "401", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PatchMapping(value = "/my-info", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PatchMapping(value = "/my-info")
public ResponseEntity<EditMyInfoResponse> editInfo(@RequestHeader("Authorization") String authorizationHeader,
@RequestPart(required = false) MultipartFile profileImage,
@RequestPart EditMyInfoRequest request) throws IOException {
return ResponseEntity.ok(userService.editInfo(authorizationHeader, profileImage, request));
@RequestBody EditMyInfoRequest request) throws IOException {
return ResponseEntity.ok(userService.editInfo(authorizationHeader, request));
}

@Operation(summary = "마이페이지의 관심 크루 조회", description = "사용자가 북마크한 팀원모집 게시물을 조회합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class EditMyInfoRequest {
private Fields interestField;
private List<String> links;
private String selfIntro;
private String profileImageUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Service
@Slf4j
Expand Down Expand Up @@ -70,16 +68,18 @@ public ResponseEntity<UserInfoResponse> setInfo(UserInfoRequest request, String
return new ResponseEntity<>(new UserInfoResponse(true, "상세 정보 입력 성공"), HttpStatus.OK);
}

public EditMyInfoResponse editInfo(String authorizationHeader, MultipartFile profileImage, EditMyInfoRequest request) throws IOException {
public EditMyInfoResponse editInfo(String authorizationHeader, EditMyInfoRequest request) {
User user = findUser(authorizationHeader);

String profileImageUrl = user.getProfile();
String requestImageUrl = request.getProfileImageUrl();

try {
if (profileImage != null) {
if (requestImageUrl != null) {
if (profileImageUrl != null) {
s3Service.deleteFile(user.getProfile());
s3Service.deleteFile(profileImageUrl);
}
profileImageUrl = s3Service.uploadImage(profileImage);
profileImageUrl = requestImageUrl;
}
user.editUserInfo(profileImageUrl,
request.getNickname(),
Expand Down

0 comments on commit 288e6f0

Please sign in to comment.