Skip to content

Conversation

@Hyun0828
Copy link
Collaborator

@Hyun0828 Hyun0828 commented Sep 8, 2025

PR 타입(하나 이상의 PR 타입을 선택해주세요)

  • 기능 추가
  • 기능 삭제
  • 버그 수정
  • 의존성, 환경 변수, 빌드 관련 코드 업데이트
  • 리팩터링

반영 브랜치

dev -> main

작업 내용

[MERGE] dev->main 병합

테스트 결과

Summary by CodeRabbit

  • Refactor
    • 모든 포트 목록이 이제 ‘모집중’ 상태만 표시되며, 최신 생성순으로 정렬되어 일관된 탐색 경험을 제공합니다.
    • 역할(포지션) 필터 적용 시에도 ‘모집중’ 상태만 대상으로, 지원자 수 기준 정렬에 최신 생성순 우선 로직을 적용했습니다.
    • ‘내 포트’ 보기에서도 최신순 정렬로 통일하여 최근 생성한 포트를 빠르게 확인할 수 있습니다.

@coderabbitai
Copy link

coderabbitai bot commented Sep 8, 2025

Walkthrough

리포지토리에서 다수의 조회/삭제 메서드를 정리하고, potStatus 필터와 정렬(주로 createdAt DESC)을 명시적으로 적용하는 @Query/@param 기반 메서드로 대체했습니다. 서비스는 해당 변경에 맞춰 호출부를 갱신하여 RECRUITING 상태 중심의 페이징/정렬을 일관되게 사용합니다. 단건 삭제는 제거되고 사용자+포트폴리오 ID 목록 기반의 일괄 삭제가 추가되었습니다.

Changes

Cohort / File(s) Change Summary
Repository 정비 및 쿼리 명시화
src/main/java/stackpot/stackpot/pot/repository/PotRepository.java
- 메서드 제거: findByRecruitmentDetails_RecruitmentRole(...), findByUserId(...), findByPotMembers_User_Id(...), deleteByUserId(...)
- 시그니처 변경/대체: findByUserIdAndPotStatus(...)findByUserIdAndPotStatusOrderByCreatedAtDesc(...) (@Query/@param 적용, createdAt DESC 정렬)
- 상태 필터 추가: findAllOrderByApplicantsCountDesc(...), findByRecruitmentRolesInOrderByApplicantsCountDesc(...)potStatus 파라미터 추가
- 일괄 삭제 추가: deleteByUserIdAndPotIds(userId, potIds) (@Modifying, @transactional, JPQL 명시)
- 전반적으로 potStatus 필터와 정렬 기준을 @query로 명시
서비스 호출부 업데이트
src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java
- RECRUITING 상태 고정 필터 및 createdAt DESC 정렬을 사용하도록 레포지토리 호출 교체
- onlyMine 분기 및 역할 필터 경로에서 상태 파라미터와 정렬 일관화

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant S as PotQueryServiceImpl
  participant R as PotRepository

  rect rgb(240,248,255)
  note over C,S: 목록 페이징 조회 요청
  C->>S: getAllPotsWithPaging(userId, onlyMine, roles, pageable)
  alt onlyMine == true
    note right of S: 내 포트만, RECRUITING 필터
    S->>R: findByUserIdAndPotStatusOrderByCreatedAtDesc(userId, "RECRUITING", pageable)
    R-->>S: Page<Pot>
  else onlyMine == false and roles is empty
    note right of S: 전체, RECRUITING 필터<br/>지원자수 DESC 기반
    S->>R: findAllOrderByApplicantsCountDesc("RECRUITING", pageable)
    R-->>S: Page<Pot>
  else onlyMine == false and roles not empty
    note right of S: 역할 필터 + RECRUITING<br/>지원자수 DESC
    S->>R: findByRecruitmentRolesInOrderByApplicantsCountDesc(roles, "RECRUITING", pageable)
    R-->>S: Page<Pot>
  end
  S-->>C: Page<Pot>
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

:bug: bug

Poem

작은 냄비 탁—뚜껑을 열고 보니,
상태는 RECRUITING, 정렬은 척척이!
지원자 수 세며 춤추는 발끝,
createdAt 별빛 따라 한 줄로 딱딱.
휙—삭제는 묶음으로, 깔끔히 끝!
(ฅ•̀ᆽ•́)ฅ ʀᴀʙʙɪᴛ ᴀᴘᴘʀᴏᴠᴇᴅ 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java (1)

160-163: isMember 계산 로직 오류: 현재 분기에서는 항상 false 가능

