[feat] AI 댓글 수동 할당 및 자동 감지 토글 API 추가#122
Conversation
k3vin7
commented
Mar 29, 2026
- POST /admin/ai-comments/posts/{postId}/assign: 관리자가 작곡가를 게시물에 직접 할당
- GET /admin/ai-comments/settings: 자동 감지 설정 조회
- PUT /admin/ai-comments/settings/auto-detect: 자동 감지 ON/OFF 토글
- ai_comment_settings 테이블 추가 (Flyway V12)
- 서비스 테스트 및 REST Docs 추가
There was a problem hiding this comment.
Code Review
This pull request introduces administrative controls for AI comments, including a toggle for auto-detection and a manual assignment feature. It adds a new AiCommentSettings entity, a corresponding repository, and an AiCommentAdminController to manage these settings. Security configurations were updated to restrict admin endpoints. Feedback suggests refining the repository queries to specifically target the first settings record instead of using findAll and narrowing the scope of the security request matchers for better precision.
| return aiCommentSettingsRepository.findAll().stream() | ||
| .findFirst() | ||
| .map(AiCommentSettings::isAutoDetectEnabled) | ||
| .orElse(true); |
There was a problem hiding this comment.
| AiCommentSettings settings = aiCommentSettingsRepository.findAll().stream() | ||
| .findFirst() | ||
| .orElseThrow(() -> new IllegalStateException("AI 댓글 설정을 찾을 수 없습니다.")); |
There was a problem hiding this comment.
findAll()을 사용하여 설정을 조회하는 대신, AiCommentSettingsRepository에 추가를 제안한 findFirstByOrderByIdAsc() 메서드를 사용하는 것이 좋습니다. 이 방법은 의도를 더 명확하게 드러내고, 여러 설정 행이 존재할 경우의 예기치 않은 동작을 방지하며, 더 효율적입니다.
AiCommentSettings settings = aiCommentSettingsRepository.findFirstByOrderByIdAsc()
.orElseThrow(() -> new IllegalStateException("AI 댓글 설정을 찾을 수 없습니다."));| public interface AiCommentSettingsRepository extends JpaRepository<AiCommentSettings, Long> { | ||
| } |
There was a problem hiding this comment.
ai_comment_settings 테이블은 단일 행으로 관리되는 전역 설정을 저장하는 것으로 보입니다. findAll()을 사용하여 설정을 조회하면, 실수로 여러 행이 추가되었을 때 어떤 행을 가져올지 보장할 수 없으며 불필요하게 모든 데이터를 조회하는 비효율이 발생할 수 있습니다. ID를 기준으로 정렬하여 첫 번째 설정만 가져오는 명시적인 메서드를 추가하는 것이 좋습니다.
| public interface AiCommentSettingsRepository extends JpaRepository<AiCommentSettings, Long> { | |
| } | |
| public interface AiCommentSettingsRepository extends JpaRepository<AiCommentSettings, Long> { | |
| java.util.Optional<AiCommentSettings> findFirstByOrderByIdAsc(); | |
| } |
| .requestMatchers(HttpMethod.POST, "/banners/images").hasRole("ADMIN") | ||
| .requestMatchers(HttpMethod.PUT, "/banners/**").hasRole("ADMIN") | ||
| .requestMatchers(HttpMethod.DELETE, "/banners/**").hasRole("ADMIN") | ||
| .requestMatchers("/admin/**").hasRole("ADMIN") |
There was a problem hiding this comment.
/admin/** 경로에 대해 일괄적으로 ADMIN 권한을 부여하는 것은 너무 광범위하여 의도치 않은 보안 위험을 초래할 수 있습니다. 향후 /admin 경로 하위에 다른 접근 제어가 필요한 API가 추가될 경우, 이 설정 때문에 모두 ADMIN 전용으로 제한될 수 있습니다. 새로 추가된 AI 댓글 관리 API 경로에 대해서만 구체적으로 권한을 설정하는 것이 더 안전하고 명확합니다.
| .requestMatchers("/admin/**").hasRole("ADMIN") | |
| .requestMatchers("/admin/ai-comments/**").hasRole("ADMIN") |