Fix more decimal conversion issues
This commit is contained in:
parent
e1c1738818
commit
cfea8b5889
@ -2,7 +2,8 @@ from datetime import datetime
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from beanie import Document
|
from beanie import Document
|
||||||
from pydantic import BaseModel
|
from bson import Decimal128
|
||||||
|
from pydantic import BaseModel, validator
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from backend.services.project.constants import MilestoneStatus
|
from backend.services.project.constants import MilestoneStatus
|
||||||
@ -16,6 +17,18 @@ class Milestone(BaseModel):
|
|||||||
expected_payment: Decimal
|
expected_payment: Decimal
|
||||||
actual_paid: Decimal
|
actual_paid: Decimal
|
||||||
|
|
||||||
|
@validator("expected_payment", pre=True)
|
||||||
|
def convert_decimal128_expected_payment(cls, value):
|
||||||
|
if isinstance(value, Decimal128):
|
||||||
|
return value.to_decimal() # Convert MongoDB Decimal128 to Python Decimal
|
||||||
|
return value
|
||||||
|
|
||||||
|
@validator("actual_paid", pre=True)
|
||||||
|
def convert_decimal128_actual_paid(cls, value):
|
||||||
|
if isinstance(value, Decimal128):
|
||||||
|
return value.to_decimal() # Convert MongoDB Decimal128 to Python Decimal
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
class ProjectDoc(Document):
|
class ProjectDoc(Document):
|
||||||
product_id: str
|
product_id: str
|
||||||
|
|||||||
@ -3,6 +3,8 @@ from backend.application.payment_hub import PaymentHub
|
|||||||
from typing import Dict, Optional, Tuple
|
from typing import Dict, Optional, Tuple
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from backend.services.project.models import ProjectDoc
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
payment_hub = PaymentHub()
|
payment_hub = PaymentHub()
|
||||||
|
|
||||||
@ -190,6 +192,28 @@ async def fetch_checkout_session_url(
|
|||||||
async def invoke_checkout_session_webhook():
|
async def invoke_checkout_session_webhook():
|
||||||
return await payment_hub.invoke_checkout_session_webhook()
|
return await payment_hub.invoke_checkout_session_webhook()
|
||||||
|
|
||||||
|
@router.get(
|
||||||
|
"/test/{user_id}",
|
||||||
|
operation_id="test",
|
||||||
|
summary="test user_id",
|
||||||
|
description="test user_id",
|
||||||
|
)
|
||||||
|
async def test(
|
||||||
|
user_id: str
|
||||||
|
):
|
||||||
|
return user_id
|
||||||
|
|
||||||
|
@router.get(
|
||||||
|
"/testproj/{project_id}",
|
||||||
|
operation_id="test",
|
||||||
|
summary="test project_id",
|
||||||
|
description="test project_id",
|
||||||
|
)
|
||||||
|
async def test_project(
|
||||||
|
project_id: str
|
||||||
|
):
|
||||||
|
return await ProjectDoc.get(project_id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user