RECRUITING 리스트에서 "COMPLETED".equals(pot.getPotStatus()) 조건 때문에 멤버 여부가 무조건 false가 됩니다. 저장된 memberPotIds 기준만 사용하세요.

-                    boolean isMember = "COMPLETED".equals(pot.getPotStatus()) && memberPotIds.contains(potId);
+                    boolean isMember = memberPotIds.contains(potId);
🧹 Nitpick comments (4)
src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java (3)

134-134: RECRUITING + createdAt DESC 적용은 적절. 상수/Enum 화 권장

  • "RECRUITING" 하드코딩 대신 공용 상수 또는 Enum(PotStatus)이면 안전합니다.
  • 대량 데이터 대비 (user_id, pot_status, created_at) 복합 인덱스 여부 확인 권장.

162-162: 메서드명 오타 의심: toPrviewDto → toPreviewDto

컨버터 시그니처를 변경할 수 있다면 정정 권장(프로젝트 전반 검색 필요). 호환성 위해 일시적으로 alias 추가도 고려.


133-133: 페이지 인덱스 가드 추가 권장

page가 1 미만으로 들어오면 IllegalArgumentException 위험. 최소 0으로 클램핑하세요.

-        Pageable pageable = PageRequest.of(page - 1, size);
+        int pageIndex = Math.max(0, page - 1);
+        Pageable pageable = PageRequest.of(pageIndex, size);
src/main/java/stackpot/stackpot/pot/repository/PotRepository.java (1)

28-31: OK — 사용자별 RECRUITING + createdAt DESC. 상수/Enum 및 인덱스 고려

  • "RECRUITING" 등 상태 문자열은 Enum(PotStatus, @Enumerated STRING) 또는 상수로 통일 권장.
  • (user.id, potStatus, createdAt) 복합 인덱스가 있으면 페이징 성능 안정적.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 493eafb and 1326116.

📒 Files selected for processing (2)
  • src/main/java/stackpot/stackpot/pot/repository/PotRepository.java (2 hunks)
  • src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java (2 hunks)
🔇 Additional comments (2)
src/main/java/stackpot/stackpot/pot/service/pot/PotQueryServiceImpl.java (2)

267-267: LGTM — 사용자 본인 필터에 createdAt DESC 정렬 일관 적용

레포지토리 시그니처 변경과 정렬 의도가 일치합니다.


270-273: 정렬 기준 제품 의도 확인 필요 (이름 vs 실제 정렬 불일치)

서비스에서는 “ApplicantsCountDesc” 메서드를 호출하지만, 레포의 JPQL은 createdAt 우선 정렬입니다. 제품 요구가 “지원자수 우선”인지 “최신순 우선”인지 확인 부탁. 레포 파일 코멘트에 수정 제안 포함했습니다.

Comment on lines +58 to 62
"WHERE p.potStatus = :potStatus " +
"GROUP BY p " +
"ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC")
Page<Pot> findAllOrderByApplicantsCountDesc(Pageable pageable);
"ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ")
Page<Pot> findAllOrderByApplicantsCountDesc(@Param("potStatus") String potStatus, Pageable pageable);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

메서드명-정렬 불일치 및 카운트 쿼리 부재

메서드명은 ApplicantsCountDesc지만 JPQL은 createdAt 우선입니다. 또한 GROUP BY가 있어 자동 count 쿼리 효율 저하 가능. 아래처럼 정렬 순서와 countQuery를 명시해주세요.

-    @Query("SELECT p FROM Pot p LEFT JOIN PotApplication pa ON p = pa.pot " +
-            "WHERE p.potStatus = :potStatus " +
-            "GROUP BY p " +
-            "ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ")
+    @Query(value = "SELECT p FROM Pot p LEFT JOIN p.potApplication pa " +
+            "WHERE p.potStatus = :potStatus " +
+            "GROUP BY p " +
+            "ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC",
+           countQuery = "SELECT COUNT(p) FROM Pot p WHERE p.potStatus = :potStatus")
     Page<Pot> findAllOrderByApplicantsCountDesc(@Param("potStatus") String potStatus, Pageable pageable);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"WHERE p.potStatus = :potStatus " +
