From ecf0bf69e6765f2b8bd75f09ff4bb8da09ef8ebf Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Sat, 9 Dec 2023 03:44:34 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20:=20=EC=9C=A0=EC=A0=80=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserImageController.java | 6 ++---- .../studyhubserver/user/dto/data/SignUpInfo.java | 4 ++-- .../studyhubserver/user/service/UserImageService.java | 7 +++---- .../studyhubserver/user/service/UserService.java | 3 ++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserImageController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserImageController.java index d3e390ac..5b7083b6 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserImageController.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/controller/UserImageController.java @@ -5,7 +5,6 @@ import kr.co.studyhubinu.studyhubserver.user.service.UserImageService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.catalina.User; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -23,17 +22,16 @@ public class UserImageController { @Operation(summary = "회원 사진 저장", description = "jwt 토큰 bearer 헤더에" + "보내주시면 됩니다") - @PostMapping("/v1/users/image") + @PutMapping("/v1/users/image") public ResponseEntity uploadImage(UserId userId, @RequestPart(name = "image", required = false) MultipartFile image) throws IOException { userImageService.uploadUserImage(userId.getId() ,image); - return new ResponseEntity<>(HttpStatus.OK); } @DeleteMapping("/v1/users/image") public ResponseEntity deleteImage(UserId userId) { userImageService.deleteUserImage(userId.getId()); - return new ResponseEntity<>(HttpStatus.OK); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); } } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/data/SignUpInfo.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/data/SignUpInfo.java index 61542a49..ed636de4 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/data/SignUpInfo.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/dto/data/SignUpInfo.java @@ -18,14 +18,14 @@ public class SignUpInfo { private MajorType major; private GenderType gender; private String accessToken; - private String refreshToken; - public UserEntity toEntity(PasswordEncoder passwordEncoder) { + public UserEntity toEntity(PasswordEncoder passwordEncoder, String basicProfileImage) { return UserEntity.builder() .email(email) .password(passwordEncoder.encode(email, password)) .nickname(nickname) + .imageUrl(basicProfileImage) .major(major) .gender(gender) .build(); diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserImageService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserImageService.java index d0a1f30d..7aa572de 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserImageService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserImageService.java @@ -20,12 +20,12 @@ @Slf4j @Transactional public class UserImageService { + private final UserRepository userRepository; private final AmazonS3 amazonS3; - @Value("${cloud.aws.s3.bucket}") private String bucket; - + private static final String BASIC_PROFILE_IMAGE = "https://studyhub-s3.s3.ap-northeast-2.amazonaws.com/avatar_l%401x.png"; public void uploadUserImage(Long userId, MultipartFile multipartFile) throws IOException { UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); @@ -35,7 +35,7 @@ public void uploadUserImage(Long userId, MultipartFile multipartFile) throws IOE public void deleteUserImage(Long userId) { UserEntity user = userRepository.findById(userId).orElseThrow(UserNotFoundException::new); - user.updateImage(null); + user.updateImage(BASIC_PROFILE_IMAGE); } private String saveImage(MultipartFile multipartFile) throws IOException { @@ -49,5 +49,4 @@ private String saveImage(MultipartFile multipartFile) throws IOException { return amazonS3.getUrl(bucket, originalFilename).toString(); } - } diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java index 73f6d9e5..a4d0e2a5 100644 --- a/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/user/service/UserService.java @@ -28,6 +28,7 @@ @Transactional(readOnly = true) public class UserService { + private static final String BASIC_PROFILE_IMAGE = "https://studyhub-s3.s3.ap-northeast-2.amazonaws.com/avatar_l%401x.png"; private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; private final UserActivityFinder userActivityFinder; @@ -37,7 +38,7 @@ public class UserService { @Transactional public void registerUser(SignUpInfo signUpInfo) { validateExistUserEmail(signUpInfo); - UserEntity userEntity = signUpInfo.toEntity(passwordEncoder); + UserEntity userEntity = signUpInfo.toEntity(passwordEncoder, BASIC_PROFILE_IMAGE); userRepository.save(userEntity); }