Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Delete an existing skill #39

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
98 changes: 24 additions & 74 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,6 @@ def hello_world():
'''
return jsonify({"message": "Hello, World!"})


@app.route("/resume/experience", methods=["GET", "POST"])
@app.route("/resume/experience/<int:index>", methods=["GET", "DELETE"])
def experience(index=None):
'''
Handle experience requests
GET: Returns all experiences or a specific experience by index
POST: Creates a new experience
'''
if request.method == "GET":
if index is not None:
try:
return jsonify(data["experience"][index])
except IndexError:
return jsonify({"error": "Experience not found"}), 404
return jsonify(data["experience"]), 200

if request.method == 'POST':
json_data = request.json
try:
validated_data = validate_experience(json_data)

data["experience"].append(validated_data)
return jsonify({"id": len(data["experience"]) - 1}), 201
except TypeError as e:
return jsonify({"error": f"Invalid data format: {str(e)}"}), 400
except Exception as e:
return jsonify({"error": f"Internal error: {str(e)}"}), 500

if request.method == "DELETE":
try:
if index is None or index < 0 or index >= len(data["experience"]):
return jsonify({"message": "Resource doesn't exist"}), 404
else:
data['experience'].pop(index)
return jsonify({"message": "Experience Successfully Deleted"}), 200
except Exception as e:
return jsonify({"error": f"An error occurred: {str(e)}"}), 500

return jsonify({"error": "Method not allowed"}), 405

@app.route('/resume/spell_check', methods=['POST'])
def spell_check():
json_data = request.json
Expand All @@ -92,33 +51,6 @@ def spell_check():
"after": json_data
})

@app.route("/resume/education", methods=["GET", "POST"])
@app.route("/resume/education/<int:edu_id>", methods=["GET", "DELETE"])
def education(edu_id=None):
'''
Handles education requests
GET: Returns all educations (unimplemented here)
POST: Creates a new education (unimplemented here)
DELETE: Deletes an education by index
'''
if request.method == "GET":
return jsonify({})

if request.method == "POST":
return jsonify({})

if request.method == "DELETE":
try:
if edu_id is None or edu_id < 0 or edu_id >= len(data["education"]):
return jsonify({"message": "Resource doesn't exist"}), 404
else:
del data["education"][edu_id]
return jsonify({"message": "Education Successfully Deleted"}), 200
except Exception as e:
return jsonify({"error": f"An error occurred: {str(e)}"}), 500

return jsonify({})

@app.route('/resume/reword_description', methods=['GET'])
def reword_description():
'''
Expand All @@ -140,7 +72,8 @@ def reword_description():
return jsonify({"response": response})

@app.route("/resume/skill", methods=["GET", "POST"])
def skill():
@app.route('/resume/skill/<int:skill_id>', methods=['DELETE'])
def skill(skill_id = None):
'''
Handles Skill requests
'''
Expand All @@ -159,17 +92,34 @@ def skill():
{"id": len(data["skill"]) - 1}
), 201


except KeyError:
return jsonify({"error": "Invalid request"}), 400

except TypeError as e:
return jsonify({"error": str(e)}), 400
if request.method == "DELETE":
try:
if skill_id is None or skill_id < 0 or skill_id >= len(data["skill"]):
return jsonify({"message": "Resource doesn't exist"}), 404
else:
del data['skill'][skill_id]
return jsonify({"message": "Skill Successfully Deleted"}), 200
except (ValueError, TypeError, KeyError) as e:
return jsonify({"error": f"Invalid request: {str(e)}"}), 400
except Exception as e:
return jsonify({"error": f"An error occurred: {str(e)}"}), 500

return jsonify({})

@app.route('/resume/skill/<int:skill_id>', methods=['GET'])
def get_skill(skill_id):
'''
Get a specific skill
'''
try:
return jsonify(data["skill"][skill_id].__dict__)
except IndexError:
return jsonify({"error": "Skill not found"}), 404

if request.method == "GET":
try:
return jsonify(data["skill"][skill_id].__dict__)
except IndexError:
return jsonify({"error": "Skill not found"}), 404
Loading