-
Notifications
You must be signed in to change notification settings - Fork 0
test : user/file/content/subscribe/submission/activity domain 테스트 코드 작성 #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0c4321b
cb842c8
5473228
1e7de41
1de7b4a
a2460dd
6aec007
19128ee
f996d57
7a79e07
a6b936a
2c0029f
415d9e6
e5477b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,16 @@ | |
| import com.formssafe.global.error.ErrorCode; | ||
| import com.formssafe.global.error.type.BadRequestException; | ||
| import com.formssafe.global.util.DateTimeUtil; | ||
| import java.time.LocalDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
| @Transactional(readOnly = true) | ||
| @RequiredArgsConstructor | ||
|
|
@@ -105,7 +106,7 @@ public void modify(long formId, SubmissionCreateDto request, LoginUserDto loginU | |
| } | ||
| } | ||
|
|
||
| public SubmissionResponseDto getSubmission(long formId, LoginUserDto loginUser) { | ||
| public SubmissionResponseDto getTempSubmission(long formId, LoginUserDto loginUser) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null을 반환할 수 있다면 Optional로 감싸면 어떨까요? nullable한 값을 반환할 수 있다는 걸 명시할 수 있으니 좋을 것 같습니다. |
||
| User user = userService.getUserById(loginUser.id()); | ||
|
|
||
| Submission submission = submissionRepository.findSubmissionByFormIDAndUserId(formId, loginUser.id()) | ||
|
|
@@ -119,6 +120,10 @@ public SubmissionResponseDto getSubmission(long formId, LoginUserDto loginUser) | |
| return SubmissionResponseDto.from(formId, submissionDetailResponseDtos, submission.isTemp()); | ||
| } | ||
|
|
||
| public Submission getSubmission(long formId, LoginUserDto loginUser) { | ||
| return submissionRepository.findSubmissionByFormIDAndUserId(formId, loginUser.id()).orElse(null); | ||
| } | ||
|
|
||
| public List<SubmissionDetailResponseDto> getSubmissionDetailDto(Submission submission) { | ||
| List<Object> submissions = new ArrayList<>(); | ||
| submissions.addAll(getDescriptiveSubmissionFromSubmission(submission)); | ||
|
|
@@ -200,6 +205,10 @@ private void createDetailSubmission(List<SubmissionDetailDto> submissionDetailDt | |
| } | ||
| descriptiveSubmissionRepository.saveAll(descriptiveSubmissions); | ||
| objectiveSubmissionRepository.saveAll(objectiveSubmissions); | ||
|
|
||
| //TODO : 확인 필요 | ||
| submission.getDescriptiveSubmissionList().addAll(descriptiveSubmissions); | ||
| submission.getObjectiveSubmissionList().addAll(objectiveSubmissions); | ||
| } | ||
|
|
||
| private void validate(User user, Form form) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,10 +31,8 @@ public class UserService { | |
| private final UserValidateService userValidateService; | ||
|
|
||
| public User getUserById(Long id) { | ||
| User user = userRepository.findById(id) | ||
| return userRepository.findById(id) | ||
| .orElseThrow(() -> new UserNotFoundException(ErrorCode.USER_NOT_FOUND, "존재하지 않는 userId 입니다 : " + id)); | ||
|
|
||
| return user; | ||
| } | ||
|
|
||
| @Transactional | ||
|
|
@@ -43,6 +41,7 @@ public void join(JoinDto request, LoginUserDto loginUser) { | |
| if (user.isActive()) { | ||
| throw new BadRequestException(ErrorCode.USER_ALREADY_JOIN, "이미 회원가입하셨습니다."); | ||
| } | ||
| verifyNickname(request.nickname()); | ||
|
|
||
| user.updateNickname(request.nickname()); | ||
| user.activate(); | ||
|
|
@@ -57,15 +56,18 @@ public UserProfileDto getProfile(LoginUserDto loginUser) { | |
| @Transactional | ||
| public void updateNickname(NicknameUpdateDto request, LoginUserDto loginUser) { | ||
| String nickname = request.nickname(); | ||
| userValidateService.validUserNickname(nickname); | ||
| verifyNickname(nickname); | ||
|
|
||
| User user = getUserById(loginUser.id()); | ||
| user.updateNickname(request.nickname()); | ||
| } | ||
|
|
||
| if (user.getNickname().equals(nickname) || userRepository.existsByNickname(nickname)) { | ||
| private void verifyNickname(String nickname) { | ||
| userValidateService.validUserNickname(nickname); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 내부에서 닉네임 길이 유효성 검사만 하고 있으니 validUserNicknameLength()로 구체화하면 어떨까요? 메서드명만 봤을 때 verifyNickname()과 무엇이 다른지 구분이 어렵습니다. |
||
|
|
||
| if (userRepository.existsByNickname(nickname)) { | ||
| throw new BadRequestException(ErrorCode.USER_NICKNAME_DUPLICATE, "중복된 닉네임이 존재합니다."); | ||
| } | ||
|
|
||
| user.updateNickname(request.nickname()); | ||
| } | ||
|
|
||
| @Transactional | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용하지 않는 파라미터는 삭제 부탁드립니다!