Create a new file based on the PydanticFileMetadata schema.
(self, file_metadata: PydanticFileMetadata, actor: PydanticUser)
| 125 | |
| 126 | @enforce_types |
| 127 | def create_file(self, file_metadata: PydanticFileMetadata, actor: PydanticUser) -> PydanticFileMetadata: |
| 128 | """Create a new file based on the PydanticFileMetadata schema.""" |
| 129 | db_file = self.get_file_by_id(file_metadata.id, actor=actor) |
| 130 | if db_file: |
| 131 | return db_file |
| 132 | else: |
| 133 | with self.session_maker() as session: |
| 134 | file_metadata.organization_id = actor.organization_id |
| 135 | file_metadata = FileMetadataModel(**file_metadata.model_dump(to_orm=True, exclude_none=True)) |
| 136 | file_metadata.create(session, actor=actor) |
| 137 | return file_metadata.to_pydantic() |
| 138 | |
| 139 | # TODO: We make actor optional for now, but should most likely be enforced due to security reasons |
| 140 | @enforce_types |
no test coverage detected