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/add spellcheck #34

Merged
merged 9 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.venv
.pytest_cache/
__pycache__
.vscode
.vscode
.env
27 changes: 17 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
'''

from flask import Flask, jsonify, request

from models import Education, Experience, Skill
from models import Experience, Education, Skill
from spell_check import spell_check

app = Flask(__name__)

Expand Down Expand Up @@ -57,6 +57,7 @@ def experience(index=None):
return jsonify({"error": "Experience not found"}), 404
return jsonify(data["experience"]), 200


if request.method == "POST":
try:
new_experience = request.get_json()
Expand All @@ -78,14 +79,25 @@ def experience(index=None):
data["experience"].append(experience_obj)
return jsonify({"id": len(data["experience"]) - 1}), 201

except TypeError as e:
except (ValueError, TypeError, KeyError) 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


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


@app.route('/resume/spell_check', methods=['POST'])
def spell_check():
json_data = request.json
if json_data.get('description') and isinstance(json_data.get('description'), str):
json_data['description'] = spell_check(json_data['description'])
return jsonify({
"before": request.json,
"after": json_data
})

@app.route("/resume/education", methods=["GET", "POST"])
def education():
'''
Expand All @@ -100,8 +112,6 @@ def education():
if request.method == "POST":
return jsonify({})

return jsonify({})


@app.route("/resume/skill", methods=["GET", "POST"])
def skill():
Expand All @@ -128,11 +138,8 @@ 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
except (ValueError, TypeError, KeyError) as e:
return jsonify({"error": f"Invalid request: {str(e)}"}), 400

return jsonify({})

Expand Down
13 changes: 13 additions & 0 deletions spell_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Module for spell checking functionality using autocorrect library.
"""

from autocorrect import Speller

spell = Speller(lang='en')

def spell_check(text):
'''
Spell checks the text
'''
return spell(text)
23 changes: 22 additions & 1 deletion test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''
from app import app


def test_client():
'''
Makes a request and checks the message received is the same
Expand Down Expand Up @@ -75,3 +75,24 @@ def test_skill():

response = app.test_client().get(f'/resume/skill/{item_id}')
assert response.json == example_skill

def test_spell_check():
'''
Test that the spell check endpoint returns a valid response
'''

example_education = {
"course": "Engineering",
"school": "NYU",
"start_date": "October 2022",
"end_date": "August 2024",
"grade": "86%",
"logo": "example-logo.png",
"description": "I was head of the debaite team at university",
"spell_check": True
}

response = app.test_client().post('/resume/education',
json=example_education)

assert response.json['description'] == "I was head of the debate team at university"
Loading