File tree Expand file tree Collapse file tree 1 file changed +29
-6
lines changed
Expand file tree Collapse file tree 1 file changed +29
-6
lines changed Original file line number Diff line number Diff line change 1- from flask import Flask , render_template , request
1+ from flask import Flask , render_template , request , jsonify
22from pymongo import MongoClient
3+ from flask_cors import CORS
4+ import json
35
46app = Flask (__name__ )
7+ cors = CORS (app )
58
69client = MongoClient ("localhost" , 27017 )
710
8- db = client .flask_db
11+ db = client .financialDB
912creditCards = db .creditCards
1013
11- @app .route ("/" , methods = ( 'GET' , 'POST' ) )
14+ @app .route ("/" )
1215def index ():
1316 return render_template ('index.html' )
1417
15- @app .route ("/newCard" )
16- def newCard ():
17- return "New Card"
18+ @app .route ("/creditCards" , methods = ['GET' , 'POST' ])
19+ def Cards ():
20+ if request .method == "POST" :
21+ jsonContent = request .get_json ();
22+
23+ creditCards .insert_one (jsonContent )
24+ return {"message" : "Credit card added!" }, 201
25+
26+
27+ allCreditCards = creditCards .find ()
28+
29+ creditCards_list = []
30+
31+ for creditCard in allCreditCards :
32+ creditCard_dict = {
33+ "id" : str (creditCard ["_id" ]),
34+ "bank" : creditCard ["bank" ],
35+ "limit" : creditCard ["limit_total" ]
36+ }
37+
38+ creditCards_list .append (creditCard_dict )
39+
40+ return jsonify (creditCards_list )
You can’t perform that action at this time.
0 commit comments