Skip to content

Commit

Permalink
Merge pull request #7 from codestates-seb/be
Browse files Browse the repository at this point in the history
Be
  • Loading branch information
windeer9 authored Sep 12, 2023
2 parents 00e26bc + 078e9ec commit 3a9e919
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Getter @Setter
public class PostPostDto { // ์ƒ์„ฑ

private Long userId;
//private Long userId;

private String type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Setter
public class UserPostDto { // ๊ฐ€์ž…

private Long userId;
//private Long userId;

private String username;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -37,15 +38,22 @@ public User createUser(UserPostDto userPostDto, String imageUrl) {

// ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ
user.setImageUrl(imageUrl);
user.setCreateAt(LocalDateTime.now());

updateGradePostCount(user);

return userRepository.save(user);
}

// ์‚ฌ์šฉ์ž ์กฐํšŒ
public User getUser(Long userId) {

Optional<User> userOptional = userRepository.findById(userId);
return userOptional.orElseThrow(() -> new BusinessLogicException(ExceptionCode.USER_NOT_FOUND));
User findUser = userRepository.findById(userId)
.orElseThrow(() -> new BusinessLogicException(ExceptionCode.USER_NOT_FOUND));

updateGradePostCount(findUser);

return findUser;

}

Expand All @@ -58,13 +66,17 @@ public boolean verifyAnswer(Long userId, String answer) {

// ์‚ฌ์šฉ์ž ์ˆ˜์ •
public User updateUser(Long userId, UserPatchDto userPatchDto) {

User existing = getUser(userId);

existing.setUserName(userPatchDto.getUsername());
existing.setPassword(userPatchDto.getPassword());
existing.setPasswordQuestion(userPatchDto.getPasswordQuestion());
existing.setPasswordAnswer(userPatchDto.getPasswordAnswer());
existing.setImageUrl(userPatchDto.getImageUrl());
Optional.ofNullable(userPatchDto.getUsername()).ifPresent(username -> existing.setUserName(username));
Optional.ofNullable(userPatchDto.getPassword()).ifPresent(password -> existing.setPassword(password));
Optional.ofNullable(userPatchDto.getPasswordQuestion()).ifPresent(passwordQuestion -> existing.setPasswordQuestion(passwordQuestion));
Optional.ofNullable(userPatchDto.getPasswordAnswer()).ifPresent(passwordAnswer -> existing.setPasswordAnswer(passwordAnswer));
Optional.ofNullable(userPatchDto.getImageUrl()).ifPresent(imageUrl -> existing.setImageUrl(imageUrl));

updateGradePostCount(existing);


return userRepository.save(existing);
}
Expand Down

0 comments on commit 3a9e919

Please sign in to comment.