"GROUP BY p " +
"ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC")
Page<Pot> findAllOrderByApplicantsCountDesc(Pageable pageable);
"ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ")
Page<Pot> findAllOrderByApplicantsCountDesc(@Param("potStatus") String potStatus, Pageable pageable);
@Query(value = "SELECT p FROM Pot p LEFT JOIN p.potApplication pa " +
"WHERE p.potStatus = :potStatus " +
"GROUP BY p " +
"ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC",
countQuery = "SELECT COUNT(p) FROM Pot p WHERE p.potStatus = :potStatus")
Page<Pot> findAllOrderByApplicantsCountDesc(@Param("potStatus") String potStatus, Pageable pageable);
🤖 Prompt for AI Agents
In src/main/java/stackpot/stackpot/pot/repository/PotRepository.java around
lines 58-62, the JPQL ordering is inconsistent with the method name (it orders
by createdAt first) and the GROUP BY will cause an inefficient automatic count;
change the main query ORDER BY to "COUNT(pa.applicationId) DESC, p.createdAt
DESC" to match ApplicantsCountDesc, and add an explicit countQuery (e.g. "SELECT
COUNT(DISTINCT p) FROM Pot p WHERE p.potStatus = :potStatus") on the @Query
annotation so Spring Data uses a simple count instead of a grouped count.

Comment on lines +67 to 71
"WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus " +
"GROUP BY p " +
"ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC")
Page<Pot> findByRecruitmentRolesInOrderByApplicantsCountDesc(@Param("roles") List<Role> roles, Pageable pageable);
"ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ")
Page<Pot> findByRecruitmentRolesInOrderByApplicantsCountDesc(@Param("roles") List<Role> roles, @Param("potStatus") String potStatus, Pageable pageable);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

집계 값 왜곡 가능성(CROSS JOIN 중복) 및 정렬 순서 수정 필요

prd/pa 이중 조인으로 pa 행이 곱연산되어 COUNT가 과대집계될 수 있습니다. DISTINCT로 방지하고, 정렬도 지원자 수 우선으로 수정, countQuery를 명시하세요.

-    @Query("SELECT p FROM Pot p " +
-            "LEFT JOIN PotRecruitmentDetails prd ON p = prd.pot " +
-            "LEFT JOIN PotApplication pa ON p = pa.pot " +
-            "WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus " +
-            "GROUP BY p " +
-            "ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ")
+    @Query(value = "SELECT p FROM Pot p " +
+            "LEFT JOIN p.recruitmentDetails prd " +
+            "LEFT JOIN p.potApplication pa " +
+            "WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus " +
+            "GROUP BY p " +
+            "ORDER BY COUNT(DISTINCT pa.applicationId) DESC, p.createdAt DESC",
+           countQuery = "SELECT COUNT(DISTINCT p.potId) FROM Pot p " +
+                        "LEFT JOIN p.recruitmentDetails prd " +
+                        "WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus")
     Page<Pot> findByRecruitmentRolesInOrderByApplicantsCountDesc(@Param("roles") List<Role> roles, @Param("potStatus") String potStatus, Pageable pageable);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus " +
"GROUP BY p " +
"ORDER BY COUNT(pa.applicationId) DESC, p.createdAt DESC")
Page<Pot> findByRecruitmentRolesInOrderByApplicantsCountDesc(@Param("roles") List<Role> roles, Pageable pageable);
"ORDER BY p.createdAt DESC, COUNT(pa.applicationId) DESC ")
Page<Pot> findByRecruitmentRolesInOrderByApplicantsCountDesc(@Param("roles") List<Role> roles, @Param("potStatus") String potStatus, Pageable pageable);
@Query(
value = "SELECT p FROM Pot p " +
"LEFT JOIN p.recruitmentDetails prd " +
"LEFT JOIN p.potApplication pa " +
"WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus " +
"GROUP BY p " +
"ORDER BY COUNT(DISTINCT pa.applicationId) DESC, p.createdAt DESC",
countQuery = "SELECT COUNT(DISTINCT p.potId) FROM Pot p " +
"LEFT JOIN p.recruitmentDetails prd " +
"WHERE prd.recruitmentRole IN :roles AND p.potStatus = :potStatus"
)
Page<Pot> findByRecruitmentRolesInOrderByApplicantsCountDesc(
@Param("roles") List<Role> roles,
@Param("potStatus") String potStatus,
Pageable pageable
);
🤖 Prompt for AI Agents
In src/main/java/stackpot/stackpot/pot/repository/PotRepository.java around
lines 67–71, the JPQL query can overcount applicants because the double join
(prd/pa) multiplies rows; update the query to use COUNT(DISTINCT
pa.applicationId) to avoid duplicate aggregation, ensure joins are LEFT JOINs so
pots with zero applicants are included, change ORDER BY to sort by applicants
count first then p.createdAt DESC, and add an explicit countQuery for pagination
that mirrors the joins (but without the SELECT clause aggregation) so Spring
Data Page counts are correct.

@Hyun0828 Hyun0828 merged commit 01967ac into main Sep 8, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants