Skip to content

Commit

Permalink
Merge pull request #57 from study-hub-inu/feat/SH-252-user-profile-image
Browse files Browse the repository at this point in the history
[Feat] : 유저 기본 이미지 설정
  • Loading branch information
wellbeing-dough authored Dec 9, 2023
2 parents 0f44576 + ecf0bf6 commit 8e7ce03
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -23,17 +22,16 @@ public class UserImageController {

@Operation(summary = "회원 사진 저장", description = "jwt 토큰 bearer 헤더에" +
"보내주시면 됩니다")
@PostMapping("/v1/users/image")
@PutMapping("/v1/users/image")
public ResponseEntity<HttpStatus> 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<HttpStatus> deleteImage(UserId userId) {
userImageService.deleteUserImage(userId.getId());
return new ResponseEntity<>(HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -49,5 +49,4 @@ private String saveImage(MultipartFile multipartFile) throws IOException {
return amazonS3.getUrl(bucket, originalFilename).toString();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand Down

0 comments on commit 8e7ce03

Please sign in to comment.