[BE] [REFACTOR] template 패키지를 backtest 도메인 하위로 이관#211
Hidden character warning
Conversation
…rd로 수정, TemplateService의 createTemplate, updateTemplate 인자에 UUID 추가"
…적용),Service 레이어 트랜잭션(@transactional) 적용, Record dto 형태로 TemplateService 코드 수정"
…서드 파라미터 변경, @MockitoBean 도입을 통한 Mockito depricate 문제 해결"
Walkthrough템플릿 기능 관련 코드를 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
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)
backend/src/test/java/org/sejongisc/backend/backtest/service/BacktestServiceTest.java (1)
80-86:⚠️ Potential issue | 🔴 Critical
findByIdWithMemberMock 메서드로 변경 필요.
getBacktestStatus와getBackTestDetails테스트에서runRepository.findById(1L)를 mock하고 있으나,BacktestService.findBacktestRunByIdAndVerifyUser는findByIdWithMember(backtestRunId)를 호출합니다. 테스트의 mock 설정을findByIdWithMember로 수정하세요:given(runRepository.findByIdWithMember(1L)).willReturn(Optional.of(run));영향 받는 테스트:
getBacktestStatus_success,getBacktestStatus_notFound,getBacktestStatus_ownerMismatch,getBackTestDetails_success,getBackTestDetails_notFound.
🤖 Fix all issues with AI agents
In
`@backend/src/main/java/org/sejongisc/backend/backtest/service/TemplateService.java`:
- Around line 76-80: deleteTemplate currently leaves related entities (likes,
bookmarks) unhandled which can cause delete failures or orphaned rows; update
Template entity or delete logic so related data is cleaned up: either add proper
JPA cascade/remove mappings (e.g., `@OneToMany`(mappedBy="template", cascade =
CascadeType.REMOVE or orphanRemoval=true) on the Template entity) or explicitly
remove dependent records in deleteTemplate before calling
templateRepository.delete by invoking the corresponding repositories (e.g.,
likeRepository.deleteByTemplateId, bookmarkRepository.deleteByTemplateId) while
keeping the method `@Transactional` and using authorizeTemplateOwner to locate the
target.
In
`@backend/src/test/java/org/sejongisc/backend/backtest/controller/TemplateControllerTest.java`:
- Around line 57-60: The test registers AuditorAware<String> twice causing bean
conflicts: remove the duplicate `@MockitoBean` on AuditorAware<String> in
TemplateControllerTest (or alternatively remove/disable the auditorProvider()
`@Bean` in DisableJpaAuditingConfig) so only one AuditorAware bean exists; locate
the `@MockitoBean` declaration for AuditorAware<String> and delete or comment it
out (or keep the DisableJpaAuditingConfig.auditorProvider() bean and remove the
`@MockitoBean`) to resolve the injection collision.
🧹 Nitpick comments (3)
backend/src/main/java/org/sejongisc/backend/backtest/service/BacktestService.java (1)
40-72: 읽기 전용 메서드에readOnly = true적용 권장.PR 목표에서 언급된 트랜잭션 최적화 관점에서,
getBacktestStockInfo,getBacktestStatus,getBackTestDetails메서드는 읽기 전용 작업만 수행하므로@Transactional(readOnly = true)적용을 권장합니다.♻️ 권장 수정 사항
- `@Transactional` + `@Transactional`(readOnly = true) public BacktestResponse getBacktestStockInfo() {- `@Transactional` + `@Transactional`(readOnly = true) public BacktestResponse getBacktestStatus(Long backtestRunId, UUID userId) {- `@Transactional` + `@Transactional`(readOnly = true) public BacktestResponse getBackTestDetails(Long backtestRunId, UUID userId) {backend/src/main/java/org/sejongisc/backend/backtest/dto/TemplateRequest.java (1)
6-6: 사용되지 않는 import 제거 권장.
java.util.UUIDimport가 선언되어 있지만 이 record에서 사용되지 않습니다.♻️ 수정 제안
-import java.util.UUID; -backend/src/test/java/org/sejongisc/backend/backtest/service/TemplateServiceTest.java (1)
4-10: MockitoAnnotations.openMocks 대신 MockitoExtension 사용을 권장합니다. openMocks 반환 객체를 닫지 않아 테스트 간 리소스 누수가 생길 수 있어요.♻️ 제안 수정
import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; @@ -class TemplateServiceTest { +@ExtendWith(MockitoExtension.class) +class TemplateServiceTest { @@ `@BeforeEach` void setUp() { - MockitoAnnotations.openMocks(this); - userId = UUID.randomUUID(); templateId = UUID.randomUUID();Also applies to: 29-51
📝 Summary
Template 도메인을
backtest패키지로 통합하고, DTO 및 테스트 코드를 최신 구조로 리팩토링했습니다.✨ Key Changes
template패키지를backtest하위로 이관Request/Response)를 Java Record로 전환하여 불변성 확보readOnly = true기본 적용)update) 시 ID 변조 방지를 위해PathVariableID 강제 사용@MockBean→@MockitoBean교체)🔗 Related Issue
Summary by CodeRabbit
릴리스 노트
New Features
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.