def put_document(doc_id: str): ### # Update a document by doc_id ## errors = [] request = flask_rebar.get_validated_body() app.logger.debug(request) rc = 204 # Get the document from the store by ID doc = Document.query.get(doc_id) if not doc: # Create a new doc app.logger.debug(f'Creating new doc via PUT: {doc_id}') doc = Document( doc_id = doc_id, title = request['title'], text = request['text'], created = datetime.utcnow() ) db.session.add(doc) db.session.commit() rc = 201 else: # Update existing app.logger.debug(f'Updated existing doc via PUT: {doc_id}') doc.title = request['title'] doc.text = request['text'] doc.updated = datetime.utcnow() db.session.add(doc) db.session.commit() return { 'errors': errors, }, rc