Skip to content

Commit

Permalink
fix: backend for delete and edit objects by ID instead of profile name
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekzyla committed Sep 16, 2022
1 parent 75705b7 commit 87ef861
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bson import json_util
from bson import json_util, ObjectId
from flask import Flask, request
from flask_cors import cross_origin
from pymongo import MongoClient
Expand Down Expand Up @@ -56,19 +56,19 @@ def add_profile_record():
db.profiles.insert_one(profile_obj)
return "success"

@app.route('/profiles/delete/<profile_name>', methods=['POST'])
@app.route('/profiles/delete/<profile_id>', methods=['POST'])
@cross_origin(origin='*', headers=['access-control-allow-origin', 'Content-Type'])
def delete_profile_record(profile_name):
db.profiles.delete_one({'profileName': profile_name})
def delete_profile_record(profile_id):
db.profiles.delete_one({'_id': ObjectId(profile_id)})
return "success"

@app.route('/profiles/update/<profile_name>', methods=['POST'])
@app.route('/profiles/update/<profile_id>', methods=['POST'])
@cross_origin(origin='*', headers=['access-control-allow-origin', 'Content-Type'])
def update_profile_record(profile_name):
def update_profile_record(profile_id):
profile_obj = request.json
print(f"{profile_obj}")
new_values = {"$set": profile_obj}
db.profiles.update_one({'profileName': profile_name}, new_values)
db.profiles.update_one({'_id': ObjectId(profile_id)}, new_values)
return "success"


Expand Down

0 comments on commit 87ef861

Please sign in to comment.