Skip to content

Commit

Permalink
refactor: 적절한 예외 적용 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
shimbaa committed Sep 18, 2024
1 parent caa3452 commit 316a54a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package buddyguard.mybuddyguard.weight.entity;

import buddyguard.mybuddyguard.exception.InvalidRequestException;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand Down Expand Up @@ -47,7 +48,7 @@ public void update(LocalDateTime recordedAt, Double weight, String description)

public void validateOwnership(Long petId) {
if (!this.petId.equals(petId)) {
throw new RuntimeException(); // 적절한 예외 적용하기
throw new InvalidRequestException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package buddyguard.mybuddyguard.weight.service;

import buddyguard.mybuddyguard.exception.RecordNotFoundException;
import buddyguard.mybuddyguard.weight.entity.Weight;
import buddyguard.mybuddyguard.mapper.WeightMapper;
import buddyguard.mybuddyguard.weight.contoller.request.WeightCreateRequest;
Expand Down Expand Up @@ -38,7 +39,7 @@ public List<WeightResponse> getAllWeightRecords(Long petId) {
public WeightResponse getDetailWeightRecord(Long id, Long petId) {

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

weight.validateOwnership(petId);

Expand All @@ -63,7 +64,7 @@ public void updateWeightRecord(Long id, WeightUpdateRequest request) {
public void deleteWeightRecord(Long id) {

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

weightRepository.delete(weight);
}
Expand Down

0 comments on commit 316a54a

Please sign in to comment.