diff --git a/src/main/java/com/medicare/neulpeum/domain/entity/ProvidedDrugInfo.java b/src/main/java/com/medicare/neulpeum/domain/entity/ProvidedDrugInfo.java index 45c6f30..553ae23 100644 --- a/src/main/java/com/medicare/neulpeum/domain/entity/ProvidedDrugInfo.java +++ b/src/main/java/com/medicare/neulpeum/domain/entity/ProvidedDrugInfo.java @@ -27,5 +27,5 @@ public class ProvidedDrugInfo { private ConsultContentInfo consultId; @Column(nullable = false) - private Long providedAmount; + private int providedAmount; } diff --git a/src/main/java/com/medicare/neulpeum/dto/DrugUpdateRequestDto.java b/src/main/java/com/medicare/neulpeum/dto/DrugUpdateRequestDto.java index 61c9688..b4b8a81 100644 --- a/src/main/java/com/medicare/neulpeum/dto/DrugUpdateRequestDto.java +++ b/src/main/java/com/medicare/neulpeum/dto/DrugUpdateRequestDto.java @@ -1,6 +1,5 @@ package com.medicare.neulpeum.dto; -import com.medicare.neulpeum.domain.entity.ConsultContentInfo; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -9,7 +8,7 @@ @Setter @NoArgsConstructor public class DrugUpdateRequestDto { - private ConsultContentInfo consultId; + private Long consultId; private String drugName; private int usedAmount; diff --git a/src/main/java/com/medicare/neulpeum/service/ConsultService.java b/src/main/java/com/medicare/neulpeum/service/ConsultService.java index d5027de..371c3b9 100644 --- a/src/main/java/com/medicare/neulpeum/service/ConsultService.java +++ b/src/main/java/com/medicare/neulpeum/service/ConsultService.java @@ -1,7 +1,11 @@ package com.medicare.neulpeum.service; +import com.medicare.neulpeum.domain.entity.ConsultContentInfo; import com.medicare.neulpeum.domain.entity.PatientInfo; -import com.medicare.neulpeum.dto.*; +import com.medicare.neulpeum.dto.ConsultDetailResponseDto; +import com.medicare.neulpeum.dto.ConsultRequestDto; +import com.medicare.neulpeum.dto.ConsultResponseDto; +import com.medicare.neulpeum.dto.ConsultUpdateRequestDto; import java.util.List; @@ -15,4 +19,6 @@ public interface ConsultService { void update(ConsultUpdateRequestDto consultUpdateRequestDto); void delete(Long consultId); + + ConsultContentInfo findById(Long consultId); } diff --git a/src/main/java/com/medicare/neulpeum/service/ConsultServiceImpl.java b/src/main/java/com/medicare/neulpeum/service/ConsultServiceImpl.java index bc6f761..ea2b075 100644 --- a/src/main/java/com/medicare/neulpeum/service/ConsultServiceImpl.java +++ b/src/main/java/com/medicare/neulpeum/service/ConsultServiceImpl.java @@ -116,4 +116,10 @@ public void delete(Long consultId) { consultRepository.deleteByConsultId(consultId); } } + + @Override + public ConsultContentInfo findById(Long consultId) { + Optional consultContentInfoOptional= consultRepository.findById(consultId); + return consultContentInfoOptional.orElse(null); + } } diff --git a/src/main/java/com/medicare/neulpeum/service/DrugServiceImpl.java b/src/main/java/com/medicare/neulpeum/service/DrugServiceImpl.java index 0019139..eb48b7d 100644 --- a/src/main/java/com/medicare/neulpeum/service/DrugServiceImpl.java +++ b/src/main/java/com/medicare/neulpeum/service/DrugServiceImpl.java @@ -1,10 +1,15 @@ package com.medicare.neulpeum.service; +import com.medicare.neulpeum.Repository.ConsultRepository; import com.medicare.neulpeum.Repository.DrugRepository; import com.medicare.neulpeum.Repository.ProvidedDrugRepository; +import com.medicare.neulpeum.domain.entity.ConsultContentInfo; import com.medicare.neulpeum.domain.entity.DrugInfo; import com.medicare.neulpeum.domain.entity.ProvidedDrugInfo; -import com.medicare.neulpeum.dto.*; +import com.medicare.neulpeum.dto.DrugNameAndAmountResponseDto; +import com.medicare.neulpeum.dto.DrugRequestDto; +import com.medicare.neulpeum.dto.DrugResponseDto; +import com.medicare.neulpeum.dto.DrugUpdateRequestDto; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -23,6 +28,8 @@ public class DrugServiceImpl implements DrugService{ DrugRepository drugRepository; @Autowired ProvidedDrugRepository providedDrugRepository; + @Autowired + ConsultRepository consultRepository; @Override public void save(DrugRequestDto drugReq) { @@ -93,6 +100,11 @@ public void updateUsedDrug(List drugUpdateRequestDtoList) for (DrugUpdateRequestDto updateRequestDto : drugUpdateRequestDtoList) { String drugName = updateRequestDto.getDrugName(); int usedAmount = updateRequestDto.getUsedAmount(); + ConsultContentInfo consultId = consultRepository.findByConsultId(updateRequestDto.getConsultId()).orElse(null); + if (consultId == null) { + throw new IllegalArgumentException("상담내역을 찾을 수 없습니다. ID: " + updateRequestDto.getConsultId()); + } + //약 이름으로 유통기한이 가장 짧은 것을 DB에서 조회 List drugs = drugRepository.findByDrugNameOrderByExpireDateAsc(drugName); @@ -105,10 +117,11 @@ public void updateUsedDrug(List drugUpdateRequestDtoList) drugRepository.save(drug); //ProvidedDrugInfo 테이블에 저장 + ProvidedDrugInfo providedDrugInfo = ProvidedDrugInfo.builder() .drugId(drug) - .consultId(updateRequestDto.getConsultId()) - .providedAmount((long) remainingAmount) + .consultId(consultId) + .providedAmount(remainingAmount) .build(); providedDrugRepository.save(providedDrugInfo); @@ -123,8 +136,8 @@ public void updateUsedDrug(List drugUpdateRequestDtoList) //ProvidedDrugInfo 테이블에 저장 ProvidedDrugInfo providedDrugInfo = ProvidedDrugInfo.builder() .drugId(drug) - .consultId(updateRequestDto.getConsultId()) - .providedAmount((long) remainingAmount) + .consultId(consultId) + .providedAmount(usableAmount) .build(); providedDrugRepository.save(providedDrugInfo); }