diff --git a/src/main/java/teammates/ui/output/FeedbackResponsesData.java b/src/main/java/teammates/ui/output/FeedbackResponsesData.java index 215987ccdcd..74db4703828 100644 --- a/src/main/java/teammates/ui/output/FeedbackResponsesData.java +++ b/src/main/java/teammates/ui/output/FeedbackResponsesData.java @@ -1,5 +1,6 @@ package teammates.ui.output; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -16,6 +17,14 @@ public FeedbackResponsesData(List responses) { this.responses = responses.stream().map(FeedbackResponseData::new).collect(Collectors.toList()); } + public FeedbackResponsesData() { + responses = Collections.emptyList(); + } + + public void setResponses(List responses) { + this.responses = responses; + } + public List getResponses() { return responses; } diff --git a/src/main/java/teammates/ui/webapi/GetFeedbackResponsesAction.java b/src/main/java/teammates/ui/webapi/GetFeedbackResponsesAction.java index 2280d5601f9..5ca09ae8e49 100644 --- a/src/main/java/teammates/ui/webapi/GetFeedbackResponsesAction.java +++ b/src/main/java/teammates/ui/webapi/GetFeedbackResponsesAction.java @@ -1,5 +1,6 @@ package teammates.ui.webapi; +import java.util.LinkedList; import java.util.List; import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes; @@ -14,6 +15,7 @@ import teammates.common.exception.InvalidHttpParameterException; import teammates.common.util.Const; import teammates.ui.output.FeedbackResponseCommentData; +import teammates.ui.output.FeedbackResponseData; import teammates.ui.output.FeedbackResponsesData; import teammates.ui.request.Intent; @@ -77,18 +79,23 @@ JsonResult execute() { throw new InvalidHttpParameterException("Unknown intent " + intent); } - FeedbackResponsesData result = new FeedbackResponsesData(responses); - result.getResponses().forEach(response -> { - if (questionAttributes.getQuestionType() != FeedbackQuestionType.MCQ) { + List responsesData = new LinkedList<>(); + responses.forEach(response -> { + FeedbackResponseData data = new FeedbackResponseData(response); + if (questionAttributes.getQuestionType() == FeedbackQuestionType.MCQ) { // Only MCQ questions can have participant comment - return; - } - FeedbackResponseCommentAttributes comment = - logic.getFeedbackResponseCommentForResponseFromParticipant(response.getFeedbackResponseId()); - if (comment != null) { - response.setGiverComment(new FeedbackResponseCommentData(comment)); + FeedbackResponseCommentAttributes comment = + logic.getFeedbackResponseCommentForResponseFromParticipant(response.getId()); + if (comment != null) { + data.setGiverComment(new FeedbackResponseCommentData(comment)); + } } + responsesData.add(data); }); + FeedbackResponsesData result = new FeedbackResponsesData(); + if (!responsesData.isEmpty()) { + result.setResponses(responsesData); + } return new JsonResult(result); } diff --git a/src/test/java/teammates/ui/webapi/GetFeedbackResponsesActionTest.java b/src/test/java/teammates/ui/webapi/GetFeedbackResponsesActionTest.java index 966cb954690..d9523a0fae9 100644 --- a/src/test/java/teammates/ui/webapi/GetFeedbackResponsesActionTest.java +++ b/src/test/java/teammates/ui/webapi/GetFeedbackResponsesActionTest.java @@ -5,9 +5,11 @@ import org.apache.http.HttpStatus; import org.testng.annotations.Test; +import teammates.common.datatransfer.DataBundle; import teammates.common.datatransfer.FeedbackParticipantType; import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes; import teammates.common.datatransfer.attributes.FeedbackResponseAttributes; +import teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes; import teammates.common.datatransfer.attributes.FeedbackSessionAttributes; import teammates.common.datatransfer.attributes.InstructorAttributes; import teammates.common.datatransfer.attributes.StudentAttributes; @@ -17,6 +19,7 @@ import teammates.common.util.Const; import teammates.common.util.JsonUtils; import teammates.common.util.StringHelper; +import teammates.ui.output.FeedbackResponseCommentData; import teammates.ui.output.FeedbackResponseData; import teammates.ui.output.FeedbackResponsesData; import teammates.ui.request.Intent; @@ -123,6 +126,29 @@ protected void testExecute_instructorSubmission_shouldGetResponseSuccessfully() verifyFeedbackResponseEquals(expected, actualResponse); } + @Test + protected void testExecute_commentSubmission_shouldGetCommentsSuccessfully() throws InvalidParametersException { + DataBundle dataBundle = loadDataBundle("/FeedbackResponseCommentCRUDTest.json"); + removeAndRestoreDataBundle(dataBundle); + StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1"); + FeedbackQuestionAttributes qn3InSession1 = dataBundle.feedbackQuestions.get("qn3InSession1"); + FeedbackResponseAttributes response1ForQ3 = dataBundle.feedbackResponses.get("response1ForQ3"); + FeedbackResponseCommentAttributes comment1FromStudent1 = + dataBundle.feedbackResponseComments.get("comment1FromStudent1"); + + loginAsStudent(student1InCourse1.getGoogleId()); + String[] params = { + Const.ParamsNames.FEEDBACK_QUESTION_ID, qn3InSession1.getId(), + Const.ParamsNames.INTENT, Intent.STUDENT_SUBMISSION.toString(), + }; + FeedbackResponsesData actualData = getFeedbackResponse(params); + List actualResponses = actualData.getResponses(); + + assertEquals(1, actualResponses.size()); + verifyFeedbackResponseEquals(response1ForQ3, actualResponses.get(0)); + verifyFeedbackCommentEquals(comment1FromStudent1, actualResponses.get(0).getGiverComment()); + } + @Test @Override protected void testAccessControl() throws Exception { @@ -261,4 +287,12 @@ private void verifyFeedbackResponseEquals(FeedbackResponseAttributes expected, F assertEquals(JsonUtils.toJson(expected.getResponseDetails()), JsonUtils.toJson(actual.getResponseDetails())); } + + private void verifyFeedbackCommentEquals( + FeedbackResponseCommentAttributes expected, FeedbackResponseCommentData actual) { + assertNotNull(actual); + assertEquals(expected.getCommentGiver(), actual.getCommentGiver()); + assertEquals(expected.getCommentText(), actual.getCommentText()); + assertEquals(expected.getLastEditorEmail(), actual.getLastEditorEmail()); + } }