diff --git a/backend/project/endpoints/index/OpenAPI_Object.json b/backend/project/endpoints/index/OpenAPI_Object.json index 7243ff59..7b855bbd 100644 --- a/backend/project/endpoints/index/OpenAPI_Object.json +++ b/backend/project/endpoints/index/OpenAPI_Object.json @@ -41,5 +41,376 @@ } ] }, - "paths": [] + "paths": { + "/submissions/{uid}/{pid}": { + "get": { + "summary": "Get all submissions from a user for a project", + "responses": { + "200": { + "description": "A list of submission URLs", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "submissions": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + } + }, + "404": { + "description": "A 'not found' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "An error message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + }, + "post": { + "summary": "Post a new submission to a project", + "requestBody": { + "description": "Grading", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "grading": { + "type": "int", + "minimum": 0, + "maximum": 20 + } + } + } + } + } + }, + "responses": { + "201": { + "description": "The newly created submission URL", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "submission": { + "type": "string" + } + } + } + } + } + }, + "400": { + "description": "A 'bad data field' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "404": { + "description": "A 'not found' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "An error message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + }, + "parameters": [ + { + "name": "uid", + "in": "path", + "description": "User ID", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "pid", + "in": "path", + "description": "Project ID", + "required": true, + "schema": { + "type": "int" + } + } + ] + }, + "/submissions/{sid}": { + "get": { + "summary": "Get the submission", + "responses": { + "200": { + "description": "The submission", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "submission_id": { + "type": "int" + }, + "uid": { + "type": "string" + }, + "project_id": { + "type": "int" + }, + "grading": { + "type": "int" + }, + "submission_time": { + "type": "string" + }, + "submission_path": { + "type": "string" + }, + "submission_status": { + "type": "int" + } + } + } + } + } + }, + "404": { + "description": "A 'not found' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "An error message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + }, + "patch": { + "summary": "Update the submission", + "requestBody": { + "description": "The submission data", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "grading": { + "type": "int", + "minimum": 0, + "maximum": 20 + } + } + } + } + } + }, + "responses": { + "200": { + "description": "A 'submission updated' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "400": { + "description": "A 'bad data field' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "404": { + "description": "A 'not found' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "An error message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + }, + "delete": { + "summary": "Delete the submission", + "responses": { + "200": { + "description": "A 'submission deleted' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "404": { + "description": "A 'not found' message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + }, + "500": { + "description": "An error message", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + }, + "parameters": [ + { + "name": "sid", + "in": "path", + "description": "Submission ID", + "required": true, + "schema": { + "type": "int" + } + } + ] + } + } } diff --git a/backend/project/endpoints/submissions.py b/backend/project/endpoints/submissions.py index caf8b5b2..f6c4e4d8 100644 --- a/backend/project/endpoints/submissions.py +++ b/backend/project/endpoints/submissions.py @@ -126,10 +126,6 @@ def post(self, uid: str, pid: int) -> dict[str, any]: return {"message": f"An error occurred while creating a new submission " f"for user {uid} in project {pid}"}, 500 -submissions_bp.add_url_rule( - "/submissions//", - view_func=Submissions.as_view("submissions")) - class Submission(Resource): """API endpoint for the submission""" @@ -218,7 +214,7 @@ def patch(self, sid:int) -> dict[str, any]: # Save the submission session.commit() - return {"message": "Submission {sid} updated"} + return {"message": f"Submission {sid} updated"} except Exception: session.rollback() return {"message": f"An error occurred while patching submission {sid}"}, 500 @@ -262,6 +258,9 @@ def delete(self, sid: int) -> dict[str, any]: db.session.rollback() return {"message": f"An error occurred while deleting submission {sid}"}, 500 +submissions_bp.add_url_rule( + "/submissions//", + view_func=Submissions.as_view("submissions")) submissions_bp.add_url_rule( "/submissions/", view_func=Submission.as_view("submission"))