Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed

- No fixes recorded yet
- `/api/recommend` now returns all validation errors in a single response instead of only the first one, so users can correct every invalid field at once
6 changes: 3 additions & 3 deletions routes/main_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Each route is kept thin: it validates input, calls a utility function,
# and returns a response. No business logic lives here.

import os

from flask import Blueprint, render_template, request, jsonify, send_from_directory, abort

from utils.recommender import get_recommendations, validate_recommendation_inputs
Expand Down Expand Up @@ -44,8 +46,7 @@ def recommend():
# Validate before running the recommendation engine
errors = validate_recommendation_inputs(skills, level, interest, time_availability)
if errors:
# Return only the first error to keep the UI message clean
return jsonify({"error": errors[0]}), 400
return jsonify({"errors": errors}), 400

results = get_recommendations(skills, level, interest, time_availability)

Expand Down Expand Up @@ -95,6 +96,5 @@ def download_code(project_id):
if not full_path:
abort(404)

import os
filename = os.path.basename(full_path)
return send_from_directory(get_starter_code_dir(), filename, as_attachment=True)
5 changes: 3 additions & 2 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,10 @@ if (isIndexPage) {
.then(function (res) { return res.json(); })
.then(function (data) {
setLoadingState(false);
if (data.error) {
if (data.errors && data.errors.length) {
// Show all validation errors joined so the user can fix every field at once
var generalErr = document.getElementById("form-error-general");
if (generalErr) generalErr.textContent = data.error;
if (generalErr) generalErr.textContent = data.errors.join(" | ");
return;
}
renderResults(data.projects || [], data.message);
Expand Down
5 changes: 4 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ def test_recommend_api_missing_field():
"time": "Low"
})
assert response.status_code in (400, 415)
assert "error" in response.get_json()
data = response.get_json()
assert "errors" in data
assert isinstance(data["errors"], list)
assert len(data["errors"]) > 0


def test_recommend_api_empty_body():
Expand Down
Loading