Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/NadoYagsa/Pillaroid-Server
Browse files Browse the repository at this point in the history
… into feat/21-alarm
  • Loading branch information
soeunkk committed Aug 29, 2022
2 parents 24e325a + dceb12f commit 2369346
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,10 @@ public ApiResponse<MedicineResponse> getMedicineInfo(HttpServletRequest request,
throw NotFoundException.MEDICINE_NOT_FOUND;
}

// 의약품 용기(제품명, 바코드)로 정보 조회
// 의약품 용기(바코드)로 정보 조회
@GetMapping("/case")
public ApiResponse<MedicineResponse> getMedicineInfo(HttpServletRequest request,
@RequestParam(required = false) String name,
@RequestParam(required = false) String barcode) throws IOException {
if (name != null && !name.equals("")) { // 제품명
Optional<MedicineResponse> 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<MedicineResponse> getMedicineInfo(HttpServletRequest request, @RequestParam String barcode) throws IOException {
if (barcode != null && !barcode.equals("")) { // 바코드
Optional<MedicineResponse> medicineResponse = medicineService.getMedicineInfoByStandardCode(barcode);

if (medicineResponse.isPresent()) {
Expand All @@ -81,12 +71,14 @@ public ApiResponse<MedicineResponse> getMedicineInfo(HttpServletRequest request,
if (medicineResponse.isPresent()) {
return reflectFavoritesAboutMedicine(request, medicineResponse.get());
}
else
else {
throw NotFoundException.BARCODE_NOT_FOUND;
}
}
}
else
else {
throw BadRequestException.BAD_PARAMETER;
}
}

// 음성을 통한 의약품명으로 의약품 리스트 조회
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/nadoyagsa/pillaroid/service/MedicineService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ public Optional<MedicineResponse> getMedicineInfoBySerialNumber(int serialNumber
return Optional.ofNullable(medicine.get().toMedicineResponse());
}

public Optional<MedicineResponse> getMedicineInfoByCaseName(String name) {
List<Medicine> 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<MedicineResponse> getMedicineInfoByStandardCode(String barcode) {
Optional<Medicine> medicine = medicineRepository.findMedicineByStandardCode(barcode);
if (medicine.isEmpty())
Expand Down

0 comments on commit 2369346

Please sign in to comment.