Skip to content

Commit

Permalink
Merge pull request WING-NUS#358 from mengyewgau/get_route_params
Browse files Browse the repository at this point in the history
Update JSON responses for GET /api/v1/assignments/{assignment_id}/submission_similarities/
  • Loading branch information
sibinhho99 authored Oct 9, 2023
2 parents c036702 + f06b9ea commit 8696768
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 29 additions & 6 deletions app/controllers/api/v1/submission_similarities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,39 @@ def set_course_and_assignment(assignment_id = params[:assignment_id])
end

def render_submission_similarities
assignment = Assignment.find_by(id: params[:assignment_id])
assignment = set_course_and_assignment(params[:assignment_id])

if assignment.nil?
render json: { error: 'Assignment does not exist' }, status: :bad_request
return
end
# Check if the assignment has associated submission files.
if assignment.submissions.empty?
render json: { status: 'empty' }, status: :ok
return
end

# Determine process status of assignment
submission_similarity_process = assignment.submission_similarity_process
case submission_similarity_process.status
when SubmissionSimilarityProcess::STATUS_RUNNING, SubmissionSimilarityProcess::STATUS_WAITING
render json: { status: 'processing' }, status: :ok
return
when SubmissionSimilarityProcess::STATUS_ERRONEOUS
render json: { status: 'error', message: 'SSID is busy or under maintenance. Please try again later.' },
status: :service_unavailable
return
end

submission_similarities = assignment.submission_similarities

### Filtering Code
# Apply the threshold filter
if params[:threshold].present?
threshold_value = params[:threshold].to_f
submission_similarities = submission_similarities.where('similarity >= ?', threshold_value)
end

# Apply the limit filter
if params[:limit].present?
limit_value = params[:limit].to_i
Expand All @@ -68,15 +92,14 @@ def render_submission_similarities

# Apply the page filter
if params[:page].present?
per_page = params[:limit].present? ?limit_value : 20 # Default per page value is 20, limit to use a page size
per_page = params[:limit].present? ? limit_value : 20 # Default per page value is 20, limit to use a page size
page_number = params[:page].to_i
submission_similarities = submission_similarities.offset(per_page * (page_number - 1))
end


render json: submission_similarities
render json: { status: 'processed', submissionSimilarities: submission_similarities }, status: :ok
end

def render_pair_of_flagged_submissions
submission_similarity = SubmissionSimilarity.find_by(
assignment_id: params[:assignment_id],
Expand Down
2 changes: 1 addition & 1 deletion doc/SSID_API_Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Content-Type: application/octet-stream
| Code | Status | Return body |
| ---- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 200 | Successful | `{ "status": "empty" }` **[Note: This status, currently in SSID's web interface, is for when the user did not include a zip file when creating an assignment. To rectify this, the user must upload the file via the web interface. When submitting through API, the zip assignment file is compulsory.]**, `{ "status": "processing" }`, or `{ "status": "processed", "submissionSimilarities": [] }` |
| 400 | Error | `{ “error”: “Submission similarities requested does not exist." }` |
| 400 | Error | `{ “error”: “Submission similarities requested does not exist." }`, `{ “error”: “Assignment does not exist" }` |
| 401 | Unauthorized | `{ "error": "Missing or invalid API key." }` or `{ "error": "Your API key is not authorized to access this resource." }` |
| 503 | Service Unavailable | `{ "error": "SSID is busy or under maintenance. Please try again later." }` |

Expand Down

0 comments on commit 8696768

Please sign in to comment.