def view(diagram_id): """Return the diagram with id `diagram_id`. --- get: summary: Fetch a diagram parameters: - description: The diagram id. in: path name: diagram_id required: true schema: minimum: 1 type: integer example: 2 responses: '200': content: application/json: schema: $ref: '#/components/schemas/Diagram' description: OK tags: - Diagram """ diagram = obj_or_404(Diagram.by_id(diagram_id)) get_db_collection(diagram.collection_id, request.authz.READ) return DiagramSerializer.jsonify(diagram)
def delete(diagram_id): """Delete a diagram. --- delete: summary: Delete a diagram parameters: - description: The diagram id. in: path name: diagram_id required: true schema: minimum: 1 type: integer example: 2 responses: '204': description: No Content tags: - Diagram """ diagram = obj_or_404(Diagram.by_id(diagram_id)) collection = get_db_collection(diagram.collection_id, request.authz.WRITE) diagram.delete() collection.touch() db.session.commit() return ('', 204)
def update(diagram_id): """Update the diagram with id `diagram_id`. --- post: summary: Update a diagram parameters: - description: The diagram id. in: path name: diagram_id required: true schema: minimum: 1 type: integer example: 2 requestBody: content: application/json: schema: $ref: '#/components/schemas/DiagramUpdate' responses: '200': content: application/json: schema: $ref: '#/components/schemas/Diagram' description: OK tags: - Diagram """ diagram = obj_or_404(Diagram.by_id(diagram_id)) collection = get_db_collection(diagram.collection_id, request.authz.WRITE) data = parse_request('DiagramUpdate') diagram.update(data, collection) collection.touch() db.session.commit() return DiagramSerializer.jsonify(diagram)
def get_diagram(diagram_id): return Diagram.by_id(diagram_id)