feat: 전체 뉴스를 조회하는 API 구현#674
Conversation
- 기존 API에 author-id를 선택적으로 받도록
- 서비스 계층에서 siteUserId == null을 기준으로 분기하도록
- 분기를 서비스 계층에게 위임했음
Walkthrough뉴스 조회 기능이 보다 유연하게 개선되었습니다. 컨트롤러의 GET 핸들러가 Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
변경사항 상세 분석다음과 같이 5가지 주요 변경이 포함되어 있습니다.
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/java/com/example/solidconnection/news/repository/custom/NewsCustomRepositoryImpl.java (1)
15-35: JPQL 쿼리 중복이 존재합니다.
findAllNewsWithLikeStatus와findNewsByAuthorIdWithLikeStatus(Line 37-59)의 SELECT 절과 JOIN 절이 거의 동일하고, WHERE 절 유무만 다릅니다. 현재 메서드가 2개라 관리 부담이 크지 않지만, 향후 SELECT 필드가 변경되면 두 곳을 동시에 수정해야 하는 점은 인지해두시면 좋겠습니다.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/com/example/solidconnection/news/repository/custom/NewsCustomRepositoryImpl.java` around lines 15 - 35, The SELECT and LEFT JOIN parts used by findAllNewsWithLikeStatus and findNewsByAuthorIdWithLikeStatus are duplicated; extract the common JPQL SELECT/JOIN into a single reusable constant or private helper method (e.g., BASE_NEWS_JPQL or buildBaseNewsQuery()) that returns the SELECT ... FROM ... LEFT JOIN portion, then have findAllNewsWithLikeStatus append no WHERE and findNewsByAuthorIdWithLikeStatus append "WHERE n.authorId = :authorId" (or similar) to that base string, and update both methods to call entityManager.createQuery on the composed JPQL and set only the necessary parameters (siteUserId and optionally authorId). Ensure NewsResponse constructor usage and parameter names remain unchanged.src/test/java/com/example/solidconnection/news/service/NewsQueryServiceTest.java (1)
114-178: 특정 사용자의 소식지 조회에서 빈 목록 테스트가 누락되었습니다.
전체_소식지를_조회한다그룹에는 빈 목록 반환 테스트가 있지만(Line 104-111),특정_사용자의_소식지를_조회한다그룹에는 해당 작성자의 소식지가 없을 때의 테스트가 빠져 있습니다. 대칭적인 커버리지를 위해 추가를 권장합니다.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/com/example/solidconnection/news/service/NewsQueryServiceTest.java` around lines 114 - 178, Add a missing empty-list test inside the nested class 특정_사용자의_소식지를_조회한다: create an author SiteUser with no News fixtures, call newsQueryService.findNews(null, author.getId()), and assert that the returned NewsListResponse.newsResponseList() is empty and any isLiked values are null (use NewsListResponse, NewsResponse, and findNews to locate code). Name the test clearly (e.g., 작성자의_소식지가_없으면_빈_목록을_반환한다) and mirror the assertions style used in the 전체_소식지를_조회한다 empty-list test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@src/main/java/com/example/solidconnection/news/repository/custom/NewsCustomRepositoryImpl.java`:
- Around line 15-35: The SELECT and LEFT JOIN parts used by
findAllNewsWithLikeStatus and findNewsByAuthorIdWithLikeStatus are duplicated;
extract the common JPQL SELECT/JOIN into a single reusable constant or private
helper method (e.g., BASE_NEWS_JPQL or buildBaseNewsQuery()) that returns the
SELECT ... FROM ... LEFT JOIN portion, then have findAllNewsWithLikeStatus
append no WHERE and findNewsByAuthorIdWithLikeStatus append "WHERE n.authorId =
:authorId" (or similar) to that base string, and update both methods to call
entityManager.createQuery on the composed JPQL and set only the necessary
parameters (siteUserId and optionally authorId). Ensure NewsResponse constructor
usage and parameter names remain unchanged.
In
`@src/test/java/com/example/solidconnection/news/service/NewsQueryServiceTest.java`:
- Around line 114-178: Add a missing empty-list test inside the nested class
특정_사용자의_소식지를_조회한다: create an author SiteUser with no News fixtures, call
newsQueryService.findNews(null, author.getId()), and assert that the returned
NewsListResponse.newsResponseList() is empty and any isLiked values are null
(use NewsListResponse, NewsResponse, and findNews to locate code). Name the test
clearly (e.g., 작성자의_소식지가_없으면_빈_목록을_반환한다) and mirror the assertions style used in
the 전체_소식지를_조회한다 empty-list test.
* feat: 전체 news 조회 API 구현 - 기존 API에 author-id를 선택적으로 받도록 * test: 전체 news 조회 관련 테스트 코드 작성 * refactor: 날짜 오름차순으로 news 조회하는 JPA 메서드 추가 * refactor: 뉴스 조회 API를 하나로 통합 - 서비스 계층에서 siteUserId == null을 기준으로 분기하도록 * refactor: 컨트롤러 계층에서 분기문 제거 - 분기를 서비스 계층에게 위임했음 * test: 뉴스 조회 관련 테스트 코드 수정
* feat: 파견 대학 테이블명 변경 및 협정 대학 테이블 추가하는 DDL 작성 (#620) * feat: 파견 대학 테이블명 변경 및 협정 대학 테이블 추가하는 DDL 작성 * refactor: 테이블명 변경 및 추가에 따른 엔티티 생성 - 또한 목데이터 생성 로직 수정 * test: 테스트 코드에서 University -> HostUniversity로 변경 * chore: 중복 인덱스 생성 방지를 위해 인덱스 생성 제거 - FK 제약조건을 추가할 때 인덱스가 없다면 알아서 추가하기 때문 * chore: home_university 테이블에 created/updated_at 추가 * refactor: 잘못 설정되었던 테이블 간 연관 관계 재설정 (#622) * refactor: home_university와 university_info_for_apply가 FK 관계를 가지도록 * chore: FK 변경에 따른 목데이터 수정 * test: 테스트 픽스터 수정 * refactor: 대학 검색 응답 수정 (#624) * refactor: home_university와 university_info_for_apply가 FK 관계를 가지도록 * chore: FK 변경에 따른 목데이터 수정 * refactor: 필터 검색 엔드포인트 삭제 * refactor: 필터 검색 관련 서비스 로직 삭제 * refactor: 필터 검색 관련 레포지토리 메서드 삭제 * refactor: 필터 검색 관련 DTO 삭제 * test: 필터 검색 관련 테스트 코드 삭제 * refactor: 지원 대학 관련 응답에 협정 대학 이름 추가 * test: 지원 대학 응답 수정에 따른 테스트 수정 * refactor: 간접 참조 대신 연관관계 추가 - N+1 방지를 위해 fetch join도 추가 * test: 간접 참조 방식에서 연관 관계 설정으로 따른 테스트 코드 수정 * chore: 목데이터에서 지원 대학 테이블에 협정 대학 ID를 설정하도록 * test: home university fixture 추가 * refactor: home university에 대한 fetch join 추가 * refactor: s3 버전 업그레이드 및 로직 수정 (#608) * refactor: s3 sdk 버전 업그레이드 - 의존성 수정 - 버전 업그레이드에 따른 코드 수정 * refactor: 이미지 이외의 파일 관리를 위해 ImgType 의미 명확하도록 수정 - ImgType에서 UploadType으로 변경 - 해당되는 파일 모두 수정 * refactor: s3 테스트 코드 추가 * fix: s3 access-key, secret-key 최신화, 버킷 명칭 올바르게 수정 * fix: ChatService Test 변경점 반영, S3ServiceTest 단위 테스트로 변경 - images->files로 디렉토리 경로 수정 * fix: 이중 비동기 실행문제 해결 - @async에 전적으로 위임 * refactor: S3Service error 메시지 NPE 가능성 제거 * refactor: 수정사항 반영 - UploadType -> UploadPath로 명칭변경 - 컨벤션 수정(미사용 변수 삭제, 들여쓰기, 명칭변경) * fix: 테스트 코드 오류 수정 - 내부 로직에서 사용하는 fileUploadService 정의 * refactor: 수정사항 반영 - 파일 확장자 상수화 - 확장자 확인로직, 채팅이면 모든 파일 허용, 이미지 확인까지 모두 enum에서 관리 - MultipartFile이 비동기 과정에서 유실되지 않도록 byte로 변환해서 전달 - UrlPrefixResponse PascalCase로 변경 * refactor: 컨벤션 수정 - 사용하지 않는 import문 삭제 * refactor: 리프레시 토큰 만료시 쿠키 삭제 (#628) * refactor: 리프레시 토큰 만료시 쿠키 삭제 * refactor: 인증 전용 예외 생성 * refactor: 멘토링 조회 응답에 mentoringId 필드 추가 (#638) * feat: WebSocket 로깅 인터셉터 작성 (#635) * feat: WebSocket 로깅 인터셉터 작성 * refactor: Principal 명시적 형 변환 대신 null 체크하여 형 변환 * feat: 어드민에서 파견 대학을 관리하도록 (#633) * feat: 파견 대학 CRUD 관련 ErrorCode 추가 - HOST_UNIVERSITY_HAS_REFERENCES : 파견 대학 삭제 시 해당 대학을 참조하는 UnivApplyInfo가 존재하는 경우 * feat: 파견 대학 관련 정보를 업데이트하는 도메인 메서드 작성 * feat: 조회 관련 Repository 메서드 구현 * feat: 파견 대학 검색 관련 QueryDSL로 구현 * feat: 어드민 파견 대학 CRUD 관련 DTO 작성 * feat: country 조회 관련 로직 추가 및 ErrorCode 추가 * feat: 어드민 파견 대학 CRUD 관련 서비스 로직 작성 * feat: 어드민 파견 대학 관련 컨트롤러 작성 * test: 어드민 파견 대학 관리 관련 테스트 작성 * refactor: 엔드포인트의 path variable 이름 변경 - id -> host-university-id * refactor: PageResponse 응답 객체를 사용하도록 * test: 응답 변경에 따른 테스트 코드 수정 * fix: host_university 테이블의 korean_name 필드에 unique key 추가 (#645) * fix: host_university 테이블의 korean_name 필드에 unique key 쿠가 * test: test용 hostUniversityRepository 생성 * test: 고유한 korean_name을 가진 host university 객체를 사용하도록 * fix: 멘토 지원서 승인 시 유저 Role 을 Mentor로 승격 (#639) * fix: 멘토 지원서 승인 시 유저 Role 을 Mentor로 승격 * fix: 멘토 지원서 승인 시 멘토 생성 * fix: 멘토의 introduction, passTip null 허용하도록 수정 - not null 인 필드에 빈문자열로 값을 채우는 것 보다, null 허용이 더 의미 있다 판단하여 null 을 허용하도록 하였습니다. * fix: 사용하지 않는 멘토 생성 api 제거 - 멘토 생성의 주체가 어드민으로 변경되어 Mentor 도메인의 Mentor 생성 api 를 제거 * feat: 멘토 지원서 승인 예외처리 추가 - 중복 멘토 생성 예외 처리 및 테스트 추가 * refactor: Mentor 생성 시 null 전달 제거 * refactor: 멘토 지원서 승낙 시, 검증 후 승격 및 멘토 생성 * chore: 스크립트 버전 수정 (#651) * chore: 스크립트 버전 수정 * test: korean_name 컬럼 UK 관련 테스트 코드 수정 * feat: test skill 추가 (#647) * feat: serena MCP 추가 * feat: test skill 추가 * feat: hook 추가 - 응답 대기시 알람발송 - 컨벤션 어겼을 때 훅 작동 * feat: 안쓰는 파일 제거 * fix: 게시글 중복 생성 방지 (#649) * fix: 게시글 중복 생성 방지 - Redis 패키지 및 로직 정리 * fix: 게시글 중복 생성 방지 - 게시글 중복 요청 방지 Redis 로직 추가 * refactor: 게시글 중복 생성 방지 * chore: testcontainer 버전 업 (#659) * chore: windows에서도 hook이 동작하도록 (#655) * refactor: 오래된 이미지 삭제 후 이미지 pull하도록 변경 (#653) refactor: 오래된 이미지 삭제 후 이미지 pull하도록 변경 (#653) - 추가로 이미지는 5개 -> 2개 보관하도록 변경 * refactor: 멘토 도메인 응답의 사용자 id를 siteUserId로 통일 (#665) * refactor: 멘토 관련 id응답은 모두 site-user-id가 되도록 수정 * test: 멘토 관련 테스트 코드 수정 * refactor: 채팅 도메인 응답의 사용자 관련 id를 siteUserId로 통일 (#666) * refactor: 채팅 관련 응답에서 사용자 관련 Id를 siteUserId로 통일 * refactor: siteUserId를 포함하도록 서비스 코드 수정 * test: 사용자 id로 응답 통일 관련 테스트 수정 * feat: 전체 뉴스를 조회하는 API 구현 (#674) * feat: 전체 news 조회 API 구현 - 기존 API에 author-id를 선택적으로 받도록 * test: 전체 news 조회 관련 테스트 코드 작성 * refactor: 날짜 오름차순으로 news 조회하는 JPA 메서드 추가 * refactor: 뉴스 조회 API를 하나로 통합 - 서비스 계층에서 siteUserId == null을 기준으로 분기하도록 * refactor: 컨트롤러 계층에서 분기문 제거 - 분기를 서비스 계층에게 위임했음 * test: 뉴스 조회 관련 테스트 코드 수정 * chore: 누락된 제약 조건을 추가하는 스크립트 작성 (#676) --------- Co-authored-by: Yeon <84384499+lsy1307@users.noreply.github.com> Co-authored-by: 황규혁 <126947828+Gyuhyeok99@users.noreply.github.com> Co-authored-by: hyungjun <115551339+sukangpunch@users.noreply.github.com> Co-authored-by: 정재희 <y2hjjh@naver.com>
관련 이슈
작업 내용
기존에는 특정
author-id의 뉴스만 조회 가능했으나, 전체 뉴스를 조회할 수 있도록 API를 수정했습니다.author-id를 선택적으로 받을 수 있도록 구현했습니다.repository 로직같은 경우 기존에 작성된 native query를 참고했습니다.
커밋 순으로 읽으시기보단, 전체 파일 변경 보시는 게 이해하기 더 쉬울 것 같습니다.
특이 사항
해당 PR은 머지 후 체리픽해서 prod에 반영할 예정입니다 ,,!
리뷰 요구사항 (선택)