Skip to content

Commit

Permalink
[FIX] 프로젝트 취소 시 요청들 모두 취소하기 구현 (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
happyjamy committed Feb 21, 2024
1 parent a735e24 commit 4988494
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.oeid.mogakgo.domain.user.domain.User;
import io.oeid.mogakgo.domain.user.exception.UserException;
import io.oeid.mogakgo.domain.user.infrastructure.UserJpaRepository;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -77,11 +76,6 @@ public Long create(Long userId, ProjectCreateReq request) {
return project.getId();
}

private boolean isExistsNotEndProjectCard(User tokenUser) {
return !projectJpaRepository.findNotEndProjectOneByCreatorId(tokenUser.getId(),
PageRequest.of(0, 1)).isEmpty();
}

@Transactional
public void delete(Long userId, Long projectId) {
// 유저 존재 여부 체크
Expand All @@ -94,6 +88,7 @@ public void delete(Long userId, Long projectId) {
project.delete(user);
}

@Transactional
public void cancel(Long userId, Long projectId) {
// 유저 존재 여부 체크
User user = getUser(userId);
Expand All @@ -106,6 +101,9 @@ public void cancel(Long userId, Long projectId) {

// 프로젝트 취소
project.cancel(user, projectHasReq);

// 프로젝트가 받은 모든 요청 거절
projectJoinRequestJpaRepository.rejectAllByProjectId(projectId);
}

public CursorPaginationResult<projectJoinRequestRes> getJoinRequest(
Expand Down Expand Up @@ -160,6 +158,11 @@ public ProjectDensityRankRes getDensityRankProjects() {
return new ProjectDensityRankRes(regionRankList);
}

private boolean isExistsNotEndProjectCard(User tokenUser) {
return !projectJpaRepository.findNotEndProjectOneByCreatorId(tokenUser.getId(),
PageRequest.of(0, 1)).isEmpty();
}

private void fillWithDefaultRegionsIfNecessary(List<Region> regionRankList) {
if (regionRankList.size() < DENSITY_RANK_LIMIT) {
// 기본 지역 순위에서 이미 리스트에 있는 지역을 제외하고 남은 지역을 추가
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 @@ -23,4 +24,8 @@ 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.requestStatus = 'PENDING'")
int rejectAllByProjectId(Long projectId);

}

0 comments on commit 4988494

Please sign in to comment.