From d90f1967b79af8654aef814dc7a4ccccd87e3cc8 Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Sat, 9 Jun 2018 20:57:44 +0800 Subject: [PATCH 01/22] Add ProgrammingSubmissionController API spec --- .../programming_submission_controller.ex | 64 +++++++++++++++++++ lib/cadet_web/router.ex | 3 + ...programming_submission_controller_test.exs | 11 ++++ 3 files changed, 78 insertions(+) create mode 100644 lib/cadet_web/controllers/programming_submission_controller.ex create mode 100644 test/cadet_web/controllers/programming_submission_controller_test.exs diff --git a/lib/cadet_web/controllers/programming_submission_controller.ex b/lib/cadet_web/controllers/programming_submission_controller.ex new file mode 100644 index 000000000..707bb28ae --- /dev/null +++ b/lib/cadet_web/controllers/programming_submission_controller.ex @@ -0,0 +1,64 @@ +defmodule CadetWeb.ProgrammingSubmissionController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :create do + post("/submission/programming") + + summary("Create a new submission of a particular mission.") + + security([%{JWT: []}]) + + consumes("application/json") + + parameters do + mission_id(:body, :integer, "mission id", required: true) + answer(:body, Schema.ref(:ProgrammingSubmission), "answer", required: true) + end + + response(200, "OK") + response(400, "Missing parameter(s)") + response(401, "Unauthorised") + end + + swagger_path :update do + post("/submission/programming/{submissionId}") + + summary("Updates an existing submission") + + security([%{JWT: []}]) + + consumes("application/json") + + parameters do + submissionId(:path, :integer, "submission id", required: true) + answer(:body, Schema.ref(:ProgrammingSubmission), "answer", required: true) + end + + response(200, "OK") + response(400, "Missing parameter(s))") + response(401, "Unauthorised") + end + + def swagger_definitions do + %{ + ProgrammingSubmission: + swagger_schema do + title("Submission for answers to programming questions") + + properties do + submitted(:boolean, "Whether this is the final submission", default: false) + + answer( + Schema.new do + properties do + code(:string, "Code submitted", required: true) + end + end + ) + end + end + } + end +end diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index a722aa289..ad4235b72 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -28,6 +28,9 @@ defmodule CadetWeb.Router do # Authenticated Pages scope "/", CadetWeb do pipe_through([:api, :auth, :ensure_auth]) + + post("/submission/programming", ProgrammingSubmissionController, :create) + post("/submission/programming/:id", ProgrammingSubmissionController, :update) end # Other scopes may use custom stacks. diff --git a/test/cadet_web/controllers/programming_submission_controller_test.exs b/test/cadet_web/controllers/programming_submission_controller_test.exs new file mode 100644 index 000000000..d9c7a626b --- /dev/null +++ b/test/cadet_web/controllers/programming_submission_controller_test.exs @@ -0,0 +1,11 @@ +defmodule CadetWeb.ProgrammingSubmissionControllerTest do + use CadetWeb.ConnCase + + alias CadetWeb.ProgrammingSubmissionController + + test "swagger" do + ProgrammingSubmissionController.swagger_definitions() + ProgrammingSubmissionController.swagger_path_create(nil) + ProgrammingSubmissionController.swagger_path_update(nil) + end +end From cf736a72b7583ffa11a21efd606406985f29e9ec Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Sat, 9 Jun 2018 21:28:17 +0800 Subject: [PATCH 02/22] API docs for both MCQ and Programming Submission --- .../controllers/mcq_submission_controller.ex | 45 +++++++++++++++++++ .../programming_submission_controller.ex | 32 +++---------- lib/cadet_web/router.ex | 5 ++- .../mcq_submission_controller_test.exs | 10 +++++ ...programming_submission_controller_test.exs | 3 +- 5 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 lib/cadet_web/controllers/mcq_submission_controller.ex create mode 100644 test/cadet_web/controllers/mcq_submission_controller_test.exs diff --git a/lib/cadet_web/controllers/mcq_submission_controller.ex b/lib/cadet_web/controllers/mcq_submission_controller.ex new file mode 100644 index 000000000..69142626d --- /dev/null +++ b/lib/cadet_web/controllers/mcq_submission_controller.ex @@ -0,0 +1,45 @@ +defmodule CadetWeb.MCQSubmissionController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :submit do + post("/submission/mcq") + + summary("Creates a new submission of a particular MCQ question.") + + security([%{JWT: []}]) + + consumes("application/json") + produces("application/json") + + parameters do + submission(:body, Schema.ref(:MCQSubmission), "submission", required: true) + end + + response(200, "OK", Schema.ref(:MCQCorrectness)) + response(400, "Missing parameter(s) or wrong submission type") + response(401, "Unauthorised") + end + + def swagger_definitions do + %{ + MCQSubmission: + swagger_schema do + properties do + questionId(:integer, "The question id", required: true) + + answer(:integer, "The index of the MCQ choice that is the answer", required: true) + end + end, + MCQCorrectness: + swagger_schema do + + properties do + correct(:boolean, "Whether the answer submitted was correct") + end + end + } + end + +end diff --git a/lib/cadet_web/controllers/programming_submission_controller.ex b/lib/cadet_web/controllers/programming_submission_controller.ex index 707bb28ae..170a6615b 100644 --- a/lib/cadet_web/controllers/programming_submission_controller.ex +++ b/lib/cadet_web/controllers/programming_submission_controller.ex @@ -3,41 +3,21 @@ defmodule CadetWeb.ProgrammingSubmissionController do use PhoenixSwagger - swagger_path :create do + swagger_path :submit do post("/submission/programming") - summary("Create a new submission of a particular mission.") + summary("Create/update a submission of a particular programming question.") security([%{JWT: []}]) consumes("application/json") parameters do - mission_id(:body, :integer, "mission id", required: true) - answer(:body, Schema.ref(:ProgrammingSubmission), "answer", required: true) + submission(:body, Schema.ref(:ProgrammingSubmission), "submission", required: true) end response(200, "OK") - response(400, "Missing parameter(s)") - response(401, "Unauthorised") - end - - swagger_path :update do - post("/submission/programming/{submissionId}") - - summary("Updates an existing submission") - - security([%{JWT: []}]) - - consumes("application/json") - - parameters do - submissionId(:path, :integer, "submission id", required: true) - answer(:body, Schema.ref(:ProgrammingSubmission), "answer", required: true) - end - - response(200, "OK") - response(400, "Missing parameter(s))") + response(400, "Missing parameter(s) or wrong submission type") response(401, "Unauthorised") end @@ -45,9 +25,9 @@ defmodule CadetWeb.ProgrammingSubmissionController do %{ ProgrammingSubmission: swagger_schema do - title("Submission for answers to programming questions") - properties do + questionId(:integer, "The question id", required: true) + submitted(:boolean, "Whether this is the final submission", default: false) answer( diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index ad4235b72..83e307c1f 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -29,8 +29,9 @@ defmodule CadetWeb.Router do scope "/", CadetWeb do pipe_through([:api, :auth, :ensure_auth]) - post("/submission/programming", ProgrammingSubmissionController, :create) - post("/submission/programming/:id", ProgrammingSubmissionController, :update) + post("/submission/programming", ProgrammingSubmissionController, :submit) + + post("/submission/mcq", MCQSubmissionController, :submit) end # Other scopes may use custom stacks. diff --git a/test/cadet_web/controllers/mcq_submission_controller_test.exs b/test/cadet_web/controllers/mcq_submission_controller_test.exs new file mode 100644 index 000000000..dc8a9e6f5 --- /dev/null +++ b/test/cadet_web/controllers/mcq_submission_controller_test.exs @@ -0,0 +1,10 @@ +defmodule CadetWeb.MCQSubmissionControllerTest do + use CadetWeb.ConnCase + + alias CadetWeb.MCQSubmissionController + + test "swagger" do + MCQSubmissionController.swagger_definitions() + MCQSubmissionController.swagger_path_submit(nil) + end +end diff --git a/test/cadet_web/controllers/programming_submission_controller_test.exs b/test/cadet_web/controllers/programming_submission_controller_test.exs index d9c7a626b..84ce00907 100644 --- a/test/cadet_web/controllers/programming_submission_controller_test.exs +++ b/test/cadet_web/controllers/programming_submission_controller_test.exs @@ -5,7 +5,6 @@ defmodule CadetWeb.ProgrammingSubmissionControllerTest do test "swagger" do ProgrammingSubmissionController.swagger_definitions() - ProgrammingSubmissionController.swagger_path_create(nil) - ProgrammingSubmissionController.swagger_path_update(nil) + ProgrammingSubmissionController.swagger_path_submit(nil) end end From 032f924f42d5e1c3b3be733e63df2ba0e7b42533 Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Sat, 9 Jun 2018 21:33:31 +0800 Subject: [PATCH 03/22] Reorganise files --- .../{ => submission}/mcq_submission_controller.ex | 2 +- .../{ => submission}/programming_submission_controller.ex | 2 +- lib/cadet_web/router.ex | 6 ++++-- .../{ => submission}/mcq_submission_controller_test.exs | 4 ++-- .../programming_submission_controller_test.exs | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) rename lib/cadet_web/controllers/{ => submission}/mcq_submission_controller.ex (94%) rename lib/cadet_web/controllers/{ => submission}/programming_submission_controller.ex (93%) rename test/cadet_web/controllers/{ => submission}/mcq_submission_controller_test.exs (58%) rename test/cadet_web/controllers/{ => submission}/programming_submission_controller_test.exs (57%) diff --git a/lib/cadet_web/controllers/mcq_submission_controller.ex b/lib/cadet_web/controllers/submission/mcq_submission_controller.ex similarity index 94% rename from lib/cadet_web/controllers/mcq_submission_controller.ex rename to lib/cadet_web/controllers/submission/mcq_submission_controller.ex index 69142626d..137ddba2e 100644 --- a/lib/cadet_web/controllers/mcq_submission_controller.ex +++ b/lib/cadet_web/controllers/submission/mcq_submission_controller.ex @@ -1,4 +1,4 @@ -defmodule CadetWeb.MCQSubmissionController do +defmodule CadetWeb.Submission.MCQSubmissionController do use CadetWeb, :controller use PhoenixSwagger diff --git a/lib/cadet_web/controllers/programming_submission_controller.ex b/lib/cadet_web/controllers/submission/programming_submission_controller.ex similarity index 93% rename from lib/cadet_web/controllers/programming_submission_controller.ex rename to lib/cadet_web/controllers/submission/programming_submission_controller.ex index 170a6615b..8a8e88a06 100644 --- a/lib/cadet_web/controllers/programming_submission_controller.ex +++ b/lib/cadet_web/controllers/submission/programming_submission_controller.ex @@ -1,4 +1,4 @@ -defmodule CadetWeb.ProgrammingSubmissionController do +defmodule CadetWeb.Submission.ProgrammingSubmissionController do use CadetWeb, :controller use PhoenixSwagger diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index 83e307c1f..0eeebdc60 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -29,9 +29,11 @@ defmodule CadetWeb.Router do scope "/", CadetWeb do pipe_through([:api, :auth, :ensure_auth]) - post("/submission/programming", ProgrammingSubmissionController, :submit) + scope "/submission", Submission do + post("/submission/programming", ProgrammingSubmissionController, :submit) + post("/submission/mcq", MCQSubmissionController, :submit) + end - post("/submission/mcq", MCQSubmissionController, :submit) end # Other scopes may use custom stacks. diff --git a/test/cadet_web/controllers/mcq_submission_controller_test.exs b/test/cadet_web/controllers/submission/mcq_submission_controller_test.exs similarity index 58% rename from test/cadet_web/controllers/mcq_submission_controller_test.exs rename to test/cadet_web/controllers/submission/mcq_submission_controller_test.exs index dc8a9e6f5..d92540c3d 100644 --- a/test/cadet_web/controllers/mcq_submission_controller_test.exs +++ b/test/cadet_web/controllers/submission/mcq_submission_controller_test.exs @@ -1,7 +1,7 @@ -defmodule CadetWeb.MCQSubmissionControllerTest do +defmodule CadetWeb.Submission.MCQSubmissionControllerTest do use CadetWeb.ConnCase - alias CadetWeb.MCQSubmissionController + alias CadetWeb.Submission.MCQSubmissionController test "swagger" do MCQSubmissionController.swagger_definitions() diff --git a/test/cadet_web/controllers/programming_submission_controller_test.exs b/test/cadet_web/controllers/submission/programming_submission_controller_test.exs similarity index 57% rename from test/cadet_web/controllers/programming_submission_controller_test.exs rename to test/cadet_web/controllers/submission/programming_submission_controller_test.exs index 84ce00907..929b160b5 100644 --- a/test/cadet_web/controllers/programming_submission_controller_test.exs +++ b/test/cadet_web/controllers/submission/programming_submission_controller_test.exs @@ -1,7 +1,7 @@ -defmodule CadetWeb.ProgrammingSubmissionControllerTest do +defmodule CadetWeb.Submission.ProgrammingSubmissionControllerTest do use CadetWeb.ConnCase - alias CadetWeb.ProgrammingSubmissionController + alias CadetWeb.Submission.ProgrammingSubmissionController test "swagger" do ProgrammingSubmissionController.swagger_definitions() From 3ba228ad01db42a9eb6d5bc280c05e5518468e54 Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Sat, 9 Jun 2018 22:04:00 +0800 Subject: [PATCH 04/22] Add missions controller index API Spec --- .../controllers/missions_controller.ex | 106 ++++++++++++++++++ .../submission/mcq_submission_controller.ex | 2 - lib/cadet_web/router.ex | 1 + .../controllers/missions_controller_test.exs | 10 ++ 4 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 lib/cadet_web/controllers/missions_controller.ex create mode 100644 test/cadet_web/controllers/missions_controller_test.exs diff --git a/lib/cadet_web/controllers/missions_controller.ex b/lib/cadet_web/controllers/missions_controller.ex new file mode 100644 index 000000000..0d87e88e1 --- /dev/null +++ b/lib/cadet_web/controllers/missions_controller.ex @@ -0,0 +1,106 @@ +defmodule CadetWeb.MissionsController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :index do + get("/missions") + + summary("Get a list of all missions") + + security([%{JWT: []}]) + + produces("application/json") + + response(200, "OK", Schema.ref(:MissionsList)) + response(401, "Unauthorised") + end + + def swagger_definitions do + %{ + MissionsList: + swagger_schema do + description("A list of all missions") + type(:array) + items(Schema.ref(:Mission)) + end, + Mission: + swagger_schema do + properties do + id(:integer, "The mission id", required: true) + title(:string, "The title of the mission", required: true) + summary_long(:string, "Long summary", required: true) + summary_short(:string, "Short summary", required: true) + close_at(:string, "The closing date", format: "date-time", required: true) + + max_xp( + :integer, + "The maximum amount of XP to be earned from this mission", + required: true + ) + + cover_picture(:string, "The URL to the cover picture", required: true) + mission_pdf(:string, "The URL to the mission pdf") + + question( + Schema.new do + type(:array) + items(Schema.ref(:ProgrammingQuestion)) + end + ) + end + end, + ProgrammingQuestion: + swagger_schema do + properties do + id(:integer, "The question id", required: true) + library(Schema.ref(:Library), "The library used for this question", required: true) + content(:string, "The question itself", required: true) + solution_template(:string) + end + end, + Library: + swagger_schema do + properties do + version(:integer) + + globals( + Schema.new do + type(:array) + + items( + Schema.new do + type(:string) + end + ) + end + ) + + externals( + Schema.new do + type(:array) + + items( + Schema.new do + type(:string) + end + ) + end + ) + + files( + Schema.new do + type(:array) + + items( + Schema.new do + type(:string) + end + ) + end + ) + end + end + } + end +end diff --git a/lib/cadet_web/controllers/submission/mcq_submission_controller.ex b/lib/cadet_web/controllers/submission/mcq_submission_controller.ex index 137ddba2e..d1b9d1d55 100644 --- a/lib/cadet_web/controllers/submission/mcq_submission_controller.ex +++ b/lib/cadet_web/controllers/submission/mcq_submission_controller.ex @@ -34,12 +34,10 @@ defmodule CadetWeb.Submission.MCQSubmissionController do end, MCQCorrectness: swagger_schema do - properties do correct(:boolean, "Whether the answer submitted was correct") end end } end - end diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index 0eeebdc60..ab0ebbea6 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -34,6 +34,7 @@ defmodule CadetWeb.Router do post("/submission/mcq", MCQSubmissionController, :submit) end + get("/missions", MissionsController, :index) end # Other scopes may use custom stacks. diff --git a/test/cadet_web/controllers/missions_controller_test.exs b/test/cadet_web/controllers/missions_controller_test.exs new file mode 100644 index 000000000..333684627 --- /dev/null +++ b/test/cadet_web/controllers/missions_controller_test.exs @@ -0,0 +1,10 @@ +defmodule CadetWeb.MissionsControllerTest do + use CadetWeb.ConnCase + + alias CadetWeb.MissionsController + + test "swagger" do + MissionsController.swagger_definitions() + MissionsController.swagger_path_index(nil) + end +end From 7c7cb2e9c6c7d9fc4111df317c2f6fe73e9d7866 Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Sun, 10 Jun 2018 14:51:58 +0800 Subject: [PATCH 05/22] Rename submission to answer and add :show method --- .../answer/mcq_answer_controller.ex | 61 ++++++++++++++++++ .../answer/programming_answer_controller.ex | 63 +++++++++++++++++++ .../submission/mcq_submission_controller.ex | 43 ------------- .../programming_submission_controller.ex | 44 ------------- lib/cadet_web/router.ex | 8 ++- .../answer/mcq_answer_controller_test.exs | 11 ++++ .../programming_answer_controller_test.exs | 11 ++++ .../mcq_submission_controller_test.exs | 10 --- ...programming_submission_controller_test.exs | 10 --- 9 files changed, 151 insertions(+), 110 deletions(-) create mode 100644 lib/cadet_web/controllers/answer/mcq_answer_controller.ex create mode 100644 lib/cadet_web/controllers/answer/programming_answer_controller.ex delete mode 100644 lib/cadet_web/controllers/submission/mcq_submission_controller.ex delete mode 100644 lib/cadet_web/controllers/submission/programming_submission_controller.ex create mode 100644 test/cadet_web/controllers/answer/mcq_answer_controller_test.exs create mode 100644 test/cadet_web/controllers/answer/programming_answer_controller_test.exs delete mode 100644 test/cadet_web/controllers/submission/mcq_submission_controller_test.exs delete mode 100644 test/cadet_web/controllers/submission/programming_submission_controller_test.exs diff --git a/lib/cadet_web/controllers/answer/mcq_answer_controller.ex b/lib/cadet_web/controllers/answer/mcq_answer_controller.ex new file mode 100644 index 000000000..05c9dcaf6 --- /dev/null +++ b/lib/cadet_web/controllers/answer/mcq_answer_controller.ex @@ -0,0 +1,61 @@ +defmodule CadetWeb.Answer.MCQAnswerController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :show do + get("/answer/mcq/{questionId}") + + summary("Obtain answer of a particular MCQ") + + security([%{JWT: []}]) + + produces("application/json") + + parameters do + questionId(:path, :integer, "question id", required: true) + end + + response(200, "OK", Schema.ref(:MCQAnswer)) + response(400, "Missing parameter(s) or wrong answer type or non-existent answer for given questionId") + response(401, "Unauthorised") + end + + swagger_path :submit do + post("/answer/mcq") + + summary("Create/update answer of a particular MCQ question.") + + security([%{JWT: []}]) + + consumes("application/json") + produces("application/json") + + parameters do + answer(:body, Schema.ref(:MCQAnswer), "answer", required: true) + end + + response(200, "OK", Schema.ref(:MCQCorrectness)) + response(400, "Missing parameter(s) or wrong answer type or invalid questionId") + response(401, "Unauthorised") + end + + def swagger_definitions do + %{ + MCQAnswer: + swagger_schema do + properties do + questionId(:integer, "The question id", required: true) + + answer(:integer, "The index of the MCQ choice that is the answer", required: true) + end + end, + MCQCorrectness: + swagger_schema do + properties do + correct(:boolean, "Whether the answer submitted was correct") + end + end + } + end +end diff --git a/lib/cadet_web/controllers/answer/programming_answer_controller.ex b/lib/cadet_web/controllers/answer/programming_answer_controller.ex new file mode 100644 index 000000000..c58ae6e1f --- /dev/null +++ b/lib/cadet_web/controllers/answer/programming_answer_controller.ex @@ -0,0 +1,63 @@ +defmodule CadetWeb.Answer.ProgrammingAnswerController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :show do + get("/answer/programming/{questionId}") + + summary("Obtain answer of a particular programming question") + + security([%{JWT: []}]) + + produces("application/json") + + parameters do + questionId(:path, :integer, "question id", required: true) + end + + response(200, "OK", Schema.ref(:ProgrammingAnswer)) + response(400, "Missing parameter(s) or wrong answer type or non-existent answer for given questionId") + response(401, "Unauthorised") + end + + + swagger_path :submit do + post("/answer/programming") + + summary("Create/update answer of a particular programming question.") + + security([%{JWT: []}]) + + consumes("application/json") + + parameters do + answer(:body, Schema.ref(:ProgrammingAnswer), "answer", required: true) + end + + response(200, "OK") + response(400, "Missing parameter(s) or wrong answer type") + response(401, "Unauthorised") + end + + def swagger_definitions do + %{ + ProgrammingAnswer: + swagger_schema do + properties do + questionId(:integer, "The question id", required: true) + + submitted(:boolean, "Whether this is the final answer", default: false) + + answer( + Schema.new do + properties do + code(:string, "Code submitted", required: true) + end + end + ) + end + end + } + end +end diff --git a/lib/cadet_web/controllers/submission/mcq_submission_controller.ex b/lib/cadet_web/controllers/submission/mcq_submission_controller.ex deleted file mode 100644 index d1b9d1d55..000000000 --- a/lib/cadet_web/controllers/submission/mcq_submission_controller.ex +++ /dev/null @@ -1,43 +0,0 @@ -defmodule CadetWeb.Submission.MCQSubmissionController do - use CadetWeb, :controller - - use PhoenixSwagger - - swagger_path :submit do - post("/submission/mcq") - - summary("Creates a new submission of a particular MCQ question.") - - security([%{JWT: []}]) - - consumes("application/json") - produces("application/json") - - parameters do - submission(:body, Schema.ref(:MCQSubmission), "submission", required: true) - end - - response(200, "OK", Schema.ref(:MCQCorrectness)) - response(400, "Missing parameter(s) or wrong submission type") - response(401, "Unauthorised") - end - - def swagger_definitions do - %{ - MCQSubmission: - swagger_schema do - properties do - questionId(:integer, "The question id", required: true) - - answer(:integer, "The index of the MCQ choice that is the answer", required: true) - end - end, - MCQCorrectness: - swagger_schema do - properties do - correct(:boolean, "Whether the answer submitted was correct") - end - end - } - end -end diff --git a/lib/cadet_web/controllers/submission/programming_submission_controller.ex b/lib/cadet_web/controllers/submission/programming_submission_controller.ex deleted file mode 100644 index 8a8e88a06..000000000 --- a/lib/cadet_web/controllers/submission/programming_submission_controller.ex +++ /dev/null @@ -1,44 +0,0 @@ -defmodule CadetWeb.Submission.ProgrammingSubmissionController do - use CadetWeb, :controller - - use PhoenixSwagger - - swagger_path :submit do - post("/submission/programming") - - summary("Create/update a submission of a particular programming question.") - - security([%{JWT: []}]) - - consumes("application/json") - - parameters do - submission(:body, Schema.ref(:ProgrammingSubmission), "submission", required: true) - end - - response(200, "OK") - response(400, "Missing parameter(s) or wrong submission type") - response(401, "Unauthorised") - end - - def swagger_definitions do - %{ - ProgrammingSubmission: - swagger_schema do - properties do - questionId(:integer, "The question id", required: true) - - submitted(:boolean, "Whether this is the final submission", default: false) - - answer( - Schema.new do - properties do - code(:string, "Code submitted", required: true) - end - end - ) - end - end - } - end -end diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index ab0ebbea6..fe004121d 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -29,9 +29,11 @@ defmodule CadetWeb.Router do scope "/", CadetWeb do pipe_through([:api, :auth, :ensure_auth]) - scope "/submission", Submission do - post("/submission/programming", ProgrammingSubmissionController, :submit) - post("/submission/mcq", MCQSubmissionController, :submit) + scope "/answer", Answer do + get("/programming/:id", ProgrammingAnswerController, :show) + post("/programming", ProgrammingAnswerController, :submit) + get("/mcq/:id", MCQAnswerController, :show) + post("/mcq", MCQAnswerController, :submit) end get("/missions", MissionsController, :index) diff --git a/test/cadet_web/controllers/answer/mcq_answer_controller_test.exs b/test/cadet_web/controllers/answer/mcq_answer_controller_test.exs new file mode 100644 index 000000000..511980189 --- /dev/null +++ b/test/cadet_web/controllers/answer/mcq_answer_controller_test.exs @@ -0,0 +1,11 @@ +defmodule CadetWeb.Answer.MCQAnswerControllerTest do + use CadetWeb.ConnCase + + alias CadetWeb.Answer.MCQAnswerController + + test "swagger" do + MCQAnswerController.swagger_definitions() + MCQAnswerController.swagger_path_submit(nil) + MCQAnswerController.swagger_path_show(nil) + end +end diff --git a/test/cadet_web/controllers/answer/programming_answer_controller_test.exs b/test/cadet_web/controllers/answer/programming_answer_controller_test.exs new file mode 100644 index 000000000..72edbb96a --- /dev/null +++ b/test/cadet_web/controllers/answer/programming_answer_controller_test.exs @@ -0,0 +1,11 @@ +defmodule CadetWeb.Answer.ProgrammingAnswerControllerTest do + use CadetWeb.ConnCase + + alias CadetWeb.Answer.ProgrammingAnswerController + + test "swagger" do + ProgrammingAnswerController.swagger_definitions() + ProgrammingAnswerController.swagger_path_submit(nil) + ProgrammingAnswerController.swagger_path_show(nil) + end +end diff --git a/test/cadet_web/controllers/submission/mcq_submission_controller_test.exs b/test/cadet_web/controllers/submission/mcq_submission_controller_test.exs deleted file mode 100644 index d92540c3d..000000000 --- a/test/cadet_web/controllers/submission/mcq_submission_controller_test.exs +++ /dev/null @@ -1,10 +0,0 @@ -defmodule CadetWeb.Submission.MCQSubmissionControllerTest do - use CadetWeb.ConnCase - - alias CadetWeb.Submission.MCQSubmissionController - - test "swagger" do - MCQSubmissionController.swagger_definitions() - MCQSubmissionController.swagger_path_submit(nil) - end -end diff --git a/test/cadet_web/controllers/submission/programming_submission_controller_test.exs b/test/cadet_web/controllers/submission/programming_submission_controller_test.exs deleted file mode 100644 index 929b160b5..000000000 --- a/test/cadet_web/controllers/submission/programming_submission_controller_test.exs +++ /dev/null @@ -1,10 +0,0 @@ -defmodule CadetWeb.Submission.ProgrammingSubmissionControllerTest do - use CadetWeb.ConnCase - - alias CadetWeb.Submission.ProgrammingSubmissionController - - test "swagger" do - ProgrammingSubmissionController.swagger_definitions() - ProgrammingSubmissionController.swagger_path_submit(nil) - end -end From 3e3434e35af499ec16f931a2cbf50ba8d9305aec Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Mon, 11 Jun 2018 22:19:24 +0800 Subject: [PATCH 06/22] Add more missions controller spec --- .../controllers/missions_controller.ex | 76 +++++++++++++++++-- lib/cadet_web/router.ex | 2 + .../controllers/missions_controller_test.exs | 2 + 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/lib/cadet_web/controllers/missions_controller.ex b/lib/cadet_web/controllers/missions_controller.ex index 0d87e88e1..78f0f10d0 100644 --- a/lib/cadet_web/controllers/missions_controller.ex +++ b/lib/cadet_web/controllers/missions_controller.ex @@ -13,6 +13,39 @@ defmodule CadetWeb.MissionsController do produces("application/json") response(200, "OK", Schema.ref(:MissionsList)) + response(400, "Missing parameter(s)") + response(401, "Unauthorised") + end + + swagger_path :open do + get("/missions/open") + + summary("Get a list of open missions") + + security([%{JWT: []}]) + + produces("application/json") + + response(200, "OK", Schema.ref(:MissionsList)) + response(400, "Missing parameter(s)") + response(401, "Unauthorised") + end + + swagger_path :questions do + get("/missions/{missionId}/questions") + + summary("Get questions contained inside a mission. Response is either `mcq` or `programming`") + + security([%{JWT: []}]) + + produces("application/json") + + parameters do + missionId(:path, :integer, "mission id", required: true) + end + + response(200, "OK", Schema.ref(:Questions)) + response(400, "Missing parameter(s) or invalid missionId") response(401, "Unauthorised") end @@ -27,10 +60,13 @@ defmodule CadetWeb.MissionsController do Mission: swagger_schema do properties do + order(:integer, "The order of showing the missions", required: true) id(:integer, "The mission id", required: true) title(:string, "The title of the mission", required: true) + category(:string, "Either mission/sidequest/path/contest", required: true) summary_long(:string, "Long summary", required: true) summary_short(:string, "Short summary", required: true) + open_at(:string, "The opening date", format: "date-time", required: true) close_at(:string, "The closing date", format: "date-time", required: true) max_xp( @@ -41,13 +77,36 @@ defmodule CadetWeb.MissionsController do cover_picture(:string, "The URL to the cover picture", required: true) mission_pdf(:string, "The URL to the mission pdf") - - question( - Schema.new do - type(:array) - items(Schema.ref(:ProgrammingQuestion)) - end - ) + end + end, + Questions: + swagger_schema do + properties do + mcq(Schema.new do + type(:array) + items(Schema.ref(:MCQQuestion)) + end) + programming(Schema.new do + type(:array) + items(Schema.ref(:ProgrammingQuestion)) + end) + end + end, + MCQQuestion: + swagger_schema do + properties do + content(:string, "the question content", required: true) + choices(Schema.new do + type(:array) + items(Schema.ref(:MCQChoice)) + end) + end + end, + MCQChoice: + swagger_schema do + properties do + content(:string, "the choice content", required: true) + hint(:string, "the hint", required: true) end end, ProgrammingQuestion: @@ -62,7 +121,8 @@ defmodule CadetWeb.MissionsController do Library: swagger_schema do properties do - version(:integer) + chapter(:integer) + sourceChap(:integer) globals( Schema.new do diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index fe004121d..bb807835e 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -37,6 +37,8 @@ defmodule CadetWeb.Router do end get("/missions", MissionsController, :index) + get("/missions/open", MissionsController, :open) + get("/missions/:id/questions", MissionsController, :questions) end # Other scopes may use custom stacks. diff --git a/test/cadet_web/controllers/missions_controller_test.exs b/test/cadet_web/controllers/missions_controller_test.exs index 333684627..a679defe8 100644 --- a/test/cadet_web/controllers/missions_controller_test.exs +++ b/test/cadet_web/controllers/missions_controller_test.exs @@ -6,5 +6,7 @@ defmodule CadetWeb.MissionsControllerTest do test "swagger" do MissionsController.swagger_definitions() MissionsController.swagger_path_index(nil) + MissionsController.swagger_path_open(nil) + MissionsController.swagger_path_questions(nil) end end From 90c741df003f30977375626e06c60ba1756e6590 Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Mon, 11 Jun 2018 22:31:58 +0800 Subject: [PATCH 07/22] Added changes so far --- .../controllers/grading_controller.ex | 23 +++++++++++++++++++ .../controllers/missions_controller.ex | 2 -- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 lib/cadet_web/controllers/grading_controller.ex diff --git a/lib/cadet_web/controllers/grading_controller.ex b/lib/cadet_web/controllers/grading_controller.ex new file mode 100644 index 000000000..605a7c6a8 --- /dev/null +++ b/lib/cadet_web/controllers/grading_controller.ex @@ -0,0 +1,23 @@ +defmodule CadetWeb.GradingController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :index do + get("/grading") + + summary("Get a list of all submissions with current user as the grader") + + security([%{JWT: []}]) + + produces("application/json") + + response(200, "OK", Schema.ref(:Submissions)) + response(401, "Unauthorised") + end + + def swagger_definitions do + + end + +end diff --git a/lib/cadet_web/controllers/missions_controller.ex b/lib/cadet_web/controllers/missions_controller.ex index 78f0f10d0..4bcbe3fd6 100644 --- a/lib/cadet_web/controllers/missions_controller.ex +++ b/lib/cadet_web/controllers/missions_controller.ex @@ -13,7 +13,6 @@ defmodule CadetWeb.MissionsController do produces("application/json") response(200, "OK", Schema.ref(:MissionsList)) - response(400, "Missing parameter(s)") response(401, "Unauthorised") end @@ -27,7 +26,6 @@ defmodule CadetWeb.MissionsController do produces("application/json") response(200, "OK", Schema.ref(:MissionsList)) - response(400, "Missing parameter(s)") response(401, "Unauthorised") end From a0bd9b5e37c3bb4ed9840e73142a2e3c8d48fe4a Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Tue, 12 Jun 2018 23:56:32 +0800 Subject: [PATCH 08/22] Add :show to GradingController and various fixups --- .../answer/mcq_answer_controller.ex | 11 +++- .../answer/programming_answer_controller.ex | 14 +++-- .../controllers/grading_controller.ex | 56 ++++++++++++++++++- .../controllers/missions_controller.ex | 53 +++++++++++++----- lib/cadet_web/router.ex | 5 +- .../controllers/grading_controller_test.exs | 11 ++++ 6 files changed, 127 insertions(+), 23 deletions(-) create mode 100644 test/cadet_web/controllers/grading_controller_test.exs diff --git a/lib/cadet_web/controllers/answer/mcq_answer_controller.ex b/lib/cadet_web/controllers/answer/mcq_answer_controller.ex index 05c9dcaf6..c03db59f5 100644 --- a/lib/cadet_web/controllers/answer/mcq_answer_controller.ex +++ b/lib/cadet_web/controllers/answer/mcq_answer_controller.ex @@ -6,7 +6,7 @@ defmodule CadetWeb.Answer.MCQAnswerController do swagger_path :show do get("/answer/mcq/{questionId}") - summary("Obtain answer of a particular MCQ") + summary("Obtain answer of a particular MCQ previously submitted by current user") security([%{JWT: []}]) @@ -17,14 +17,19 @@ defmodule CadetWeb.Answer.MCQAnswerController do end response(200, "OK", Schema.ref(:MCQAnswer)) - response(400, "Missing parameter(s) or wrong answer type or non-existent answer for given questionId") + + response( + 400, + "Missing parameter(s) or wrong answer type or non-existent answer for given questionId" + ) + response(401, "Unauthorised") end swagger_path :submit do post("/answer/mcq") - summary("Create/update answer of a particular MCQ question.") + summary("Create/update answer of a particular MCQ question (under the current user).") security([%{JWT: []}]) diff --git a/lib/cadet_web/controllers/answer/programming_answer_controller.ex b/lib/cadet_web/controllers/answer/programming_answer_controller.ex index c58ae6e1f..7e991be54 100644 --- a/lib/cadet_web/controllers/answer/programming_answer_controller.ex +++ b/lib/cadet_web/controllers/answer/programming_answer_controller.ex @@ -6,7 +6,9 @@ defmodule CadetWeb.Answer.ProgrammingAnswerController do swagger_path :show do get("/answer/programming/{questionId}") - summary("Obtain answer of a particular programming question") + summary( + "Obtain answer of a particular programming question submitted previously by current user" + ) security([%{JWT: []}]) @@ -17,15 +19,19 @@ defmodule CadetWeb.Answer.ProgrammingAnswerController do end response(200, "OK", Schema.ref(:ProgrammingAnswer)) - response(400, "Missing parameter(s) or wrong answer type or non-existent answer for given questionId") + + response( + 400, + "Missing parameter(s) or wrong answer type or non-existent answer for given questionId" + ) + response(401, "Unauthorised") end - swagger_path :submit do post("/answer/programming") - summary("Create/update answer of a particular programming question.") + summary("Create/update answer of a particular programming question (under the current user).") security([%{JWT: []}]) diff --git a/lib/cadet_web/controllers/grading_controller.ex b/lib/cadet_web/controllers/grading_controller.ex index 605a7c6a8..6dd69e83c 100644 --- a/lib/cadet_web/controllers/grading_controller.ex +++ b/lib/cadet_web/controllers/grading_controller.ex @@ -6,7 +6,7 @@ defmodule CadetWeb.GradingController do swagger_path :index do get("/grading") - summary("Get a list of all submissions with current user as the grader") + summary("Get a list of all submissions with current user as the grader.") security([%{JWT: []}]) @@ -16,8 +16,60 @@ defmodule CadetWeb.GradingController do response(401, "Unauthorised") end - def swagger_definitions do + swagger_path :show do + get("/grading/{submissionId}/{questionId}") + + summary("Get information about a specific question in a specific submission to be graded.") + + security([%{JWT: []}]) + + produces("application/json") + + parameters do + submissionId(:path, :integer, "submission id", required: true) + questionId(:path, :integer, "question id", required: true) + end + response(200, "OK", Schema.ref(:GradingInfo)) end + def swagger_definitions do + %{ + Submissions: + swagger_schema do + type(:array) + items(Schema.ref(:Submission)) + end, + Submission: + swagger_schema do + properties do + submissionId(:integer, "submission id", required: true) + missionId(:integer, "mission id", required: true) + studentId(:integer, "student id", required: true) + + questions( + Schema.new do + type(:array) + items(Schema.ref(:Questions)) + end + ) + end + end, + GradingInfo: + swagger_schema do + properties do + answer(Schema.ref(:Answer)) + marks(:integer, "Marks given to this answer", required: true) + weight(:integer, "the max xp that can be given to this question", required: true) + comment(:string, "existing comments if present", required: true) + end + end, + Answer: + swagger_schema do + properties do + code(:string, "Code provided by student", required: true) + end + end + } + end end diff --git a/lib/cadet_web/controllers/missions_controller.ex b/lib/cadet_web/controllers/missions_controller.ex index 4bcbe3fd6..818335d85 100644 --- a/lib/cadet_web/controllers/missions_controller.ex +++ b/lib/cadet_web/controllers/missions_controller.ex @@ -29,6 +29,24 @@ defmodule CadetWeb.MissionsController do response(401, "Unauthorised") end + swagger_path :show do + get("/missions/{missionId}") + + summary("Get information about one particular mission.") + + security([%{JWT: []}]) + + produces("application/json") + + parameters do + missionId(:path, :integer, "mission id", required: true) + end + + response(200, "OK", Schema.ref(:Mission)) + response(400, "Missing parameter(s) or invalid missionId") + response(401, "Unauthorised") + end + swagger_path :questions do get("/missions/{missionId}/questions") @@ -80,24 +98,33 @@ defmodule CadetWeb.MissionsController do Questions: swagger_schema do properties do - mcq(Schema.new do - type(:array) - items(Schema.ref(:MCQQuestion)) - end) - programming(Schema.new do - type(:array) - items(Schema.ref(:ProgrammingQuestion)) - end) + mcq( + Schema.new do + type(:array) + items(Schema.ref(:MCQQuestion)) + end + ) + + programming( + Schema.new do + type(:array) + items(Schema.ref(:ProgrammingQuestion)) + end + ) end end, MCQQuestion: swagger_schema do properties do + questionId(:integer, "question id", required: true) content(:string, "the question content", required: true) - choices(Schema.new do - type(:array) - items(Schema.ref(:MCQChoice)) - end) + + choices( + Schema.new do + type(:array) + items(Schema.ref(:MCQChoice)) + end + ) end end, MCQChoice: @@ -110,7 +137,7 @@ defmodule CadetWeb.MissionsController do ProgrammingQuestion: swagger_schema do properties do - id(:integer, "The question id", required: true) + questionId(:integer, "The question id", required: true) library(Schema.ref(:Library), "The library used for this question", required: true) content(:string, "The question itself", required: true) solution_template(:string) diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index bb807835e..48b168114 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -36,9 +36,12 @@ defmodule CadetWeb.Router do post("/mcq", MCQAnswerController, :submit) end - get("/missions", MissionsController, :index) + resources("/missions", MissionsController, only: [:index, :show]) get("/missions/open", MissionsController, :open) get("/missions/:id/questions", MissionsController, :questions) + + get("/grading", GradingController, :index) + get("/grading/:submissionid/:questionid", GradingController, :show) end # Other scopes may use custom stacks. diff --git a/test/cadet_web/controllers/grading_controller_test.exs b/test/cadet_web/controllers/grading_controller_test.exs new file mode 100644 index 000000000..4340ebb1c --- /dev/null +++ b/test/cadet_web/controllers/grading_controller_test.exs @@ -0,0 +1,11 @@ +defmodule CadetWeb.GradingControllerTest do + use CadetWeb.ConnCase + + alias CadetWeb.GradingController + + test "swagger" do + GradingController.swagger_definitions() + GradingController.swagger_path_index(nil) + GradingController.swagger_path_show(nil) + end +end From 570573d0479b827eddf6800ec118af7b1e57e8e5 Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Tue, 12 Jun 2018 23:58:42 +0800 Subject: [PATCH 09/22] Fix Library according to #43 --- lib/cadet_web/controllers/missions_controller.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cadet_web/controllers/missions_controller.ex b/lib/cadet_web/controllers/missions_controller.ex index 818335d85..fab55f26f 100644 --- a/lib/cadet_web/controllers/missions_controller.ex +++ b/lib/cadet_web/controllers/missions_controller.ex @@ -147,7 +147,6 @@ defmodule CadetWeb.MissionsController do swagger_schema do properties do chapter(:integer) - sourceChap(:integer) globals( Schema.new do From 37dd4323f52da1c8f66a507ce0b1b40d35e72581 Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Sat, 16 Jun 2018 17:52:20 +0800 Subject: [PATCH 10/22] Complete GradingController api spec --- .../controllers/grading_controller.ex | 56 +++++++++++++++++++ lib/cadet_web/router.ex | 2 + 2 files changed, 58 insertions(+) diff --git a/lib/cadet_web/controllers/grading_controller.ex b/lib/cadet_web/controllers/grading_controller.ex index 6dd69e83c..7518be777 100644 --- a/lib/cadet_web/controllers/grading_controller.ex +++ b/lib/cadet_web/controllers/grading_controller.ex @@ -31,6 +31,50 @@ defmodule CadetWeb.GradingController do end response(200, "OK", Schema.ref(:GradingInfo)) + response(400, "Invalid or missing parameter(s) or submission and/or question not found") + response(401, "Unauthorised") + end + + swagger_path :update_comment do + post("/grading/{submissionId}/{questionId}") + + summary("Update comment given to the answer of a particular qurrstion in a submission") + + security([%{JWT: []}]) + + consumes("application/json") + produces("application/json") + + parameters do + submissionId(:path, :integer, "submission id", required: true) + questionId(:path, :integer, "question id", required: true) + comment(:body, Schema.ref(:Comment), "comment given for a question", required: true) + end + + response(200, "OK") + response(400, "Invalid or missing parameter(s) or submission and/or question not found") + response(401, "Unauthorised") + end + + swagger_path :update_mark do + post("/grading/{submissionId}") + + summary("Update marks of a submission") + + security([%{JWT: []}]) + + consumes("application/json") + produces("application/json") + + parameters do + submissionId(:path, :integer, "submission id", required: true) + questionId(:path, :integer, "question id", required: true) + mark(:body, Schema.ref(:Mark), "mark given for a question", required: true) + end + + response(200, "OK") + response(400, "Invalid or missing parameter(s) or submission and/or question not found") + response(401, "Unauthorised") end def swagger_definitions do @@ -69,6 +113,18 @@ defmodule CadetWeb.GradingController do properties do code(:string, "Code provided by student", required: true) end + end, + Comment: + swagger_schema do + properties do + comment(:string, "comment given", required: true) + end + end, + Mark: + swagger_schema do + properties do + exp(:integer, "xp given", required: true) + end end } end diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index 48b168114..61dfe286d 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -42,6 +42,8 @@ defmodule CadetWeb.Router do get("/grading", GradingController, :index) get("/grading/:submissionid/:questionid", GradingController, :show) + post("/grading/:submissionid/:questionid", GradingController, :update_comment) + post("/grading/:submissionid", GradingController, :update_mark) end # Other scopes may use custom stacks. From 95b7851cabaa8115ef36360b0627d17f5568612e Mon Sep 17 00:00:00 2001 From: Julius Putra Tanu Setiaji Date: Mon, 18 Jun 2018 09:03:04 +0800 Subject: [PATCH 11/22] Unify marks and comments --- .../controllers/grading_controller.ex | 45 +++++-------------- lib/cadet_web/router.ex | 3 +- .../controllers/grading_controller_test.exs | 1 + 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/lib/cadet_web/controllers/grading_controller.ex b/lib/cadet_web/controllers/grading_controller.ex index 7518be777..6cc81e3eb 100644 --- a/lib/cadet_web/controllers/grading_controller.ex +++ b/lib/cadet_web/controllers/grading_controller.ex @@ -35,10 +35,12 @@ defmodule CadetWeb.GradingController do response(401, "Unauthorised") end - swagger_path :update_comment do + swagger_path :update do post("/grading/{submissionId}/{questionId}") - summary("Update comment given to the answer of a particular qurrstion in a submission") + summary( + "Update comment and/or marks given to the answer of a particular qurrstion in a submission" + ) security([%{JWT: []}]) @@ -48,28 +50,7 @@ defmodule CadetWeb.GradingController do parameters do submissionId(:path, :integer, "submission id", required: true) questionId(:path, :integer, "question id", required: true) - comment(:body, Schema.ref(:Comment), "comment given for a question", required: true) - end - - response(200, "OK") - response(400, "Invalid or missing parameter(s) or submission and/or question not found") - response(401, "Unauthorised") - end - - swagger_path :update_mark do - post("/grading/{submissionId}") - - summary("Update marks of a submission") - - security([%{JWT: []}]) - - consumes("application/json") - produces("application/json") - - parameters do - submissionId(:path, :integer, "submission id", required: true) - questionId(:path, :integer, "question id", required: true) - mark(:body, Schema.ref(:Mark), "mark given for a question", required: true) + grading(:body, Schema.ref(:Grade), "comment given for a question", required: true) end response(200, "OK") @@ -103,9 +84,8 @@ defmodule CadetWeb.GradingController do swagger_schema do properties do answer(Schema.ref(:Answer)) - marks(:integer, "Marks given to this answer", required: true) - weight(:integer, "the max xp that can be given to this question", required: true) - comment(:string, "existing comments if present", required: true) + grade(Schema.ref(:Grade)) + max_xp(:integer, "the max xp that can be given to this question", required: true) end end, Answer: @@ -114,16 +94,11 @@ defmodule CadetWeb.GradingController do code(:string, "Code provided by student", required: true) end end, - Comment: - swagger_schema do - properties do - comment(:string, "comment given", required: true) - end - end, - Mark: + Grade: swagger_schema do properties do - exp(:integer, "xp given", required: true) + comment(:string, "comment given") + xp(:integer, "xp given") end end } diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index 61dfe286d..13ff2636b 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -42,8 +42,7 @@ defmodule CadetWeb.Router do get("/grading", GradingController, :index) get("/grading/:submissionid/:questionid", GradingController, :show) - post("/grading/:submissionid/:questionid", GradingController, :update_comment) - post("/grading/:submissionid", GradingController, :update_mark) + post("/grading/:submissionid/:questionid", GradingController, :update) end # Other scopes may use custom stacks. diff --git a/test/cadet_web/controllers/grading_controller_test.exs b/test/cadet_web/controllers/grading_controller_test.exs index 4340ebb1c..f588af8ce 100644 --- a/test/cadet_web/controllers/grading_controller_test.exs +++ b/test/cadet_web/controllers/grading_controller_test.exs @@ -7,5 +7,6 @@ defmodule CadetWeb.GradingControllerTest do GradingController.swagger_definitions() GradingController.swagger_path_index(nil) GradingController.swagger_path_show(nil) + GradingController.swagger_path_update(nil) end end From 1b2150ae162be2d631f56d799e9588062d75b5da Mon Sep 17 00:00:00 2001 From: Shaowei Chen Date: Sun, 24 Jun 2018 00:12:04 +0800 Subject: [PATCH 12/22] Amend assessments controller --- .../controllers/assessments_controller.ex | 156 ++++++++++++++++++ lib/cadet_web/router.ex | 4 +- 2 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 lib/cadet_web/controllers/assessments_controller.ex diff --git a/lib/cadet_web/controllers/assessments_controller.ex b/lib/cadet_web/controllers/assessments_controller.ex new file mode 100644 index 000000000..e5ac1d20b --- /dev/null +++ b/lib/cadet_web/controllers/assessments_controller.ex @@ -0,0 +1,156 @@ +defmodule CadetWeb.AssessmentsController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :index do + get("/assessments") + + summary("Get a list of all assessments") + + security([%{JWT: []}]) + + produces("application/json") + + response(200, "OK", Schema.ref(:AssessmentsList)) + response(401, "Unauthorised") + end + + swagger_path :show do + get("/assessments/{assessmentId}") + + summary("Get information about one particular assessment.") + + security([%{JWT: []}]) + + produces("application/json") + + parameters do + assessmentId(:path, :integer, "assessment id", required: true) + end + + response(200, "OK", Schema.ref(:Assessment)) + response(400, "Missing parameter(s) or invalid assessmentId") + response(401, "Unauthorised") + end + + def swagger_definitions do + %{ + AssessmentsList: + swagger_schema do + description("A list of all assessments") + type(:array) + items(Schema.ref(:Assessment)) + end, + Assessment: + swagger_schema do + properties do + order(:integer, "The order of showing the assessments", required: true) + id(:integer, "The assessment id", required: true) + title(:string, "The title of the assessment", required: true) + type(:string, "Either mission/sidequest/path/contest", required: true) + summary_long(:string, "Long summary", required: true) + summary_short(:string, "Short summary", required: true) + open_at(:string, "The opening date", format: "date-time", required: true) + close_at(:string, "The closing date", format: "date-time", required: true) + + max_xp( + :integer, + "The maximum amount of XP to be earned from this assessment", + required: true + ) + + cover_picture(:string, "The URL to the cover picture", required: true) + mission_pdf(:string, "The URL to the assessment pdf") + + # Questions will only be returned for GET /assessments/{assessmentId} + questions(Schema.ref(:Questions), "The list of questions for this assessment") + end + end, + Questions: + swagger_schema do + description("A list of questions") + type(:array) + items(Schema.ref(:Question)) + end, + Question: + swagger_schema do + properties do + questionId(:integer, "question id", required: true) + questionType(:string, "the question type (mcq/programming)", required: true) + content(:string, "the question content", required: true) + + choices( + Schema.new do + type(:array) + items(Schema.ref(:MCQChoice)) + end, + "mcq choices if question type is mcq" + ) + + answer( + :string_or_integer, + "previous answer for this quesiton (string/int) depending on question type", + required: true + ) + + library( + Schema.ref(:Library), + "The library used for this question (programming questions only)" + ) + + solution_template(:string, "solution template for programming questions") + end + end, + MCQChoice: + swagger_schema do + properties do + content(:string, "the choice content", required: true) + hint(:string, "the hint", required: true) + end + end, + Library: + swagger_schema do + properties do + chapter(:integer) + + globals( + Schema.new do + type(:array) + + items( + Schema.new do + type(:string) + end + ) + end + ) + + externals( + Schema.new do + type(:array) + + items( + Schema.new do + type(:string) + end + ) + end + ) + + files( + Schema.new do + type(:array) + + items( + Schema.new do + type(:string) + end + ) + end + ) + end + end + } + end +end diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index 13ff2636b..2b5521a6f 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -36,9 +36,7 @@ defmodule CadetWeb.Router do post("/mcq", MCQAnswerController, :submit) end - resources("/missions", MissionsController, only: [:index, :show]) - get("/missions/open", MissionsController, :open) - get("/missions/:id/questions", MissionsController, :questions) + resources("/assessments", AssessmentsController, only: [:index, :show]) get("/grading", GradingController, :index) get("/grading/:submissionid/:questionid", GradingController, :show) From 05708fc23799dcecfb73393e8bbf168bb7b72e1c Mon Sep 17 00:00:00 2001 From: Shaowei Chen Date: Sun, 24 Jun 2018 00:18:42 +0800 Subject: [PATCH 13/22] Remove missions controller --- .../controllers/missions_controller.ex | 190 ------------------ 1 file changed, 190 deletions(-) delete mode 100644 lib/cadet_web/controllers/missions_controller.ex diff --git a/lib/cadet_web/controllers/missions_controller.ex b/lib/cadet_web/controllers/missions_controller.ex deleted file mode 100644 index fab55f26f..000000000 --- a/lib/cadet_web/controllers/missions_controller.ex +++ /dev/null @@ -1,190 +0,0 @@ -defmodule CadetWeb.MissionsController do - use CadetWeb, :controller - - use PhoenixSwagger - - swagger_path :index do - get("/missions") - - summary("Get a list of all missions") - - security([%{JWT: []}]) - - produces("application/json") - - response(200, "OK", Schema.ref(:MissionsList)) - response(401, "Unauthorised") - end - - swagger_path :open do - get("/missions/open") - - summary("Get a list of open missions") - - security([%{JWT: []}]) - - produces("application/json") - - response(200, "OK", Schema.ref(:MissionsList)) - response(401, "Unauthorised") - end - - swagger_path :show do - get("/missions/{missionId}") - - summary("Get information about one particular mission.") - - security([%{JWT: []}]) - - produces("application/json") - - parameters do - missionId(:path, :integer, "mission id", required: true) - end - - response(200, "OK", Schema.ref(:Mission)) - response(400, "Missing parameter(s) or invalid missionId") - response(401, "Unauthorised") - end - - swagger_path :questions do - get("/missions/{missionId}/questions") - - summary("Get questions contained inside a mission. Response is either `mcq` or `programming`") - - security([%{JWT: []}]) - - produces("application/json") - - parameters do - missionId(:path, :integer, "mission id", required: true) - end - - response(200, "OK", Schema.ref(:Questions)) - response(400, "Missing parameter(s) or invalid missionId") - response(401, "Unauthorised") - end - - def swagger_definitions do - %{ - MissionsList: - swagger_schema do - description("A list of all missions") - type(:array) - items(Schema.ref(:Mission)) - end, - Mission: - swagger_schema do - properties do - order(:integer, "The order of showing the missions", required: true) - id(:integer, "The mission id", required: true) - title(:string, "The title of the mission", required: true) - category(:string, "Either mission/sidequest/path/contest", required: true) - summary_long(:string, "Long summary", required: true) - summary_short(:string, "Short summary", required: true) - open_at(:string, "The opening date", format: "date-time", required: true) - close_at(:string, "The closing date", format: "date-time", required: true) - - max_xp( - :integer, - "The maximum amount of XP to be earned from this mission", - required: true - ) - - cover_picture(:string, "The URL to the cover picture", required: true) - mission_pdf(:string, "The URL to the mission pdf") - end - end, - Questions: - swagger_schema do - properties do - mcq( - Schema.new do - type(:array) - items(Schema.ref(:MCQQuestion)) - end - ) - - programming( - Schema.new do - type(:array) - items(Schema.ref(:ProgrammingQuestion)) - end - ) - end - end, - MCQQuestion: - swagger_schema do - properties do - questionId(:integer, "question id", required: true) - content(:string, "the question content", required: true) - - choices( - Schema.new do - type(:array) - items(Schema.ref(:MCQChoice)) - end - ) - end - end, - MCQChoice: - swagger_schema do - properties do - content(:string, "the choice content", required: true) - hint(:string, "the hint", required: true) - end - end, - ProgrammingQuestion: - swagger_schema do - properties do - questionId(:integer, "The question id", required: true) - library(Schema.ref(:Library), "The library used for this question", required: true) - content(:string, "The question itself", required: true) - solution_template(:string) - end - end, - Library: - swagger_schema do - properties do - chapter(:integer) - - globals( - Schema.new do - type(:array) - - items( - Schema.new do - type(:string) - end - ) - end - ) - - externals( - Schema.new do - type(:array) - - items( - Schema.new do - type(:string) - end - ) - end - ) - - files( - Schema.new do - type(:array) - - items( - Schema.new do - type(:string) - end - ) - end - ) - end - end - } - end -end From acf75b92f27ee1d9b8ee76bdbf6ee2026a196487 Mon Sep 17 00:00:00 2001 From: Shaowei Chen Date: Sun, 24 Jun 2018 00:24:24 +0800 Subject: [PATCH 14/22] Minor fix --- ...s_controller_test.exs => assessments_controller_test.exs} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename test/cadet_web/controllers/{missions_controller_test.exs => assessments_controller_test.exs} (56%) diff --git a/test/cadet_web/controllers/missions_controller_test.exs b/test/cadet_web/controllers/assessments_controller_test.exs similarity index 56% rename from test/cadet_web/controllers/missions_controller_test.exs rename to test/cadet_web/controllers/assessments_controller_test.exs index a679defe8..b339ca877 100644 --- a/test/cadet_web/controllers/missions_controller_test.exs +++ b/test/cadet_web/controllers/assessments_controller_test.exs @@ -1,4 +1,4 @@ -defmodule CadetWeb.MissionsControllerTest do +defmodule CadetWeb.AssessmentsControllerTest do use CadetWeb.ConnCase alias CadetWeb.MissionsController @@ -6,7 +6,6 @@ defmodule CadetWeb.MissionsControllerTest do test "swagger" do MissionsController.swagger_definitions() MissionsController.swagger_path_index(nil) - MissionsController.swagger_path_open(nil) - MissionsController.swagger_path_questions(nil) + MissionsController.swagger_path_show(nil) end end From a434634fbbc13b58383504b9c881d5bef54826e2 Mon Sep 17 00:00:00 2001 From: Shaowei Chen Date: Sun, 24 Jun 2018 00:25:54 +0800 Subject: [PATCH 15/22] I'm blind --- .../cadet_web/controllers/assessments_controller_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cadet_web/controllers/assessments_controller_test.exs b/test/cadet_web/controllers/assessments_controller_test.exs index b339ca877..2d7963210 100644 --- a/test/cadet_web/controllers/assessments_controller_test.exs +++ b/test/cadet_web/controllers/assessments_controller_test.exs @@ -1,11 +1,11 @@ defmodule CadetWeb.AssessmentsControllerTest do use CadetWeb.ConnCase - alias CadetWeb.MissionsController + alias CadetWeb.AssessmentsController test "swagger" do - MissionsController.swagger_definitions() - MissionsController.swagger_path_index(nil) - MissionsController.swagger_path_show(nil) + AssessmentsController.swagger_definitions() + AssessmentsController.swagger_path_index(nil) + AssessmentsController.swagger_path_show(nil) end end From bc7982729f192cf54a5669b9ac31a0c17a4e241b Mon Sep 17 00:00:00 2001 From: shaowei Date: Sun, 24 Jun 2018 10:57:19 +0800 Subject: [PATCH 16/22] Update Answer controller spec --- .../controllers/answers_controller.ex | 38 +++++++++++++++++++ .../controllers/assessments_controller.ex | 21 ++++++---- .../controllers/grading_controller.ex | 12 +++--- lib/cadet_web/router.ex | 8 +--- 4 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 lib/cadet_web/controllers/answers_controller.ex diff --git a/lib/cadet_web/controllers/answers_controller.ex b/lib/cadet_web/controllers/answers_controller.ex new file mode 100644 index 000000000..c7d446ae5 --- /dev/null +++ b/lib/cadet_web/controllers/answers_controller.ex @@ -0,0 +1,38 @@ +defmodule CadetWeb.AnswerController do + use CadetWeb, :controller + + use PhoenixSwagger + + swagger_path :submit do + get("/assessments/question/{questionId}/submit") + + summary("Submit an answer to a question") + + security([%{JWT: []}]) + + consumes("application/json") + + parameters do + answer(:body, Schema.ref(:Answer), "answer", required: true) + end + + response(200, "OK") + response(400, "Missing parameter(s) or wrong answer type") + response(401, "Unauthorised") + end + + def swagger_definitions do + %{ + Answer: + swagger_schema do + properties do + answer( + :string_or_int, + "answer of appropriate type depending on question type", + required: true + ) + end + end + } + end +end diff --git a/lib/cadet_web/controllers/assessments_controller.ex b/lib/cadet_web/controllers/assessments_controller.ex index e5ac1d20b..aec4598ce 100644 --- a/lib/cadet_web/controllers/assessments_controller.ex +++ b/lib/cadet_web/controllers/assessments_controller.ex @@ -76,21 +76,26 @@ defmodule CadetWeb.AssessmentsController do Question: swagger_schema do properties do - questionId(:integer, "question id", required: true) - questionType(:string, "the question type (mcq/programming)", required: true) - content(:string, "the question content", required: true) + questionId(:integer, "The question id", required: true) + questionType(:string, "The question type (mcq/programming)", required: true) + content(:string, "The question content", required: true) choices( Schema.new do type(:array) items(Schema.ref(:MCQChoice)) end, - "mcq choices if question type is mcq" + "MCQ choices if question type is mcq" + ) + + solution( + Schema.ref(:MCQChoice), + "The correct choice for an MCQ question that belongs to a Path assessment" ) answer( :string_or_integer, - "previous answer for this quesiton (string/int) depending on question type", + "Previous answer for this quesiton (string/int) depending on question type", required: true ) @@ -99,14 +104,14 @@ defmodule CadetWeb.AssessmentsController do "The library used for this question (programming questions only)" ) - solution_template(:string, "solution template for programming questions") + solution_template(:string, "Solution template for programming questions") end end, MCQChoice: swagger_schema do properties do - content(:string, "the choice content", required: true) - hint(:string, "the hint", required: true) + content(:string, "The choice content", required: true) + hint(:string, "The hint", required: true) end end, Library: diff --git a/lib/cadet_web/controllers/grading_controller.ex b/lib/cadet_web/controllers/grading_controller.ex index 6cc81e3eb..5d402cb8f 100644 --- a/lib/cadet_web/controllers/grading_controller.ex +++ b/lib/cadet_web/controllers/grading_controller.ex @@ -88,12 +88,12 @@ defmodule CadetWeb.GradingController do max_xp(:integer, "the max xp that can be given to this question", required: true) end end, - Answer: - swagger_schema do - properties do - code(:string, "Code provided by student", required: true) - end - end, + # Answer: + # swagger_schema do + # properties do + # code(:string, "Code provided by student", required: true) + # end + # end, Grade: swagger_schema do properties do diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index 2b5521a6f..01e4c7fc9 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -29,14 +29,8 @@ defmodule CadetWeb.Router do scope "/", CadetWeb do pipe_through([:api, :auth, :ensure_auth]) - scope "/answer", Answer do - get("/programming/:id", ProgrammingAnswerController, :show) - post("/programming", ProgrammingAnswerController, :submit) - get("/mcq/:id", MCQAnswerController, :show) - post("/mcq", MCQAnswerController, :submit) - end - resources("/assessments", AssessmentsController, only: [:index, :show]) + post("/assessments/question/:questionid/submit", AnswerController, :submit) get("/grading", GradingController, :index) get("/grading/:submissionid/:questionid", GradingController, :show) From af341801bb156b9c6626f9f43f0dfe3a150beec5 Mon Sep 17 00:00:00 2001 From: shaowei Date: Sun, 24 Jun 2018 11:00:14 +0800 Subject: [PATCH 17/22] Add answer controller test file --- .../controllers/answer/mcq_answer_controller_test.exs | 11 ----------- .../answer/programming_answer_controller_test.exs | 11 ----------- test/cadet_web/controllers/answer_controller_test.exs | 10 ++++++++++ 3 files changed, 10 insertions(+), 22 deletions(-) delete mode 100644 test/cadet_web/controllers/answer/mcq_answer_controller_test.exs delete mode 100644 test/cadet_web/controllers/answer/programming_answer_controller_test.exs create mode 100644 test/cadet_web/controllers/answer_controller_test.exs diff --git a/test/cadet_web/controllers/answer/mcq_answer_controller_test.exs b/test/cadet_web/controllers/answer/mcq_answer_controller_test.exs deleted file mode 100644 index 511980189..000000000 --- a/test/cadet_web/controllers/answer/mcq_answer_controller_test.exs +++ /dev/null @@ -1,11 +0,0 @@ -defmodule CadetWeb.Answer.MCQAnswerControllerTest do - use CadetWeb.ConnCase - - alias CadetWeb.Answer.MCQAnswerController - - test "swagger" do - MCQAnswerController.swagger_definitions() - MCQAnswerController.swagger_path_submit(nil) - MCQAnswerController.swagger_path_show(nil) - end -end diff --git a/test/cadet_web/controllers/answer/programming_answer_controller_test.exs b/test/cadet_web/controllers/answer/programming_answer_controller_test.exs deleted file mode 100644 index 72edbb96a..000000000 --- a/test/cadet_web/controllers/answer/programming_answer_controller_test.exs +++ /dev/null @@ -1,11 +0,0 @@ -defmodule CadetWeb.Answer.ProgrammingAnswerControllerTest do - use CadetWeb.ConnCase - - alias CadetWeb.Answer.ProgrammingAnswerController - - test "swagger" do - ProgrammingAnswerController.swagger_definitions() - ProgrammingAnswerController.swagger_path_submit(nil) - ProgrammingAnswerController.swagger_path_show(nil) - end -end diff --git a/test/cadet_web/controllers/answer_controller_test.exs b/test/cadet_web/controllers/answer_controller_test.exs new file mode 100644 index 000000000..1fbe4f8e1 --- /dev/null +++ b/test/cadet_web/controllers/answer_controller_test.exs @@ -0,0 +1,10 @@ +defmodule CadetWeb.AnswerControllerTest do + use CadetWeb.ConnCase + + alias CadetWeb.AnswerController + + test "swagger" do + AnswerController.swagger_definitions() + AnswerController.swagger_path_submit(nil) + end +end From 5190e14ee7c316dc6258e6543edc207320585165 Mon Sep 17 00:00:00 2001 From: shaowei Date: Sun, 24 Jun 2018 12:09:33 +0800 Subject: [PATCH 18/22] Update grading controller spec --- .../controllers/assessments_controller.ex | 5 +- .../controllers/grading_controller.ex | 46 +++++++++---------- lib/cadet_web/router.ex | 2 +- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/cadet_web/controllers/assessments_controller.ex b/lib/cadet_web/controllers/assessments_controller.ex index aec4598ce..0d6dc04ce 100644 --- a/lib/cadet_web/controllers/assessments_controller.ex +++ b/lib/cadet_web/controllers/assessments_controller.ex @@ -88,10 +88,7 @@ defmodule CadetWeb.AssessmentsController do "MCQ choices if question type is mcq" ) - solution( - Schema.ref(:MCQChoice), - "The correct choice for an MCQ question that belongs to a Path assessment" - ) + solution(:integer, "Solution to a mcq question if it belongs to path assessment") answer( :string_or_integer, diff --git a/lib/cadet_web/controllers/grading_controller.ex b/lib/cadet_web/controllers/grading_controller.ex index 5d402cb8f..eb10e796a 100644 --- a/lib/cadet_web/controllers/grading_controller.ex +++ b/lib/cadet_web/controllers/grading_controller.ex @@ -6,20 +6,24 @@ defmodule CadetWeb.GradingController do swagger_path :index do get("/grading") - summary("Get a list of all submissions with current user as the grader.") + summary("Get a list of all submissions with current user as the grader. ") security([%{JWT: []}]) produces("application/json") + parameters do + filter(:query, :string, "Filter only specific types e.g. done/pending") + end + response(200, "OK", Schema.ref(:Submissions)) response(401, "Unauthorised") end swagger_path :show do - get("/grading/{submissionId}/{questionId}") + get("/grading/{submissionId}") - summary("Get information about a specific question in a specific submission to be graded.") + summary("Get information about a specific submission to be graded.") security([%{JWT: []}]) @@ -27,7 +31,6 @@ defmodule CadetWeb.GradingController do parameters do submissionId(:path, :integer, "submission id", required: true) - questionId(:path, :integer, "question id", required: true) end response(200, "OK", Schema.ref(:GradingInfo)) @@ -39,7 +42,7 @@ defmodule CadetWeb.GradingController do post("/grading/{submissionId}/{questionId}") summary( - "Update comment and/or marks given to the answer of a particular qurrstion in a submission" + "Update comment and/or marks given to the answer of a particular querstion in a submission" ) security([%{JWT: []}]) @@ -71,29 +74,26 @@ defmodule CadetWeb.GradingController do submissionId(:integer, "submission id", required: true) missionId(:integer, "mission id", required: true) studentId(:integer, "student id", required: true) - - questions( - Schema.new do - type(:array) - items(Schema.ref(:Questions)) - end - ) end end, GradingInfo: swagger_schema do - properties do - answer(Schema.ref(:Answer)) - grade(Schema.ref(:Grade)) - max_xp(:integer, "the max xp that can be given to this question", required: true) - end + description( + "A list of questions with submitted answers and previous grading info if available" + ) + + type(:array) + + items( + Schema.new do + properties do + question(Schema.ref(:Question)) + grade(Schema.ref(:Grade)) + max_xp(:integer, "the max xp that can be given to this question", required: true) + end + end + ) end, - # Answer: - # swagger_schema do - # properties do - # code(:string, "Code provided by student", required: true) - # end - # end, Grade: swagger_schema do properties do diff --git a/lib/cadet_web/router.ex b/lib/cadet_web/router.ex index 01e4c7fc9..9f5fe8b0b 100644 --- a/lib/cadet_web/router.ex +++ b/lib/cadet_web/router.ex @@ -33,7 +33,7 @@ defmodule CadetWeb.Router do post("/assessments/question/:questionid/submit", AnswerController, :submit) get("/grading", GradingController, :index) - get("/grading/:submissionid/:questionid", GradingController, :show) + get("/grading/:submissionid", GradingController, :show) post("/grading/:submissionid/:questionid", GradingController, :update) end From 4cc6799b8c27d48096a5b6542abc0a22ef9ef5f9 Mon Sep 17 00:00:00 2001 From: shaowei Date: Sun, 24 Jun 2018 12:12:28 +0800 Subject: [PATCH 19/22] Rename answers controller file --- .../answer/mcq_answer_controller.ex | 66 ------------------ .../answer/programming_answer_controller.ex | 69 ------------------- ...ers_controller.ex => answer_controller.ex} | 0 3 files changed, 135 deletions(-) delete mode 100644 lib/cadet_web/controllers/answer/mcq_answer_controller.ex delete mode 100644 lib/cadet_web/controllers/answer/programming_answer_controller.ex rename lib/cadet_web/controllers/{answers_controller.ex => answer_controller.ex} (100%) diff --git a/lib/cadet_web/controllers/answer/mcq_answer_controller.ex b/lib/cadet_web/controllers/answer/mcq_answer_controller.ex deleted file mode 100644 index c03db59f5..000000000 --- a/lib/cadet_web/controllers/answer/mcq_answer_controller.ex +++ /dev/null @@ -1,66 +0,0 @@ -defmodule CadetWeb.Answer.MCQAnswerController do - use CadetWeb, :controller - - use PhoenixSwagger - - swagger_path :show do - get("/answer/mcq/{questionId}") - - summary("Obtain answer of a particular MCQ previously submitted by current user") - - security([%{JWT: []}]) - - produces("application/json") - - parameters do - questionId(:path, :integer, "question id", required: true) - end - - response(200, "OK", Schema.ref(:MCQAnswer)) - - response( - 400, - "Missing parameter(s) or wrong answer type or non-existent answer for given questionId" - ) - - response(401, "Unauthorised") - end - - swagger_path :submit do - post("/answer/mcq") - - summary("Create/update answer of a particular MCQ question (under the current user).") - - security([%{JWT: []}]) - - consumes("application/json") - produces("application/json") - - parameters do - answer(:body, Schema.ref(:MCQAnswer), "answer", required: true) - end - - response(200, "OK", Schema.ref(:MCQCorrectness)) - response(400, "Missing parameter(s) or wrong answer type or invalid questionId") - response(401, "Unauthorised") - end - - def swagger_definitions do - %{ - MCQAnswer: - swagger_schema do - properties do - questionId(:integer, "The question id", required: true) - - answer(:integer, "The index of the MCQ choice that is the answer", required: true) - end - end, - MCQCorrectness: - swagger_schema do - properties do - correct(:boolean, "Whether the answer submitted was correct") - end - end - } - end -end diff --git a/lib/cadet_web/controllers/answer/programming_answer_controller.ex b/lib/cadet_web/controllers/answer/programming_answer_controller.ex deleted file mode 100644 index 7e991be54..000000000 --- a/lib/cadet_web/controllers/answer/programming_answer_controller.ex +++ /dev/null @@ -1,69 +0,0 @@ -defmodule CadetWeb.Answer.ProgrammingAnswerController do - use CadetWeb, :controller - - use PhoenixSwagger - - swagger_path :show do - get("/answer/programming/{questionId}") - - summary( - "Obtain answer of a particular programming question submitted previously by current user" - ) - - security([%{JWT: []}]) - - produces("application/json") - - parameters do - questionId(:path, :integer, "question id", required: true) - end - - response(200, "OK", Schema.ref(:ProgrammingAnswer)) - - response( - 400, - "Missing parameter(s) or wrong answer type or non-existent answer for given questionId" - ) - - response(401, "Unauthorised") - end - - swagger_path :submit do - post("/answer/programming") - - summary("Create/update answer of a particular programming question (under the current user).") - - security([%{JWT: []}]) - - consumes("application/json") - - parameters do - answer(:body, Schema.ref(:ProgrammingAnswer), "answer", required: true) - end - - response(200, "OK") - response(400, "Missing parameter(s) or wrong answer type") - response(401, "Unauthorised") - end - - def swagger_definitions do - %{ - ProgrammingAnswer: - swagger_schema do - properties do - questionId(:integer, "The question id", required: true) - - submitted(:boolean, "Whether this is the final answer", default: false) - - answer( - Schema.new do - properties do - code(:string, "Code submitted", required: true) - end - end - ) - end - end - } - end -end diff --git a/lib/cadet_web/controllers/answers_controller.ex b/lib/cadet_web/controllers/answer_controller.ex similarity index 100% rename from lib/cadet_web/controllers/answers_controller.ex rename to lib/cadet_web/controllers/answer_controller.ex From c60414c66a6a3f86ce572fa141999824370f57bf Mon Sep 17 00:00:00 2001 From: shaowei Date: Sun, 24 Jun 2018 12:17:51 +0800 Subject: [PATCH 20/22] Change submit method to POST --- lib/cadet_web/controllers/answer_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cadet_web/controllers/answer_controller.ex b/lib/cadet_web/controllers/answer_controller.ex index c7d446ae5..dbbc66140 100644 --- a/lib/cadet_web/controllers/answer_controller.ex +++ b/lib/cadet_web/controllers/answer_controller.ex @@ -4,7 +4,7 @@ defmodule CadetWeb.AnswerController do use PhoenixSwagger swagger_path :submit do - get("/assessments/question/{questionId}/submit") + post("/assessments/question/{questionId}/submit") summary("Submit an answer to a question") From edd0ed2db24b22ef6696a8b1359d7f6d701aecf5 Mon Sep 17 00:00:00 2001 From: shaowei Date: Mon, 25 Jun 2018 00:18:25 +0800 Subject: [PATCH 21/22] Split Assessment swagger model into two models --- .../controllers/assessments_controller.ex | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/cadet_web/controllers/assessments_controller.ex b/lib/cadet_web/controllers/assessments_controller.ex index 0d6dc04ce..8d4b03706 100644 --- a/lib/cadet_web/controllers/assessments_controller.ex +++ b/lib/cadet_web/controllers/assessments_controller.ex @@ -40,16 +40,14 @@ defmodule CadetWeb.AssessmentsController do swagger_schema do description("A list of all assessments") type(:array) - items(Schema.ref(:Assessment)) + items(Schema.ref(:AssessmentOverview)) end, - Assessment: + AssessmentOverview: swagger_schema do properties do - order(:integer, "The order of showing the assessments", required: true) id(:integer, "The assessment id", required: true) title(:string, "The title of the assessment", required: true) type(:string, "Either mission/sidequest/path/contest", required: true) - summary_long(:string, "Long summary", required: true) summary_short(:string, "Short summary", required: true) open_at(:string, "The opening date", format: "date-time", required: true) close_at(:string, "The closing date", format: "date-time", required: true) @@ -61,9 +59,16 @@ defmodule CadetWeb.AssessmentsController do ) cover_picture(:string, "The URL to the cover picture", required: true) + end + end, + Assessment: + swagger_schema do + properties do + id(:integer, "The assessment id", required: true) + title(:string, "The title of the assessment", required: true) + summary_long(:string, "Long summary", required: true) mission_pdf(:string, "The URL to the assessment pdf") - # Questions will only be returned for GET /assessments/{assessmentId} questions(Schema.ref(:Questions), "The list of questions for this assessment") end end, From 7f247e83c23314f13ac7f8b950d9d29ce0d4aee4 Mon Sep 17 00:00:00 2001 From: shaowei Date: Mon, 25 Jun 2018 00:46:01 +0800 Subject: [PATCH 22/22] Minor changes to add missing description/field --- lib/cadet_web/controllers/answer_controller.ex | 6 +++++- lib/cadet_web/controllers/assessments_controller.ex | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/cadet_web/controllers/answer_controller.ex b/lib/cadet_web/controllers/answer_controller.ex index dbbc66140..05df41f0f 100644 --- a/lib/cadet_web/controllers/answer_controller.ex +++ b/lib/cadet_web/controllers/answer_controller.ex @@ -6,7 +6,11 @@ defmodule CadetWeb.AnswerController do swagger_path :submit do post("/assessments/question/{questionId}/submit") - summary("Submit an answer to a question") + summary("Submit an answer to a question.") + + description( + "For MCQ, answer contains choice_id. For programming question, this is a string containing the student's code." + ) security([%{JWT: []}]) diff --git a/lib/cadet_web/controllers/assessments_controller.ex b/lib/cadet_web/controllers/assessments_controller.ex index 8d4b03706..c22033c82 100644 --- a/lib/cadet_web/controllers/assessments_controller.ex +++ b/lib/cadet_web/controllers/assessments_controller.ex @@ -66,6 +66,7 @@ defmodule CadetWeb.AssessmentsController do properties do id(:integer, "The assessment id", required: true) title(:string, "The title of the assessment", required: true) + type(:string, "Either mission/sidequest/path/contest", required: true) summary_long(:string, "Long summary", required: true) mission_pdf(:string, "The URL to the assessment pdf")