diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/HelpErrorCode.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/help/HelpErrorCode.java similarity index 87% rename from check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/HelpErrorCode.java rename to check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/help/HelpErrorCode.java index 7b02f36..a6ede10 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/HelpErrorCode.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/help/HelpErrorCode.java @@ -1,4 +1,4 @@ -package com.example.checkinrequestMS.HelpAPI.domain.exceptions; +package com.example.checkinrequestMS.HelpAPI.domain.exceptions.help; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/HelpException.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/help/HelpException.java similarity index 77% rename from check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/HelpException.java rename to check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/help/HelpException.java index cf7a1c6..fea88f2 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/HelpException.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/help/HelpException.java @@ -1,4 +1,4 @@ -package com.example.checkinrequestMS.HelpAPI.domain.exceptions; +package com.example.checkinrequestMS.HelpAPI.domain.exceptions.help; import com.example.checkinrequestMS.common.exception.types.DomainException; diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/ProgressErrorCode.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/progress/ProgressErrorCode.java similarity index 54% rename from check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/ProgressErrorCode.java rename to check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/progress/ProgressErrorCode.java index 3713e43..4e128dc 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/ProgressErrorCode.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/progress/ProgressErrorCode.java @@ -1,4 +1,4 @@ -package com.example.checkinrequestMS.HelpAPI.domain.exceptions; +package com.example.checkinrequestMS.HelpAPI.domain.exceptions.progress; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -6,7 +6,7 @@ @Getter @RequiredArgsConstructor public enum ProgressErrorCode { - ; + NO_PROGRESS("진행 정보가 존재하지 않습니다."); private final String detail; } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/progress/ProgressException.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/progress/ProgressException.java new file mode 100644 index 0000000..f0c8881 --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/exceptions/progress/ProgressException.java @@ -0,0 +1,10 @@ +package com.example.checkinrequestMS.HelpAPI.domain.exceptions.progress; + +import com.example.checkinrequestMS.common.exception.types.DomainException; + +public class ProgressException extends DomainException { + + public ProgressException(ProgressErrorCode errorCode) { + super(errorCode.getDetail()); + } +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpCRUDService.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpCRUDService.java index 3fe1ae4..d031450 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpCRUDService.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpCRUDService.java @@ -2,7 +2,7 @@ import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.LineUp; import com.example.checkinrequestMS.HelpAPI.infra.db.help.LineUpJPARepository; -import com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAException; +import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAException; import com.example.checkinrequestMS.PlaceAPI.domain.Place; import com.example.checkinrequestMS.PlaceAPI.domain.exceptions.place.PlaceException; import com.example.checkinrequestMS.PlaceAPI.infra.PlaceRepository; @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAErrorCode.ERROR_SAVING; +import static com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAErrorCode.ERROR_SAVE; import static com.example.checkinrequestMS.PlaceAPI.domain.exceptions.place.PlaceErrorCode.NO_PLACE_INFO; @Service @@ -24,14 +24,11 @@ public class LineUpCRUDService { public void registerLineUp(LineUp lineUp) { Place place = placeRepository.findById(lineUp.getPlaceId()) .orElseThrow(() -> new PlaceException(NO_PLACE_INFO)); - lineUp.setPlaceWithFullInfo(place); + //lineUp.setPlaceWithFullInfo(place); lineUp.setLineUpTitle(place); - try { - lineUpJPARepository.save(lineUp); - } catch (Exception e) { - throw new JPAException(ERROR_SAVING); - } + lineUpJPARepository.save(lineUp); + } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpSelectService.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpSelectService.java index 69ee518..b104984 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpSelectService.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/LineUp/LineUpSelectService.java @@ -1,13 +1,13 @@ package com.example.checkinrequestMS.HelpAPI.domain.service.LineUp; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.LineUp; -import com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpException; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpException; import com.example.checkinrequestMS.HelpAPI.infra.db.help.LineUpJPARepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpErrorCode.NO_LINE_UP_INFO; +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode.NO_LINE_UP_INFO; @Service @RequiredArgsConstructor @@ -18,7 +18,6 @@ public class LineUpSelectService { @Transactional public LineUp selectLineUp(Long id) { return lineUpJPARepository.findById(id).orElseThrow( - () -> new HelpException(NO_LINE_UP_INFO) - ); + () -> new HelpException(NO_LINE_UP_INFO)); } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInCRUDService.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInCRUDService.java index 9182bfc..06d9d0c 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInCRUDService.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInCRUDService.java @@ -1,16 +1,16 @@ package com.example.checkinrequestMS.HelpAPI.domain.service.checkIn; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.CheckIn; -import com.example.checkinrequestMS.HelpAPI.domain.entities.progress.Progress; +import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAErrorCode; import com.example.checkinrequestMS.HelpAPI.infra.db.help.CheckInJPARepository; -import com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAException; +import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAException; import com.example.checkinrequestMS.PlaceAPI.domain.Place; import com.example.checkinrequestMS.PlaceAPI.domain.exceptions.place.PlaceException; import com.example.checkinrequestMS.PlaceAPI.infra.PlaceRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import static com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAErrorCode.ERROR_SAVING; + import static com.example.checkinrequestMS.PlaceAPI.domain.exceptions.place.PlaceErrorCode.NO_PLACE_INFO; @Service @@ -26,10 +26,6 @@ public void registerCheckIn(CheckIn checkIn) { .orElseThrow(() -> new PlaceException(NO_PLACE_INFO)); checkIn.setCheckInTitle(place); - try { - checkInJPARepository.save(checkIn); - } catch (Exception e) { - throw new JPAException(ERROR_SAVING); - } + checkInJPARepository.save(checkIn); } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInSelectService.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInSelectService.java index 97b11dd..5efc51a 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInSelectService.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/checkIn/CheckInSelectService.java @@ -1,14 +1,14 @@ package com.example.checkinrequestMS.HelpAPI.domain.service.checkIn; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.CheckIn; -import com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpException; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpException; import com.example.checkinrequestMS.HelpAPI.infra.db.help.CheckInJPARepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpErrorCode.NO_CHECK_IN_INFO; +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode.NO_CHECK_IN_INFO; @Service @RequiredArgsConstructor diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcCRUDService.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcCRUDService.java index 6fa45cc..f1e23d7 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcCRUDService.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcCRUDService.java @@ -1,8 +1,9 @@ package com.example.checkinrequestMS.HelpAPI.domain.service.etc; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.Etc; +import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAErrorCode; import com.example.checkinrequestMS.HelpAPI.infra.db.help.EtcJPARepository; -import com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAException; +import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAException; import com.example.checkinrequestMS.PlaceAPI.domain.Place; import com.example.checkinrequestMS.PlaceAPI.domain.exceptions.place.PlaceException; import com.example.checkinrequestMS.PlaceAPI.infra.PlaceRepository; @@ -10,7 +11,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAErrorCode.ERROR_SAVING; + +import static com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAErrorCode.ERROR_SAVE; import static com.example.checkinrequestMS.PlaceAPI.domain.exceptions.place.PlaceErrorCode.NO_PLACE_INFO; @Service @@ -21,14 +23,11 @@ public class EtcCRUDService { @Transactional public void registerEtc(Etc etc) { - Place place = placeRepository.findById(etc.getPlace().getId()) + Place place = placeRepository.findById(etc.getPlaceId()) .orElseThrow(() -> new PlaceException(NO_PLACE_INFO)); - etc.setPlaceWithFullInfo(place); + //etc.setPlaceWithFullInfo(place); + + etcJPARepository.save(etc); - try { - etcJPARepository.save(etc); - } catch (Exception e) { - throw new JPAException(ERROR_SAVING); - } } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcSelectService.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcSelectService.java index e1c1f68..9dec665 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcSelectService.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/etc/EtcSelectService.java @@ -1,14 +1,13 @@ package com.example.checkinrequestMS.HelpAPI.domain.service.etc; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.Etc; -import com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpErrorCode; -import com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpException; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpException; import com.example.checkinrequestMS.HelpAPI.infra.db.help.EtcJPARepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpErrorCode.No_ETC_INFO; +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode.No_ETC_INFO; @Service @RequiredArgsConstructor @@ -21,6 +20,5 @@ public Etc selectEtc(Long id) { return etcJPARepository.findById(id).orElseThrow( () -> new HelpException(No_ETC_INFO) ); - } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDService.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDService.java index c197ee8..bc03b02 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDService.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDService.java @@ -2,16 +2,17 @@ import com.example.checkinrequestMS.HelpAPI.domain.entities.help.Help; import com.example.checkinrequestMS.HelpAPI.domain.entities.progress.Progress; -import com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpException; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpException; + +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.progress.ProgressException; import com.example.checkinrequestMS.HelpAPI.infra.db.help.HelpJPARepository; import com.example.checkinrequestMS.HelpAPI.infra.db.progress.ProgressJPARepository; -import com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpErrorCode.NO_HELP_INFO; -import static com.example.checkinrequestMS.HelpAPI.infra.exceptions.JPAErrorCode.ERROR_SAVING; +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode.NO_HELP_INFO; +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.progress.ProgressErrorCode.NO_PROGRESS; @Service @RequiredArgsConstructor @@ -23,15 +24,13 @@ public class ProgressCRUDService { @Transactional public Progress registerProgress(Progress progress) { Help help = helpJPARepository.findById(progress.getHelp().getId()).orElseThrow( - () -> new HelpException(NO_HELP_INFO) - ); + () -> new HelpException(NO_HELP_INFO)); progress.setHelp(help); + //todo: 내부 요청으로 MemberID + progressJPARepository.save(progress); - try{ - return progressJPARepository.save(progress); - }catch (Exception e) { - throw new JPAException(ERROR_SAVING); - } + return progressJPARepository.findById(progress.getId()).orElseThrow( + () -> new ProgressException(NO_PROGRESS)); } //사진파일저장, 인증 변화. diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPAExceptionAspect.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPAExceptionAspect.java new file mode 100644 index 0000000..b6ae4e8 --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPAExceptionAspect.java @@ -0,0 +1,45 @@ +package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; + + +import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAException; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; + +import static com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAErrorCode.*; + +@Component +@Aspect +public class JPAExceptionAspect { + + @Around("@annotation(JPARead)") + public Object handleJPAReadException(ProceedingJoinPoint joinPoint) throws Throwable { + try { + return joinPoint.proceed(); + } catch (Exception e) { + throw new JPAException(ERROR_READ, e); + + } + } + + @Around("@annotation(JPASave)") + public Object handleJPASaveException(ProceedingJoinPoint joinPoint) throws Throwable { + try { + return joinPoint.proceed(); + } catch (Exception e) { + throw new JPAException(ERROR_SAVE, e); + } + } + + @Around("@annotation(JPAUpdate)") + public Object handleJPAUpdateException(ProceedingJoinPoint joinPoint) throws Throwable { + try { + return joinPoint.proceed(); + } catch (Exception e) { + throw new JPAException(ERROR_UPDATE, e); + } + } + + +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPARead.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPARead.java new file mode 100644 index 0000000..c8c6fa5 --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPARead.java @@ -0,0 +1,11 @@ +package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface JPARead { +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPASave.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPASave.java new file mode 100644 index 0000000..b3abdbe --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPASave.java @@ -0,0 +1,11 @@ +package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface JPASave { +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPAUpdate.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPAUpdate.java new file mode 100644 index 0000000..1f070cb --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/aspect/JPAUpdate.java @@ -0,0 +1,11 @@ +package com.example.checkinrequestMS.HelpAPI.infra.aop.aspect; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface JPAUpdate { +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/exceptions/JPAErrorCode.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/exceptions/JPAErrorCode.java new file mode 100644 index 0000000..1389269 --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/exceptions/JPAErrorCode.java @@ -0,0 +1,15 @@ +package com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum JPAErrorCode { + ERROR_SAVE("JPA 저장 작업 중 에러"), + ERROR_UPDATE("JPA 업데이트 작업 중 에러"), + ERROR_READ("JPA 조회 작업 중 에러"); + + + private final String detail; +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/exceptions/JPAException.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/exceptions/JPAException.java new file mode 100644 index 0000000..573ab03 --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/aop/exceptions/JPAException.java @@ -0,0 +1,14 @@ +package com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions; + +import com.example.checkinrequestMS.common.exception.types.InfraException; + +public class JPAException extends InfraException { + + public JPAException(JPAErrorCode error) { + super(error.getDetail()); + } + + public JPAException(JPAErrorCode error, Exception e) { + super(error.getDetail(), e); + } +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/CheckInJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/CheckInJPARepository.java index 18f8314..3b25e87 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/CheckInJPARepository.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/CheckInJPARepository.java @@ -1,7 +1,25 @@ package com.example.checkinrequestMS.HelpAPI.infra.db.help; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.CheckIn; -import org.springframework.data.jpa.repository.JpaRepository; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPARead; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPASave; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +@RequiredArgsConstructor +public class CheckInJPARepository { + private final CheckInSpringJPARepository checkInSpringJPARepository; + + @JPASave + public void save(CheckIn checkIn) { + checkInSpringJPARepository.save(checkIn); + } + @JPARead + public Optional findById(Long id){ + return checkInSpringJPARepository.findById(id); + } -public interface CheckInJPARepository extends JpaRepository { } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/CheckInSpringJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/CheckInSpringJPARepository.java new file mode 100644 index 0000000..1520e7d --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/CheckInSpringJPARepository.java @@ -0,0 +1,7 @@ +package com.example.checkinrequestMS.HelpAPI.infra.db.help; + +import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.CheckIn; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CheckInSpringJPARepository extends JpaRepository { +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/EtcJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/EtcJPARepository.java index 35ce497..c07df0e 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/EtcJPARepository.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/EtcJPARepository.java @@ -1,7 +1,26 @@ package com.example.checkinrequestMS.HelpAPI.infra.db.help; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.Etc; -import org.springframework.data.jpa.repository.JpaRepository; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPARead; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPASave; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; -public interface EtcJPARepository extends JpaRepository { +import java.util.Optional; + +@Repository +@RequiredArgsConstructor +public class EtcJPARepository { + + private final EtcSpringJPARepository etcSpringJPARepository; + + @JPASave + public void save(Etc etc){ + etcSpringJPARepository.save(etc); + } + + @JPARead + public Optional findById(Long id){ + return etcSpringJPARepository.findById(id); + } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/EtcSpringJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/EtcSpringJPARepository.java new file mode 100644 index 0000000..71d6bf8 --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/EtcSpringJPARepository.java @@ -0,0 +1,7 @@ +package com.example.checkinrequestMS.HelpAPI.infra.db.help; + +import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.Etc; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface EtcSpringJPARepository extends JpaRepository { +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/HelpJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/HelpJPARepository.java index 93614b4..9638ea8 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/HelpJPARepository.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/HelpJPARepository.java @@ -1,8 +1,29 @@ package com.example.checkinrequestMS.HelpAPI.infra.db.help; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.Help; -import org.springframework.data.jpa.repository.JpaRepository; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpException; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPARead; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPASave; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; -public interface HelpJPARepository extends JpaRepository { +import java.util.Optional; +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode.NO_HELP_INFO; + +@Repository +@RequiredArgsConstructor +public class HelpJPARepository { + private final HelpSpringJPARepository helpSpringJPARepository; + + @JPASave + public void save(Help help){ + helpSpringJPARepository.save(help); + } + + @JPARead + public Optional findById(Long id){ + return helpSpringJPARepository.findById(id); + } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/HelpSpringJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/HelpSpringJPARepository.java new file mode 100644 index 0000000..d0f3300 --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/HelpSpringJPARepository.java @@ -0,0 +1,8 @@ +package com.example.checkinrequestMS.HelpAPI.infra.db.help; + +import com.example.checkinrequestMS.HelpAPI.domain.entities.help.Help; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface HelpSpringJPARepository extends JpaRepository { + +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/LineUpJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/LineUpJPARepository.java index 3fac7f9..51aaa45 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/LineUpJPARepository.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/LineUpJPARepository.java @@ -1,7 +1,28 @@ package com.example.checkinrequestMS.HelpAPI.infra.db.help; import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.LineUp; -import org.springframework.data.jpa.repository.JpaRepository; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpException; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPARead; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPASave; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; -public interface LineUpJPARepository extends JpaRepository { +import java.util.Optional; + +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode.NO_LINE_UP_INFO; + +@Repository +@RequiredArgsConstructor +public class LineUpJPARepository { + private final LineUpSpringJPARepository lineUpSpringJPARepository; + + @JPASave + public void save(LineUp lineUp){ + lineUpSpringJPARepository.save(lineUp); + } + + @JPARead + public Optional findById(Long id){ + return lineUpSpringJPARepository.findById(id); + } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/LineUpSpringJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/LineUpSpringJPARepository.java new file mode 100644 index 0000000..f63905b --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/help/LineUpSpringJPARepository.java @@ -0,0 +1,7 @@ +package com.example.checkinrequestMS.HelpAPI.infra.db.help; + +import com.example.checkinrequestMS.HelpAPI.domain.entities.help.child.LineUp; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface LineUpSpringJPARepository extends JpaRepository { +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/progress/ProgressJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/progress/ProgressJPARepository.java index 5c91d20..ae59d26 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/progress/ProgressJPARepository.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/progress/ProgressJPARepository.java @@ -1,7 +1,27 @@ package com.example.checkinrequestMS.HelpAPI.infra.db.progress; import com.example.checkinrequestMS.HelpAPI.domain.entities.progress.Progress; -import org.springframework.data.jpa.repository.JpaRepository; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPARead; +import com.example.checkinrequestMS.HelpAPI.infra.aop.aspect.JPASave; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; -public interface ProgressJPARepository extends JpaRepository { +import java.util.Optional; + + +@Repository +@RequiredArgsConstructor +public class ProgressJPARepository { + + private final ProgressSpringJPARepository progressSpringJPARepository; + + @JPASave + public void save(Progress progress) { + progressSpringJPARepository.save(progress); + } + + @JPARead + public Optional findById(Long id) { + return progressSpringJPARepository.findById(id); + } } diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/progress/ProgressSpringJPARepository.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/progress/ProgressSpringJPARepository.java new file mode 100644 index 0000000..14f4dba --- /dev/null +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/db/progress/ProgressSpringJPARepository.java @@ -0,0 +1,7 @@ +package com.example.checkinrequestMS.HelpAPI.infra.db.progress; + +import com.example.checkinrequestMS.HelpAPI.domain.entities.progress.Progress; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ProgressSpringJPARepository extends JpaRepository { +} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/exceptions/JPAErrorCode.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/exceptions/JPAErrorCode.java deleted file mode 100644 index 151f37c..0000000 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/exceptions/JPAErrorCode.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.example.checkinrequestMS.HelpAPI.infra.exceptions; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum JPAErrorCode { - ERROR_SAVING("JPA 저장 중 에러"); - - private final String detail; -} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/exceptions/JPAException.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/exceptions/JPAException.java deleted file mode 100644 index c1307c2..0000000 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/infra/exceptions/JPAException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.example.checkinrequestMS.HelpAPI.infra.exceptions; - -import com.example.checkinrequestMS.common.exception.types.InfraException; - -public class JPAException extends InfraException { - public JPAException(JPAErrorCode e) { - super(e.getDetail()); - } -} diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/web/form/progress/ProgressRegisterForm.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/web/form/progress/crud/ProgressRegisterForm.java similarity index 74% rename from check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/web/form/progress/ProgressRegisterForm.java rename to check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/web/form/progress/crud/ProgressRegisterForm.java index 42c8fbf..ab831d9 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/web/form/progress/ProgressRegisterForm.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/HelpAPI/web/form/progress/crud/ProgressRegisterForm.java @@ -1,4 +1,4 @@ -package com.example.checkinrequestMS.HelpAPI.web.form.progress; +package com.example.checkinrequestMS.HelpAPI.web.form.progress.crud; import jakarta.validation.constraints.NotNull; import lombok.Getter; diff --git a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/common/exception/types/InfraException.java b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/common/exception/types/InfraException.java index 225e804..4cf1b61 100644 --- a/check-in-request-MS/src/main/java/com/example/checkinrequestMS/common/exception/types/InfraException.java +++ b/check-in-request-MS/src/main/java/com/example/checkinrequestMS/common/exception/types/InfraException.java @@ -5,4 +5,7 @@ public class InfraException extends RuntimeException{ public InfraException(String errorMessage) { super(errorMessage); } + public InfraException(String errorMessage, Exception e) { + super(errorMessage, e); + } } diff --git a/check-in-request-MS/src/test/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDServiceTest.java b/check-in-request-MS/src/test/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDServiceTest.java index 88d0b17..d8182fd 100644 --- a/check-in-request-MS/src/test/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDServiceTest.java +++ b/check-in-request-MS/src/test/java/com/example/checkinrequestMS/HelpAPI/domain/service/progress/ProgressCRUDServiceTest.java @@ -2,7 +2,7 @@ import com.example.checkinrequestMS.HelpAPI.domain.entities.help.Help; import com.example.checkinrequestMS.HelpAPI.domain.entities.progress.Progress; -import com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpException; +import com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpException; import com.example.checkinrequestMS.HelpAPI.infra.db.help.HelpJPARepository; import com.example.checkinrequestMS.HelpAPI.infra.db.progress.ProgressJPARepository; import org.junit.jupiter.api.DisplayName; @@ -11,12 +11,10 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.web.servlet.ResultActions; import java.util.Optional; -import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.HelpErrorCode.NO_HELP_INFO; +import static com.example.checkinrequestMS.HelpAPI.domain.exceptions.help.HelpErrorCode.NO_HELP_INFO; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.*; @@ -43,8 +41,11 @@ void registerProgress() { given(help.getId()).willReturn(1L); given(helpJPARepository.findById(progress.getHelp().getId())).willReturn(Optional.of(help)); + given(progress.getId()).willReturn(1L); + given(progressJPARepository.findById(anyLong())).willReturn(Optional.of(progress)); + //when - Progress returned = sut.registerProgress(progress); + sut.registerProgress(progress); //then verify(progress, times(1)).setHelp(help); @@ -59,7 +60,7 @@ void registerProgress_NO_HELP_Exception() { Help help = mock(Help.class); given(progress.getHelp()).willReturn(help); given(help.getId()).willReturn(1L); - given(helpJPARepository.findById(progress.getHelp().getId())).willReturn(Optional.empty()); + given(helpJPARepository.findById(progress.getHelp().getId())).willReturn(null); //when HelpException exception = assertThrows(HelpException.class, () -> sut.registerProgress(progress)); diff --git a/check-in-request-MS/src/test/java/com/example/checkinrequestMS/HelpAPI/infra/aop/JPAExceptionAspectTest.java b/check-in-request-MS/src/test/java/com/example/checkinrequestMS/HelpAPI/infra/aop/JPAExceptionAspectTest.java new file mode 100644 index 0000000..5bc4cc8 --- /dev/null +++ b/check-in-request-MS/src/test/java/com/example/checkinrequestMS/HelpAPI/infra/aop/JPAExceptionAspectTest.java @@ -0,0 +1,38 @@ +package com.example.checkinrequestMS.HelpAPI.infra.aop; + +import com.example.checkinrequestMS.HelpAPI.infra.aop.exceptions.JPAException; +import com.example.checkinrequestMS.HelpAPI.infra.db.help.HelpJPARepository; +import com.example.checkinrequestMS.HelpAPI.infra.db.progress.ProgressJPARepository; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@SpringBootTest +class JPAExceptionAspectTest { + + @Autowired + private ProgressJPARepository progressJPARepository; + + @Autowired + private HelpJPARepository helpJPARepository; + + @Test + void save() { + Exception exception = assertThrows(JPAException.class, () -> progressJPARepository.save(null)); + + assertEquals(JPAException.class, exception.getClass()); + assertEquals("JPA 저장 작업 중 에러", exception.getMessage()); + } + + @Test + void findById() { + + Exception exception = assertThrows(JPAException.class, () -> helpJPARepository.findById(null)); + + assertEquals(JPAException.class, exception.getClass()); + assertEquals("JPA 조회 작업 중 에러", exception.getMessage()); + } +} \ No newline at end of file