Skip to content

Commit

Permalink
refactor(#151): 코드 개선
Browse files Browse the repository at this point in the history
- 검증 로직에서 레포지토리 사용을 최소화했어요.
  • Loading branch information
jyj1289 committed Oct 13, 2024
1 parent f120f2f commit 6ed30bb
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@RequiredArgsConstructor
@UseCase
public class SubmitFormUseCase {
Expand Down Expand Up @@ -39,9 +41,10 @@ public void execute(User user, SubmitFormRequest request) {
}

private void validateOnlyOneFormPerUser(User user) {
if (formRepository.existsByUserId(user.getId())) {
if (formRepository.findByUser(user).get().isRejected()) {
formRepository.deleteByUser(user);
Optional<Form> form = formRepository.findByUser(user);
if (form.isPresent()) {
if (form.get().isRejected()) {
formRepository.delete(form.get());
return;
}
throw new FormAlreadySubmittedException();
Expand Down

0 comments on commit 6ed30bb

Please sign in to comment.