diff --git a/backend/src/review/review.service.ts b/backend/src/review/review.service.ts index 16c7535..83477dc 100644 --- a/backend/src/review/review.service.ts +++ b/backend/src/review/review.service.ts @@ -29,6 +29,15 @@ export class ReviewService { let images = await this.imageRepository.findBy({ id: In(imageIds.concat([receiptImageId ?? -1])), }); + + let isPositive = false; + try { + isPositive = await getReviewIsPositive(content); + } catch (e) { + console.log(e); + throw new BadRequestException('리뷰 분석 중 오류가 발생했습니다.'); + } + const receiptImage = images.find((image) => image.id === receiptImageId); let menu = []; if (receiptImage) { @@ -42,13 +51,6 @@ export class ReviewService { } } - let isPositive = false; - try { - isPositive = await getReviewIsPositive(content); - } catch (e) { - throw new BadRequestException('리뷰 분석 중 오류가 발생했습니다.'); - } - return await ReviewEntity.create({ content, user, diff --git a/ml/main.py b/ml/main.py index d0ef5e7..7f93699 100644 --- a/ml/main.py +++ b/ml/main.py @@ -27,6 +27,9 @@ async def receipt_ocr(data: OcrModel): jpg_image.save(receipt_path) response = ocr_receipt(receipt_path) + if(response is None): + raise HTTPException(status_code=403, detail="잘못된 영수증입니다") + return response diff --git a/ml/ocr/execution.py b/ml/ocr/execution.py index a778952..bafda49 100644 --- a/ml/ocr/execution.py +++ b/ml/ocr/execution.py @@ -44,6 +44,9 @@ def ocr_receipt(path): images = response_body["images"] images_receipt = images[0].get("receipt") + if(images_receipt is None): + return None + receipt_title = images_receipt["result"]["storeInfo"]["name"]["text"] receipt_address = images_receipt["result"]["storeInfo"]["addresses"][0]["text"] receipt_date = images_receipt["result"]["paymentInfo"]["date"]["text"]