-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1477 from bcgov/feat/daniel-requir-other-1455
feat: Add validation rule for other_fuel_type
- Loading branch information
Showing
8 changed files
with
122 additions
and
16 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 |
---|---|---|
@@ -1,17 +1,34 @@ | ||
from fastapi import Depends, Request | ||
from fastapi import Depends | ||
from fastapi.exceptions import RequestValidationError | ||
|
||
from lcfs.web.api.fuel_code.repo import FuelCodeRepository | ||
from lcfs.web.api.fuel_supply.repo import FuelSupplyRepository | ||
from lcfs.web.api.fuel_supply.schema import FuelSupplyCreateUpdateSchema | ||
|
||
|
||
class FuelSupplyValidation: | ||
def __init__( | ||
self, | ||
request: Request = None, | ||
fs_repo: FuelSupplyRepository = Depends(FuelSupplyRepository), | ||
fc_repo: FuelCodeRepository = Depends(FuelCodeRepository), | ||
): | ||
self.fs_repo = fs_repo | ||
self.request = request | ||
self.fc_repo = fc_repo | ||
|
||
async def check_duplicate(self, fuel_supply: FuelSupplyCreateUpdateSchema): | ||
return await self.fs_repo.check_duplicate(fuel_supply) | ||
|
||
async def validate_other(self, fuel_supply: FuelSupplyCreateUpdateSchema): | ||
fuel_type = await self.fc_repo.get_fuel_type_by_id(fuel_supply.fuel_type_id) | ||
|
||
if fuel_type.unrecognized: | ||
if not fuel_supply.fuel_type_other: | ||
raise RequestValidationError( | ||
[ | ||
{ | ||
"loc": ("fuelTypeOther",), | ||
"msg": "required when using Other", | ||
"type": "value_error", | ||
} | ||
] | ||
) |
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