diff --git a/src/main/java/com/nadoyagsa/pillaroid/controller/MedicineController.java b/src/main/java/com/nadoyagsa/pillaroid/controller/MedicineController.java index f88d035..e883135 100644 --- a/src/main/java/com/nadoyagsa/pillaroid/controller/MedicineController.java +++ b/src/main/java/com/nadoyagsa/pillaroid/controller/MedicineController.java @@ -55,20 +55,10 @@ public ApiResponse getMedicineInfo(HttpServletRequest request, throw NotFoundException.MEDICINE_NOT_FOUND; } - // 의약품 용기(제품명, 바코드)로 정보 조회 + // 의약품 용기(바코드)로 정보 조회 @GetMapping("/case") - public ApiResponse getMedicineInfo(HttpServletRequest request, - @RequestParam(required = false) String name, - @RequestParam(required = false) String barcode) throws IOException { - if (name != null && !name.equals("")) { // 제품명 - Optional medicineResponse = medicineService.getMedicineInfoByCaseName(name); - - if (medicineResponse.isPresent()) { - return reflectFavoritesAboutMedicine(request, medicineResponse.get()); - } - else - throw NotFoundException.MEDICINE_NOT_FOUND; - } else if (barcode != null && !barcode.equals("")) { // 바코드 + public ApiResponse getMedicineInfo(HttpServletRequest request, @RequestParam String barcode) throws IOException { + if (barcode != null && !barcode.equals("")) { // 바코드 Optional medicineResponse = medicineService.getMedicineInfoByStandardCode(barcode); if (medicineResponse.isPresent()) { @@ -81,12 +71,14 @@ public ApiResponse getMedicineInfo(HttpServletRequest request, if (medicineResponse.isPresent()) { return reflectFavoritesAboutMedicine(request, medicineResponse.get()); } - else + else { throw NotFoundException.BARCODE_NOT_FOUND; + } } } - else + else { throw BadRequestException.BAD_PARAMETER; + } } // 음성을 통한 의약품명으로 의약품 리스트 조회 diff --git a/src/main/java/com/nadoyagsa/pillaroid/service/MedicineService.java b/src/main/java/com/nadoyagsa/pillaroid/service/MedicineService.java index 0094e65..a164630 100644 --- a/src/main/java/com/nadoyagsa/pillaroid/service/MedicineService.java +++ b/src/main/java/com/nadoyagsa/pillaroid/service/MedicineService.java @@ -48,21 +48,6 @@ public Optional getMedicineInfoBySerialNumber(int serialNumber return Optional.ofNullable(medicine.get().toMedicineResponse()); } - public Optional getMedicineInfoByCaseName(String name) { - List medicineList = medicineRepository.findMedicinesByStartingName(name); - - // DB에 저장된 제품명에서 괄호를 제거하고 동일한 의약품명이 있다면 해당 의약품 정보 전달 else 가장 먼저 조회된 결과 전달 - for (Medicine medicine : medicineList) { - if (medicine.getName().strip().equals(name)) - return Optional.ofNullable(medicine.toMedicineResponse()); - } - - if (medicineList.size() == 0) - return Optional.empty(); - else - return Optional.ofNullable(medicineList.get(0).toMedicineResponse()); - } - public Optional getMedicineInfoByStandardCode(String barcode) { Optional medicine = medicineRepository.findMedicineByStandardCode(barcode); if (medicine.isEmpty())