Skip to content

Commit

Permalink
Merge pull request #228 from PawWithU/feat/227-voluteer-apply-fix
Browse files Browse the repository at this point in the history
[Feature] 이동봉사 신청 시 검증 로직 수정
  • Loading branch information
kyeong-hyeok authored Jun 3, 2024
2 parents ce79b52 + 1ae1a6c commit e89c105
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Application extends BaseTimeEntity {
private String phone; // 전화번호
@Column(length = 200, nullable = false)
private String content; // 전달 및 문의사항
@OneToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Post post; // 공고 id
@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pawwithu.connectdog.domain.application.repository;

import com.pawwithu.connectdog.domain.application.entity.Application;
import com.pawwithu.connectdog.domain.application.entity.ApplicationStatus;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -15,5 +16,6 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>
Optional<Application> findByIdAndIntermediaryId(Long id, Long intermediaryId);
Long countAllByPostId(Long id);
List<Application> findByVolunteer(Volunteer volunteer);
Optional<Application> findByPostIdAndStatusNot(Long postId, ApplicationStatus status);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public interface CustomApplicationRepository {
List<ApplicationVolunteerCompletedResponse> getVolunteerCompletedApplications(Long volunteerId, Pageable pageable);
List<ApplicationIntermediaryCompletedResponse> getIntermediaryCompletedApplications(Long intermediaryId, Pageable pageable);
List<Tuple> getCountOfApplicationsByStatus(Long id);
boolean existsByPostIdAndPostStatus(Long postId);
void updateExpiredApplications(LocalDate today);
List<Application> getYesterdayExpiredApplications(LocalDate date);
List<Application> getExpiredProgressingPosts(LocalDate date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.pawwithu.connectdog.domain.application.entity.ApplicationStatus;
import com.pawwithu.connectdog.domain.application.repository.CustomApplicationRepository;
import com.pawwithu.connectdog.domain.post.entity.Post;
import com.pawwithu.connectdog.domain.post.entity.PostStatus;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand Down Expand Up @@ -185,16 +186,6 @@ public List<Tuple> getCountOfApplicationsByStatus(Long id) {
.fetch();
}

@Override
public boolean existsByPostIdAndPostStatus(Long postId) {
return queryFactory
.select(application)
.from(application)
.where(application.post.id.eq(postId)
.and(application.status.ne(ApplicationStatus.REJECTED)))
.fetchOne() != null;
}

// 어제 모집 마감된 신청 가져오기
@Override
public List<Application> getYesterdayExpiredApplications(LocalDate date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ public void volunteerApply(String email, Long postId, VolunteerApplyRequest requ
// 이동봉사자
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
// 공고
Post post = postRepository.findById(postId).orElseThrow(() -> new BadRequestException(POST_NOT_FOUND));
Post post = postRepository.findByIdAndStatus(postId, PostStatus.RECRUITING).orElseThrow(() -> new BadRequestException(POST_NOT_FOUND));
// 이동봉사 중개
Intermediary intermediary = post.getIntermediary();
// 해당 공고에 대한 신청이 이미 존재할 경우 - 신청 상태가 반려가 아닐 경우
if (customApplicationRepository.existsByPostIdAndPostStatus(postId)) {
throw new BadRequestException(ALREADY_EXIST_APPLICATION);
}
// 해당 공고에 대한 신청이 이미 존재할 경우 예외 처리 - 신청 상태가 반려가 아닐 경우
applicationRepository.findByPostIdAndStatusNot(postId, ApplicationStatus.REJECTED)
.ifPresent(application -> {
throw new BadRequestException(ALREADY_EXIST_APPLICATION);
});
// 공고 신청 저장
Application application = request.toEntity(post, intermediary, volunteer);
applicationRepository.save(application);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.pawwithu.connectdog.domain.post.repository;

import com.pawwithu.connectdog.domain.post.entity.Post;
import com.pawwithu.connectdog.domain.post.entity.PostStatus;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface PostRepository extends JpaRepository<Post, Long> {

Optional<Post> findByIdAndIntermediaryId(Long id, Long intermediaryId);
Optional<Post> findByIdAndStatus(Long id, PostStatus postStatus);
}

0 comments on commit e89c105

Please sign in to comment.