Skip to content

Commit

Permalink
adjusted by comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cremertim committed Oct 27, 2024
1 parent e1ec400 commit 5048cf8
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ public ResponseEntity<FaqDTO> createFaq(@RequestBody Faq faq, @PathVariable Long
if (faq.getId() != null) {
throw new BadRequestAlertException("A new faq cannot already have an ID", ENTITY_NAME, "idExists");
}
if (faq.getFaqState() == FaqState.ACCEPTED) {
checkRoleForCourse(courseId, Role.INSTRUCTOR);
}
checkIsInstructor(faq.getFaqState(), courseId);
if (faq.getCourse() == null || !faq.getCourse().getId().equals(courseId)) {
throw new BadRequestAlertException("Course ID in path and FAQ do not match", ENTITY_NAME, "courseIdMismatch");
}
Expand All @@ -107,13 +105,9 @@ public ResponseEntity<FaqDTO> updateFaq(@RequestBody Faq faq, @PathVariable Long
if (faqId == null || !faqId.equals(faq.getId())) {
throw new BadRequestAlertException("Id of FAQ and path must match", ENTITY_NAME, "idNull");
}
if (faq.getFaqState() == FaqState.ACCEPTED) {
checkRoleForCourse(courseId, Role.INSTRUCTOR);
}
checkIsInstructor(faq.getFaqState(), courseId);
Faq existingFaq = faqRepository.findByIdElseThrow(faqId);
if (existingFaq.getFaqState() == FaqState.ACCEPTED) {
checkRoleForCourse(courseId, Role.INSTRUCTOR);
}
checkIsInstructor(faq.getFaqState(), courseId);
if (!Objects.equals(existingFaq.getCourse().getId(), courseId)) {
throw new BadRequestAlertException("Course ID of the FAQ provided courseID must match", ENTITY_NAME, "idNull");
}
Expand Down Expand Up @@ -235,4 +229,10 @@ private void checkShouldAccessNotAccepted(FaqState faqState, Long courseId) {
}
}

private void checkIsInstructor(FaqState faqState, Long courseId) {
if (faqState != FaqState.ACCEPTED) {
checkRoleForCourse(courseId, Role.TEACHING_ASSISTANT);
}
}

}

0 comments on commit 5048cf8

Please sign in to comment.