feat(farming): 기록 작물이 해당 농장 등록 작물인지 검증 - #53
Merged
Conversation
기록 작물이 해당 농장에 등록되지 않았을 때 사용할 FARMING_RECORD_CROP_NOT_IN_FARM(400)을 추가한다. 사용처는 후속 커밋에서 연결한다. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
create/update에서 농장 소유(findFarm)와 전역 작물 존재(findCrop) 확인에 더해, (회원,농장,작물) 조합이 MemberCrop에 등록됐는지 existsByMemberIdAndFarmIdAndCropId로 확인하고, 미등록이면 FARMING_RECORD_CROP_NOT_IN_FARM(400)을 던진다. 음성 기록도 confirm이 같은 create를 타므로 함께 커버된다. 기존 create/update 해피패스 테스트는 등록 조합을 전제하므로 setUp에 기본 stub(lenient)만 추가해 그린을 유지한다. 미등록 거부 회귀 테스트는 후속 커밋에서 추가한다. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
create/update 시 (회원,농장,작물)이 MemberCrop에 등록되지 않았으면 FARMING_RECORD_CROP_NOT_IN_FARM을 던지고 저장하지 않음을 검증한다. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…validation # Conflicts: # backend/application/src/main/kotlin/com/chamchamcham/application/farming/FarmingRecordService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
변경 내용
기록 생성/수정 시, 기록하려는 작물이 해당 농장에 등록된 작물(MemberCrop) 인지 검증한다.
미등록 (회원,농장,작물) 조합이면 저장하지 않고 새 에러코드로 거부한다.
FarmingRecordService.create/update에assertCropRegisteredToFarm(memberId, farmId, cropId)추가ErrorCode.FARMING_RECORD_CROP_NOT_IN_FARM(FARMING_006, 400) 신설MemberCropRepository.existsByMemberIdAndFarmIdAndCropId(...)재사용 (신규 쿼리 없음)변경 이유
기존엔 농장 소유(
findFarm)와 전역 작물 존재(findCrop)만 따로 확인하고, "이 농장에 이 작물이등록돼 있는가"라는 조합 검증이 없었다. 그래서 심지도 않은 작물로 기록을 남기는 것이 가능했다.
영향 범위
FARMING_006)이 발생할 수 있다.FarmingRecordService.create를 타므로 같은 검증이 적용된다.이 에러코드 메시지 처리가 필요할 수 있다.
배포 및 호환성
DB 스키마 변경 없음. 신규 에러코드/메시지 키 추가(
error.farming_record_crop_not_in_farm).검증
cd backend && ./gradlew test→ BUILD SUCCESSFUL (전체 백엔드 테스트, dev 최신 rebase 기준)체크리스트
🤖 Generated with Claude Code