Code: Select all
Organization
Code: Select all
organization_id
Code: Select all
def get_organization_from_body(organization_id: str = Body(None),
user: User = Depends(get_authenticated_user),
organization_service: OrganizationService = Depends(get_organization_service),
) -> Organization:
if not organization_id:
raise HTTPException(status_code=400, detail='Missing organization_id.')
organization = organization_service.get_organization_for_user(organization_id, user)
if not organization:
raise HTTPException(status_code=403, detail='Organization authorization failed.')
return organization
Code: Select all
@router.post('', response_model=Bundle)
async def create_bundle([...]
organization: Organization = Depends(get_organization_from_body),
) -> Model:
Code: Select all
{
'name': generated_name,
'organization_id': created_organization['id_key']
}
< /code>
und Hinzufügen meines eingehenden pydantischen Modells: < /p>
@router.post('', response_model=Bundle)
async def create_bundle(bundle: BundleCreate,
organization: Organization = Depends(get_organization_from_body),
[...]
) -> BundleModel:
[...]
return bundle
< /code>
Das Ergebnis ist dasselbe, ob das pydantische Modell /Schema organisation_id < /code> als Feld enthält oder nicht: < /p>
class BundleBase(BaseModel):
name: str
class Config:
orm_mode = True
class BundleCreate(BundleBase):
organization_id: str
client_id: Optional[str]
Code: Select all
{'detail': [{'loc': ['body', 'bundle'], 'msg': 'field required', 'type': 'value_error.missing'}]}
Code: Select all
{
'bundle': {
'name': generated_name,
},
'organization_id': created_organization['id_key']
}