From e8822a8d3a0069c1f38bfb3c010d08d4566f8b06 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 7 Mar 2021 20:38:49 -0700 Subject: [PATCH] Add route to create client --- server/main.py | 33 ++++++++++++++++++++++++++++++--- server/output/.gitkeep | 0 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 server/output/.gitkeep diff --git a/server/main.py b/server/main.py index aabbdd4..cc77a02 100644 --- a/server/main.py +++ b/server/main.py @@ -1,10 +1,37 @@ -from flask import Flask +import os +import json +from pathlib import Path +from flask import Flask, request from flask_cors import CORS -build_folder = '../client/build' -app = Flask(__name__, static_folder=build_folder, static_url_path='') +build_folder = Path('../client/build') +output_folder = Path('./output') +app = Flask(__name__, static_folder=str(build_folder), static_url_path='') CORS(app) +@app.route('/api/clients', methods=['POST']) +def clients(): + content = request.json + print('Recieved:', content) + + phone = str(content['phone']) + + for i in range(1, 100): + suffix = str(i).zfill(3) + folder = phone + '_' + suffix + path = output_folder / folder + if not path.exists(): + break + + path.mkdir() + info_file = path / 'info.json' + info_file.touch() + info_file.write_text(json.dumps(content, indent=4)) + + client_id = folder + + return {'client_id': client_id} + @app.route('/') def index(): return app.send_static_file('index.html') diff --git a/server/output/.gitkeep b/server/output/.gitkeep new file mode 100644 index 0000000..e69de29