Spaces:
Running
Running
move TransactionProcessingOutput to entity file
Browse files- src/entity/api/transaction_api.py +20 -3
- src/main.py +2 -21
src/entity/api/transaction_api.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
from typing import Optional, Literal
|
| 2 |
-
from pydantic import BaseModel, Field
|
| 3 |
from datetime import datetime
|
| 4 |
from src.entity.transaction import Transaction
|
| 5 |
import logging
|
|
@@ -122,4 +122,21 @@ class TransactionApi(BaseModel):
|
|
| 122 |
"customer_longitude": -122.4194,
|
| 123 |
"customer_city_population": 870000,
|
| 124 |
}
|
| 125 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional, Literal, ClassVar
|
| 2 |
+
from pydantic import BaseModel, Field, ConfigDict
|
| 3 |
from datetime import datetime
|
| 4 |
from src.entity.transaction import Transaction
|
| 5 |
import logging
|
|
|
|
| 122 |
"customer_longitude": -122.4194,
|
| 123 |
"customer_city_population": 870000,
|
| 124 |
}
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
class TransactionProcessingOutput(BaseModel):
|
| 128 |
+
"""
|
| 129 |
+
TransactionProcessingOutput is a class that represents the output of the transaction processing endpoint.
|
| 130 |
+
It contains the fraud detection result and the fraud score.
|
| 131 |
+
This class is used as the response model for the /transaction/process endpoint.
|
| 132 |
+
"""
|
| 133 |
+
is_fraud: int = Field(description="The prediction result. 1 if the transaction is detected as fraudulent, 0 otherwise.")
|
| 134 |
+
fraud_score: float = Field(description="Probability of transaction being fraudulent.")
|
| 135 |
+
|
| 136 |
+
model_config: ClassVar[ConfigDict] = ConfigDict(
|
| 137 |
+
json_schema_extra = {
|
| 138 |
+
"example": {
|
| 139 |
+
"is_fraud": 1,
|
| 140 |
+
"fraud_score": 0.85
|
| 141 |
+
}
|
| 142 |
+
})
|
src/main.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import logging
|
| 3 |
import secrets
|
| 4 |
import requests
|
| 5 |
-
from typing import Annotated, Generator
|
| 6 |
from fastapi import (
|
| 7 |
FastAPI,
|
| 8 |
Request,
|
|
@@ -13,7 +13,6 @@ from fastapi import (
|
|
| 13 |
from fastapi.background import BackgroundTasks
|
| 14 |
from fastapi.responses import RedirectResponse, JSONResponse
|
| 15 |
from fastapi.security.api_key import APIKeyHeader
|
| 16 |
-
from pydantic import BaseModel, Field, ConfigDict
|
| 17 |
from psycopg.errors import UniqueViolation
|
| 18 |
from sqlalchemy.exc import IntegrityError
|
| 19 |
from starlette.status import (
|
|
@@ -26,7 +25,7 @@ from dotenv import load_dotenv
|
|
| 26 |
from sqlalchemy import text
|
| 27 |
from sqlalchemy.orm import Session
|
| 28 |
|
| 29 |
-
from src.entity.api.transaction_api import TransactionApi
|
| 30 |
from src.service.fraud_service import check_for_fraud_api
|
| 31 |
from src.service.logging_service import setup_logging
|
| 32 |
from src.service.notification_service import send_notification
|
|
@@ -81,24 +80,6 @@ def redirect_to_docs():
|
|
| 81 |
Redirect to the API documentation.
|
| 82 |
'''
|
| 83 |
return RedirectResponse(url='/docs')
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
class TransactionProcessingOutput(BaseModel):
|
| 87 |
-
"""
|
| 88 |
-
TransactionProcessingOutput is a class that represents the output of the transaction processing endpoint.
|
| 89 |
-
It contains the fraud detection result and the fraud score.
|
| 90 |
-
This class is used as the response model for the /transaction/process endpoint.
|
| 91 |
-
"""
|
| 92 |
-
is_fraud: int = Field(description="The prediction result. 1 if the transaction is detected as fraudulent, 0 otherwise.")
|
| 93 |
-
fraud_score: float = Field(description="Probability of transaction being fraudulent.")
|
| 94 |
-
|
| 95 |
-
model_config: ClassVar[ConfigDict] = ConfigDict(
|
| 96 |
-
json_schema_extra = {
|
| 97 |
-
"example": {
|
| 98 |
-
"is_fraud": 1,
|
| 99 |
-
"fraud_score": 0.85
|
| 100 |
-
}
|
| 101 |
-
})
|
| 102 |
|
| 103 |
@app.get("/transaction/get_fraud_status/{transaction_number}",
|
| 104 |
tags=["transaction"],
|
|
|
|
| 2 |
import logging
|
| 3 |
import secrets
|
| 4 |
import requests
|
| 5 |
+
from typing import Annotated, Generator
|
| 6 |
from fastapi import (
|
| 7 |
FastAPI,
|
| 8 |
Request,
|
|
|
|
| 13 |
from fastapi.background import BackgroundTasks
|
| 14 |
from fastapi.responses import RedirectResponse, JSONResponse
|
| 15 |
from fastapi.security.api_key import APIKeyHeader
|
|
|
|
| 16 |
from psycopg.errors import UniqueViolation
|
| 17 |
from sqlalchemy.exc import IntegrityError
|
| 18 |
from starlette.status import (
|
|
|
|
| 25 |
from sqlalchemy import text
|
| 26 |
from sqlalchemy.orm import Session
|
| 27 |
|
| 28 |
+
from src.entity.api.transaction_api import TransactionApi, TransactionProcessingOutput
|
| 29 |
from src.service.fraud_service import check_for_fraud_api
|
| 30 |
from src.service.logging_service import setup_logging
|
| 31 |
from src.service.notification_service import send_notification
|
|
|
|
| 80 |
Redirect to the API documentation.
|
| 81 |
'''
|
| 82 |
return RedirectResponse(url='/docs')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
@app.get("/transaction/get_fraud_status/{transaction_number}",
|
| 85 |
tags=["transaction"],
|