-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: 사용자 프로필 업데이트 기능 추가 * refactor: 도메인쪽으로 비즈니스 로직을 이동 * test: 기존의 터지던 테스트들을 수정 * test: 닉네임, 프로필 이미지 수정하는 메서드에 대한 테스트 코드 추가 * test: API 문서 수정 * feat: 로그인 할 때마다 로그인 정보 업데이트 되는 기능 삭제 * refactor: RequestParam을 ModelAttribute로 교체 * refactor: 리뷰 반영 * test: ControllerAdvice에 대한 테스트 코드 추가
- Loading branch information
1 parent
fdf5767
commit f459e68
Showing
20 changed files
with
309 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...end/src/main/java/com/darass/darass/exception/httpbasicexception/BadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.darass.darass.exception.httpbasicexception; | ||
|
||
public class BadRequestException extends CustomException { | ||
|
||
public BadRequestException(String message, Integer code) { | ||
super(message, code); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/com/darass/darass/user/S3ClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.darass.darass.user; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
@Configuration | ||
public class S3ClientConfig { | ||
@Bean | ||
public S3Client s3Client() { | ||
return S3Client.builder() | ||
.region(Region.AP_NORTHEAST_2) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
backend/src/main/java/com/darass/darass/user/dto/UserUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
package com.darass.darass.user.dto; | ||
|
||
import javax.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class UserUpdateRequest { | ||
|
||
@NotNull | ||
private String nickName; | ||
|
||
private MultipartFile profileImageFile; | ||
|
||
} | ||
|
60 changes: 60 additions & 0 deletions
60
backend/src/main/java/com/darass/darass/user/infrastructure/S3Uploader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.darass.darass.user.infrastructure; | ||
|
||
import com.darass.darass.exception.ExceptionWithMessageAndCode; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Date; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import software.amazon.awssdk.core.exception.SdkClientException; | ||
import software.amazon.awssdk.core.sync.RequestBody; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class S3Uploader { | ||
|
||
private static final String S3_BUCKET_NAME = "darass-user-profile-image"; | ||
private static final String CLOUDFRONT_URL = "https://d3qmnph7nb4773.cloudfront.net/"; | ||
private final S3Client s3; | ||
|
||
public String upload(MultipartFile multipartFile) { | ||
File uploadFile = convert(multipartFile); | ||
String uploadFileUrl = uploadToS3(uploadFile); | ||
return uploadFileUrl; | ||
} | ||
|
||
private File convert(MultipartFile multipartFile) { | ||
File file = new File(multipartFile.getOriginalFilename()); | ||
try (FileOutputStream fos = new FileOutputStream(file)) { | ||
fos.write(multipartFile.getBytes()); | ||
} catch (IOException e) { | ||
throw ExceptionWithMessageAndCode.IO_EXCEPTION.getException(); | ||
} | ||
return file; | ||
} | ||
|
||
private String uploadToS3(File uploadFile) { | ||
String fileName = new Date().getTime() + uploadFile.getName(); | ||
PutObjectRequest objectRequest = PutObjectRequest.builder() | ||
.bucket(S3_BUCKET_NAME) | ||
.key(fileName) | ||
.build(); | ||
try { | ||
s3.putObject(objectRequest, RequestBody.fromFile(uploadFile)); | ||
} catch (SdkClientException e) { | ||
throw ExceptionWithMessageAndCode.INTERNAL_SERVER.getException(); | ||
} finally { | ||
removeNewFile(uploadFile); | ||
} | ||
String uploadFileUrl = CLOUDFRONT_URL + fileName; | ||
return uploadFileUrl; | ||
} | ||
|
||
private void removeNewFile(File uploadFile) { | ||
uploadFile.delete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,35 +67,20 @@ void oauthLogin_register() { | |
} | ||
|
||
@Transactional | ||
@DisplayName("(로그인 - 이미 DB에 회원정보가 있는경우) login 메서드는 oauth 토큰이 주어지면, 인증서버에서 사용자 정보를 받아와서 DB 업데이트를 하고 primary key를 payload 삼아 accessToken을 리턴한다.") | ||
@DisplayName("(로그인 - 이미 DB에 회원정보가 있는경우) login 메서드는 oauth 토큰이 주어지면, primary key를 payload 삼아 accessToken을 리턴한다.") | ||
@Test | ||
void oauthLogin_login() { | ||
//given | ||
socialLoginUserRepository.save(socialLoginUser); | ||
|
||
SocialLoginUser updatedSocialLoginUser = SocialLoginUser | ||
.builder() | ||
.nickName("병욱") | ||
.oauthId(socialLoginUser.getOauthId()) | ||
.oauthProviderType(OAuthProviderType.KAKAO) | ||
.email("[email protected]") | ||
.profileImageUrl("http://kakao/updated_profile_image.png") | ||
.build(); | ||
|
||
given(oAuthProvider.findSocialLoginUser(any(), any())).willReturn(updatedSocialLoginUser); | ||
given(oAuthProvider.findSocialLoginUser(any(), any())).willReturn(socialLoginUser); | ||
|
||
//then | ||
TokenResponse tokenResponse = oAuthService.oauthLogin(OAuthProviderType.KAKAO.getName(), oauthAccessToken); | ||
|
||
//when | ||
String payload = jwtTokenProvider.getPayload(tokenResponse.getAccessToken()); | ||
|
||
SocialLoginUser result = socialLoginUserRepository.findById(Long.parseLong(payload)).get(); | ||
assertThat(result.getNickName()).isEqualTo(updatedSocialLoginUser.getNickName()); | ||
assertThat(result.getProfileImageUrl()).isEqualTo(updatedSocialLoginUser.getProfileImageUrl()); | ||
assertThat(result.getOauthId()).isEqualTo(updatedSocialLoginUser.getOauthId()); | ||
assertThat(result.getOauthProviderType()).isEqualTo(updatedSocialLoginUser.getOauthProviderType()); | ||
assertThat(result.getEmail()).isEqualTo(updatedSocialLoginUser.getEmail()); | ||
assertThat(payload).isNotNull(); | ||
} | ||
|
||
@DisplayName("findSocialLoginUserByAccessToken 메서드는 accessToken이 주어지면 SocialLoginUser를 리턴한다.") | ||
|
Oops, something went wrong.