Skip to content

Commit

Permalink
Merge pull request #34 from snuhcs-course/add-invalid-receipt
Browse files Browse the repository at this point in the history
add invalid receipt
  • Loading branch information
ozeeeno authored Dec 2, 2023
2 parents b4160d1 + 9332920 commit 33e6607
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
16 changes: 9 additions & 7 deletions backend/src/review/review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions ml/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 3 additions & 0 deletions ml/ocr/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 33e6607

Please sign in to comment.