-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (46 loc) · 1.59 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask, request, jsonify
from extractFamilyDetails import start
from flask_cors import CORS
from dotenv import load_dotenv
from treebuilder import getSampleData, getFamilyTree
from utils import validateStringNotEmpty
load_dotenv()
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})
@app.route('/', methods=['GET'])
def helloWorld():
return 'hello world', 200
@app.route('/', methods=['POST'])
def getFamilyDetails():
data = request.json
nameValidation = validateStringNotEmpty("name", data)
if nameValidation:
return nameValidation
dobValidation = validateStringNotEmpty("dob", data)
if dobValidation:
return dobValidation
stateValidation = validateStringNotEmpty("state", data)
if stateValidation:
return stateValidation
genderValidation = validateStringNotEmpty("gender", data)
if genderValidation:
return genderValidation
relationValidation = validateStringNotEmpty("relationName", data)
if relationValidation:
return relationValidation
name = data["name"]
dob = data['dob']
state = data['state']
gender = data['gender']
relationName = data['relationName']
if(state != "KA"):
return "State Not Supported", 400
res = start(name, dob, gender, relationName)
return jsonify({"data": res})
@app.route('/sample', methods=['GET'])
def getSampleFamilyTree():
sampleInput = getSampleData()
familyTree = getFamilyTree(getSampleData())
return jsonify({"sampleInput": sampleInput, "familyTree": familyTree})
if __name__ == '__main__':
app.run()