-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
217 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from fastapi import APIRouter, HTTPException | ||
from pydantic import BaseModel | ||
from app.worker import process_wrong_match_report, process_wrong_nutrition_report | ||
from loguru import logger | ||
|
||
router = APIRouter(prefix="/reports", tags=["reports"]) | ||
|
||
|
||
class WrongMatchReportRequest(BaseModel): | ||
original_name: str | ||
original_price: float | ||
wrong_match_id: str | ||
|
||
|
||
class WrongNutritionReportRequest(BaseModel): | ||
product_id: str | ||
nutrition_id: int | ||
|
||
|
||
@router.post("/wrong-match") | ||
async def report_wrong_match(report: WrongMatchReportRequest): | ||
try: | ||
process_wrong_match_report.delay( | ||
original_name=report.original_name, | ||
original_price=report.original_price, | ||
wrong_match_id=report.wrong_match_id, | ||
) | ||
return {"status": "Report submitted successfully"} | ||
except Exception as e: | ||
logger.error(f"Error submitting wrong match report: {str(e)}") | ||
raise HTTPException(status_code=500, detail="Error submitting report") | ||
|
||
|
||
@router.post("/wrong-nutrition") | ||
async def report_wrong_nutrition(report: WrongNutritionReportRequest): | ||
try: | ||
process_wrong_nutrition_report.delay( | ||
product_id=report.product_id, nutrition_id=report.nutrition_id | ||
) | ||
return {"status": "Report submitted successfully"} | ||
except Exception as e: | ||
logger.error(f"Error submitting wrong nutrition report: {str(e)}") | ||
raise HTTPException(status_code=500, detail="Error submitting report") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
migrations/versions/feff058e9105_add_wrong_match_and_nutrition_reports.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""Add wrong match and nutrition reports | ||
Revision ID: feff058e9105 | ||
Revises: 07d7883b354c | ||
Create Date: 2024-10-21 17:13:13.996589 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
import sqlmodel | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "feff058e9105" | ||
down_revision: Union[str, None] = "07d7883b354c" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"wrongmatchreport", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("original_name", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("original_price", sa.Float(), nullable=False), | ||
sa.Column("wrong_match_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("timestamp", sa.DateTime(), nullable=False), | ||
sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("notes", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["wrong_match_id"], | ||
["product.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_table( | ||
"wrongnutritionreport", | ||
sa.Column("id", sa.Integer(), nullable=False), | ||
sa.Column("product_id", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("nutrition_id", sa.Integer(), nullable=False), | ||
sa.Column("timestamp", sa.DateTime(), nullable=False), | ||
sa.Column("status", sqlmodel.sql.sqltypes.AutoString(), nullable=False), | ||
sa.Column("notes", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["nutrition_id"], | ||
["nutritionalinformation.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["product_id"], | ||
["product.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("wrongnutritionreport") | ||
op.drop_table("wrongmatchreport") | ||
# ### end Alembic commands ### |