Skip to content

Commit

Permalink
[FIX] 매칭 생성 시 해당 프로젝트 다른 요청들 거절하는 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
happyjamy committed Feb 20, 2024
1 parent b66d4d0 commit 2f67413
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import io.oeid.mogakgo.domain.project_join_req.domain.entity.ProjectJoinRequest;
import io.oeid.mogakgo.domain.project_join_req.exception.ProjectJoinRequestException;
import io.oeid.mogakgo.domain.project_join_req.infrastructure.ProjectJoinRequestJpaRepository;
import io.oeid.mogakgo.domain.user.application.UserCommonService;
import io.oeid.mogakgo.domain.project_join_req.presentation.dto.res.ProjectJoinRequestDetailAPIRes;
import io.oeid.mogakgo.domain.user.application.UserCommonService;
import io.oeid.mogakgo.domain.user.domain.User;
import io.oeid.mogakgo.domain.user.exception.UserException;
import io.oeid.mogakgo.domain.user.infrastructure.UserJpaRepository;
Expand Down Expand Up @@ -86,6 +86,11 @@ public Long accept(Long userId, Long projectRequestId) {
Long matchingId = matchingService.create(projectJoinRequest);
//----

// 프로젝트에 대한 요청들 수락 되지 않은 것들 다 거절 처리
// 비동기 가능
projectJoinRequestRepository.rejectNoAcceptedByProjectId(
projectJoinRequest.getProject().getId(), projectJoinRequest.getId());

// 내가 보낸 대기 중 요청이 있으면 취소 처리
// 여기서 나는 에러는 클라와 상관이 없으므로 에러가 발생해도 넘어갈 수 있게 처리.
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Optional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface ProjectJoinRequestJpaRepository extends JpaRepository<ProjectJoinRequest, Long>,
Expand All @@ -13,7 +14,6 @@ public interface ProjectJoinRequestJpaRepository extends JpaRepository<ProjectJo
@Query("select pjr from ProjectJoinRequest pjr where pjr.id = :id")
Optional<ProjectJoinRequest> findByIdWithProject(Long id);


@Query("select pjr from ProjectJoinRequest pjr where pjr.sender.id = :senderId and pjr.requestStatus = 'PENDING'")
Optional<ProjectJoinRequest> findPendingBySenderId(Long senderId);

Expand All @@ -23,4 +23,9 @@ public interface ProjectJoinRequestJpaRepository extends JpaRepository<ProjectJo
@Query("select pjr from ProjectJoinRequest pjr where pjr.sender.id = :userId")
Optional<ProjectJoinRequest> findAlreadyExistsAnotherJoinReq(Long userId);

@Modifying
@Query("update ProjectJoinRequest pjr set pjr.requestStatus = 'REJECTED' "
+ "where pjr.project.id = :projectId and pjr.id != :acceptedRequestId and pjr.requestStatus = 'PENDING'")
int rejectNoAcceptedByProjectId(Long projectId, Long acceptedRequestId);

}

0 comments on commit 2f67413

Please sign in to comment.