-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
514 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from fastapi import HTTPException, status | ||
|
||
from uselevers.core.exceptions import HTTPExceptionExtra, HTTPSimpleError | ||
|
||
|
||
class ReferenceValueConflict(HTTPException, HTTPExceptionExtra): | ||
def __init__(self) -> None: | ||
super().__init__( | ||
status_code=self.status_code, | ||
detail=HTTPSimpleError( | ||
message="Bill reference conflict", | ||
errors={ | ||
"reference": [ | ||
"Bill reference value already exists. " | ||
"Please select another value." | ||
] | ||
}, | ||
).model_dump(), | ||
) | ||
|
||
model = HTTPSimpleError | ||
status_code = status.HTTP_409_CONFLICT | ||
examples = { | ||
"detail": { | ||
"message": "Bill reference conflict", | ||
"errors": { | ||
"reference": [ | ||
"Bill reference value already exists. Please select another value." | ||
] | ||
}, | ||
} | ||
} |
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,18 @@ | ||
from sqlalchemy.orm import Session | ||
|
||
from . import models, schemas | ||
|
||
|
||
def save_billspec(db: Session, bill_data: schemas.BillSpec) -> models.Bill: | ||
# Create a new instance of models.Bill directly | ||
bill = models.Bill(total=bill_data.total) | ||
# Process sub_bills | ||
for sub_bill_data in bill_data.sub_bills: | ||
sub_bill = models.SubBill( | ||
amount=sub_bill_data.amount, reference=sub_bill_data.reference | ||
) | ||
bill.sub_bills.append(sub_bill) | ||
|
||
db.add(bill) | ||
db.flush() | ||
return bill |
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
Oops, something went wrong.