--- post: summary: Create an entity in a collection description: >- Create an entity in a collection with a given schema and a set of given properties in the database. This is not the API you want to be using to load bulk data, but only for interactive en
()
| 225 | |
| 226 | @blueprint.route("/api/2/entities", methods=["POST", "PUT"]) |
| 227 | def create(): |
| 228 | """ |
| 229 | --- |
| 230 | post: |
| 231 | summary: Create an entity in a collection |
| 232 | description: >- |
| 233 | Create an entity in a collection with a given schema and a set of given |
| 234 | properties in the database. This is not the API you want to be using to |
| 235 | load bulk data, but only for interactive entity manipulation in the UI. |
| 236 | Always use the `bulk` API or for loading source datasets, no |
| 237 | exceptions. |
| 238 | parameters: |
| 239 | - in: query |
| 240 | name: sign |
| 241 | description: Sign entity IDs referenced in nested properties. |
| 242 | required: false |
| 243 | schema: |
| 244 | type: boolean |
| 245 | requestBody: |
| 246 | content: |
| 247 | application/json: |
| 248 | schema: |
| 249 | $ref: '#/components/schemas/EntityCreate' |
| 250 | responses: |
| 251 | '200': |
| 252 | description: Resturns the created entity |
| 253 | content: |
| 254 | application/json: |
| 255 | schema: |
| 256 | $ref: '#/components/schemas/Entity' |
| 257 | tags: |
| 258 | - Entity |
| 259 | """ |
| 260 | data = parse_request("EntityCreate") |
| 261 | collection = get_nested_collection(data, request.authz.WRITE) |
| 262 | data.pop("id", None) |
| 263 | if get_flag("validate", default=False): |
| 264 | validate_entity(data) |
| 265 | entity_id = upsert_entity( |
| 266 | data, |
| 267 | collection, |
| 268 | authz=request.authz, |
| 269 | sync=True, |
| 270 | sign=get_flag("sign", default=False), |
| 271 | job_id=get_session_id(), |
| 272 | ) |
| 273 | db.session.commit() |
| 274 | tag_request(entity_id=entity_id, collection_id=collection.id) |
| 275 | entity = get_index_entity(entity_id, request.authz.READ) |
| 276 | return EntitySerializer.jsonify(entity) |
| 277 | |
| 278 | |
| 279 | @blueprint.route("/api/2/documents/<entity_id>", methods=["GET"]) |
nothing calls this directly
no test coverage detected