Skip to content

Commit

Permalink
refactor: 수정시 검증 로직 추가 #8
Browse files Browse the repository at this point in the history
변경하려는 체중의 petId 검증
  • Loading branch information
shimbaa committed Sep 18, 2024
1 parent 3b79c2e commit cdb3ff5
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ public WeightResponse getDetailWeightRecord(Long id, Long petId) {
}

@Transactional
public void updateWeightRecord(Long id, WeightUpdateRequest request) {
public void updateWeightRecord(Long id, Long petId, WeightUpdateRequest request) {

Weight weight = weightRepository.findById(id)
.orElseThrow(RuntimeException::new);

weight.validateOwnership(petId);

weight.update( // 변경 포인트를 해당 메서드에 모아서 하나로 통일한다.
request.recordedAt(),
request.weight(),
Expand All @@ -64,7 +66,7 @@ public void updateWeightRecord(Long id, WeightUpdateRequest request) {
public void deleteWeightRecord(Long id) {

Weight weight = weightRepository.findById(id)
.orElseThrow(RecordNotFoundException::new); // 적절한 예외 적용하기
.orElseThrow(RecordNotFoundException::new);

weightRepository.delete(weight);
}
Expand Down

0 comments on commit cdb3ff5

Please sign in to comment.