Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication: Add FAQs to Artemis #9325

Merged
merged 125 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
b3bf2bb
FAQ - system provisional backend
cremertim Sep 3, 2024
44a7060
Merge branch 'refs/heads/develop' into feature/faq/implement-faq-basis
cremertim Sep 3, 2024
f49731e
Add meta information and state to FAQ
cremertim Sep 3, 2024
c2efdbb
Fixed minor mapping error
cremertim Sep 3, 2024
5467a10
Added cascade delete
cremertim Sep 5, 2024
ebe8044
Added cascade deletion on course deletion
cremertim Sep 9, 2024
ae7e4b4
Merge branch 'refs/heads/develop' into feature/faq/implement-faq-basis
cremertim Sep 9, 2024
2d3ea4e
Changed rest of server stuff
cremertim Sep 10, 2024
be22131
Add translations and fix uppercase
cremertim Sep 10, 2024
407072e
Add first draft of FAQ System
cremertim Sep 10, 2024
f96f610
refactored toggleFilters to make commits work
cremertim Sep 10, 2024
af392db
Added integration test, but they do not work yet
cremertim Sep 11, 2024
1c29060
Integration Tests
cremertim Sep 11, 2024
943363d
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 11, 2024
6e80b3b
Integration Tests fixed. Why so ever its works now
cremertim Sep 12, 2024
4a9609c
Formula Action change from Patrick
cremertim Sep 12, 2024
f276f9b
Make components standalone
cremertim Sep 12, 2024
a436aa8
Removed unnecessary import statements
cremertim Sep 12, 2024
117b305
Made filter to use badges, not plain text
cremertim Sep 14, 2024
ea49c58
Added Student view and filtering as a service
cremertim Sep 15, 2024
ac619d3
Add markdown highlighting for FAQ's
cremertim Sep 16, 2024
b117217
Allowed students to pull stuff
cremertim Sep 17, 2024
dee6e5a
FAQ - system provisional backend
cremertim Sep 3, 2024
8d254d2
Add meta information and state to FAQ
cremertim Sep 3, 2024
d1f7823
Fixed minor mapping error
cremertim Sep 3, 2024
af53c20
Added cascade delete
cremertim Sep 5, 2024
a5b7793
Added cascade deletion on course deletion
cremertim Sep 9, 2024
58136b6
Changed rest of server stuff
cremertim Sep 10, 2024
db67131
Add translations and fix uppercase
cremertim Sep 10, 2024
6c494e7
Add first draft of FAQ System
cremertim Sep 10, 2024
16ddd8c
refactored toggleFilters to make commits work
cremertim Sep 10, 2024
019349d
Added integration test, but they do not work yet
cremertim Sep 11, 2024
4ab0edf
Integration Tests
cremertim Sep 11, 2024
b433a3a
Integration Tests fixed. Why so ever its works now
cremertim Sep 12, 2024
a232c25
Formula Action change from Patrick
cremertim Sep 12, 2024
80cc42a
Make components standalone
cremertim Sep 12, 2024
8f71b0a
Removed unnecessary import statements
cremertim Sep 12, 2024
7ffc7bf
Made filter to use badges, not plain text
cremertim Sep 14, 2024
f68d621
Added Student view and filtering as a service
cremertim Sep 15, 2024
df84495
Add markdown highlighting for FAQ's
cremertim Sep 16, 2024
1174603
Allowed students to pull stuff
cremertim Sep 17, 2024
0b2bae7
fixed imports
cremertim Sep 17, 2024
a8bd41b
fixed imports
cremertim Sep 17, 2024
688ceb8
moved faq button up
cremertim Sep 17, 2024
0290f9b
Made page scrollable, moved categories in the same row to safe space
cremertim Sep 17, 2024
5976d6f
removed search bar
cremertim Sep 17, 2024
047eb52
Fixed style issues
cremertim Sep 17, 2024
5114dd8
Fixed coderabbit style issues
cremertim Sep 17, 2024
764e7ba
Fixed coderabbit style issues
cremertim Sep 17, 2024
20f02da
Test structure
cremertim Sep 17, 2024
6953f40
Fixed Coderabbit
cremertim Sep 18, 2024
031bc3b
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 18, 2024
80c5452
Fixed Coderabbit
cremertim Sep 18, 2024
5aeda2f
Further Coderabbit
cremertim Sep 18, 2024
f5ab0e4
improved validation and further coderabbit fixes
cremertim Sep 18, 2024
b9f0935
Fixed minor issue
cremertim Sep 18, 2024
ddca96e
Fixed to enable faq for course
cremertim Sep 18, 2024
cb12c44
Another coderabit hint
cremertim Sep 18, 2024
d767dd9
Another coderabit hint
cremertim Sep 18, 2024
b5929e3
Remove repo from resource
cremertim Sep 18, 2024
c0e1432
Remove repo from resource
cremertim Sep 19, 2024
bd8a8c8
Added client test for faq.service
cremertim Sep 19, 2024
cc9c3e5
Adjusted naming to be equal
cremertim Sep 20, 2024
722366e
Added first client tests for the components
cremertim Sep 20, 2024
afe6ea1
Rename FAQ
cremertim Sep 20, 2024
7ede184
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 20, 2024
1dfdac3
Fixed creation bug and made category filter working as expected
cremertim Sep 20, 2024
8ae8c86
added tests, one is still not working
cremertim Sep 20, 2024
ab73e50
tried to fix E2E tests
cremertim Sep 20, 2024
40e1213
coderabit
cremertim Sep 20, 2024
f33cad4
Fixed E2E test
cremertim Sep 23, 2024
aff8ad6
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 23, 2024
e80e7fd
Integrated changes, fixed last test
cremertim Sep 23, 2024
688305d
refixed e2e test
cremertim Sep 23, 2024
306592b
fixed doc
cremertim Sep 24, 2024
a627e43
use base class
cremertim Sep 24, 2024
9b1ced2
use base class
cremertim Sep 24, 2024
eda1de3
adressed issues found in testing session
cremertim Sep 24, 2024
da5a0e0
added client tests
cremertim Sep 24, 2024
3f8e693
increased client tests coverage
cremertim Sep 24, 2024
1793810
Added further test, fixed failing one
cremertim Sep 25, 2024
19896f8
Added further test
cremertim Sep 25, 2024
7e031cc
Added further test
cremertim Sep 25, 2024
fbac0cd
Added further test
cremertim Sep 25, 2024
0c95e8d
Added further test
cremertim Sep 25, 2024
e759640
Added further test
cremertim Sep 25, 2024
444942c
Added further test
cremertim Sep 25, 2024
61f66ea
Reduced coverage to fix client tests.
cremertim Sep 26, 2024
188125a
Reduced coverage to fix client tests.
cremertim Sep 27, 2024
567b32b
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 27, 2024
9fd4a76
Removed module, updated service injection, renamed endpoints
cremertim Sep 27, 2024
948e364
Added FaqDTO, fixed Tests
cremertim Sep 27, 2024
c9f4151
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 27, 2024
876d6be
Added FaqDTO, fixed Tests
cremertim Sep 27, 2024
aff2daf
Adjusted css to use bootstrap
cremertim Sep 27, 2024
515b586
Scrollbar
cremertim Sep 27, 2024
091c654
inject
cremertim Sep 27, 2024
9627086
fixed two test issues
cremertim Sep 27, 2024
a38f268
inserted onChange
cremertim Sep 27, 2024
b2e4647
fixed test
cremertim Sep 27, 2024
d7da76f
fixed some coderabit hints
cremertim Sep 27, 2024
ad5707b
fixed some coderabit hints
cremertim Sep 27, 2024
fb0e40f
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 28, 2024
d145337
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 28, 2024
187133c
Merge remote-tracking branch 'origin/feature/faq/implement-faq-basis'…
cremertim Sep 28, 2024
0ce6531
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 29, 2024
0b54e6b
Adressed patricks comments, fixed failing test
cremertim Sep 29, 2024
2d25d30
remove duplicate
cremertim Sep 29, 2024
8ae824c
remove duplicate
cremertim Sep 29, 2024
2ce0631
fixed coderabit issues
cremertim Sep 29, 2024
76a1e53
fixed coderabit issues
cremertim Sep 29, 2024
8bf74af
Removed Resize Observer
cremertim Sep 30, 2024
a4925d9
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Sep 30, 2024
48cb712
Added lines for the overview, sorted per default
cremertim Oct 1, 2024
dfe9e43
Refactor database column names to contain singular
cremertim Oct 1, 2024
5b5bfec
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Oct 1, 2024
cbdaffa
Fixed translation
cremertim Oct 1, 2024
9c1b5a6
css fix
cremertim Oct 1, 2024
b42ec4f
removed validation of markdown editor
cremertim Oct 1, 2024
5122a10
Solve markdown issues
cremertim Oct 2, 2024
7ad62dc
Fixed server errors
cremertim Oct 2, 2024
bd33d53
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Oct 2, 2024
80fd090
Matched FAQ categories size to Exercise Categories
cremertim Oct 2, 2024
71cf572
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Oct 2, 2024
8c7fd30
Merge branch 'develop' into feature/faq/implement-faq-basis
cremertim Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions jest.config.js
cremertim marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ module.exports = {
coverageThreshold: {
global: {
// TODO: in the future, the following values should increase to at least 90%
statements: 87.35,
branches: 73.57,
functions: 81.91,
lines: 87.41,
statements: 87.36,
branches: 73.52,
functions: 81.9,
lines: 87.42,
cremertim marked this conversation as resolved.
Show resolved Hide resolved
},
},
coverageReporters: ['clover', 'json', 'lcov', 'text-summary'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package de.tum.cit.aet.artemis.communication.domain;

import java.util.HashSet;
import java.util.Set;

import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import de.tum.cit.aet.artemis.core.domain.AbstractAuditingEntity;
import de.tum.cit.aet.artemis.core.domain.Course;

/**
* A FAQ.
*/
@Entity
@Table(name = "faq")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class Faq extends AbstractAuditingEntity {

@Column(name = "question_title")
private String questionTitle;

@Column(name = "question_answer")
private String questionAnswer;

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "faq_category", joinColumns = @JoinColumn(name = "faq_id"))
@Column(name = "category")
private Set<String> categories = new HashSet<>();

@Enumerated(EnumType.STRING)
@Column(name = "faq_state")
private FaqState faqState;

@ManyToOne
@JsonIgnoreProperties(value = { "faqs" }, allowSetters = true)
private Course course;
cremertim marked this conversation as resolved.
Show resolved Hide resolved

public String getQuestionTitle() {
return questionTitle;
}

public void setQuestionTitle(String questionTitle) {
this.questionTitle = questionTitle;
}

public String getQuestionAnswer() {
return questionAnswer;
}

public void setQuestionAnswer(String questionAnswer) {
this.questionAnswer = questionAnswer;
}

public Course getCourse() {
return course;
}

public void setCourse(Course course) {
this.course = course;
}

public Set<String> getCategories() {
return categories;
}

public void setCategories(Set<String> categories) {
this.categories = categories;
}

public FaqState getFaqState() {
return faqState;
}

public void setFaqState(FaqState faqState) {
this.faqState = faqState;
}

@Override
public String toString() {
return "Faq{" + "id=" + getId() + ", questionTitle='" + getQuestionTitle() + "'" + ", questionAnswer='" + getQuestionAnswer() + "'" + ", faqState='" + getFaqState() + "}";
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package de.tum.cit.aet.artemis.communication.domain;

public enum FaqState {
ACCEPTED, REJECTED, PROPOSED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.tum.cit.aet.artemis.communication.dto;

import java.util.Set;

import com.fasterxml.jackson.annotation.JsonInclude;

import de.tum.cit.aet.artemis.communication.domain.Faq;
import de.tum.cit.aet.artemis.communication.domain.FaqState;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
public record FaqDTO(Long id, String questionTitle, String questionAnswer, Set<String> categories, FaqState faqState) {
cremertim marked this conversation as resolved.
Show resolved Hide resolved

public FaqDTO(Faq faq) {
this(faq.getId(), faq.getQuestionTitle(), faq.getQuestionAnswer(), faq.getCategories(), faq.getFaqState());
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved
cremertim marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.tum.cit.aet.artemis.communication.repository;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.Set;

import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import de.tum.cit.aet.artemis.communication.domain.Faq;
import de.tum.cit.aet.artemis.core.repository.base.ArtemisJpaRepository;

/**
* Spring Data repository for the Faq entity.
*/
@Profile(PROFILE_CORE)
@Repository
public interface FaqRepository extends ArtemisJpaRepository<Faq, Long> {

Set<Faq> findAllByCourseId(Long courseId);
cremertim marked this conversation as resolved.
Show resolved Hide resolved

@Query("""
SELECT DISTINCT faq.categories
FROM Faq faq
WHERE faq.course.id = :courseId
""")
Set<String> findAllCategoriesByCourseId(@Param("courseId") Long courseId);
cremertim marked this conversation as resolved.
Show resolved Hide resolved

@Transactional
@Modifying
void deleteAllByCourseId(Long courseId);
cremertim marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package de.tum.cit.aet.artemis.communication.web;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import de.tum.cit.aet.artemis.communication.domain.Faq;
import de.tum.cit.aet.artemis.communication.dto.FaqDTO;
import de.tum.cit.aet.artemis.communication.repository.FaqRepository;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.exception.BadRequestAlertException;
import de.tum.cit.aet.artemis.core.repository.CourseRepository;
import de.tum.cit.aet.artemis.core.security.Role;
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastInstructor;
import de.tum.cit.aet.artemis.core.security.annotations.EnforceAtLeastStudent;
import de.tum.cit.aet.artemis.core.service.AuthorizationCheckService;
import de.tum.cit.aet.artemis.core.util.HeaderUtil;

/**
* REST controller for managing Faqs.
*/
cremertim marked this conversation as resolved.
Show resolved Hide resolved
@Profile(PROFILE_CORE)
@RestController
@RequestMapping("api/")
public class FaqResource {
cremertim marked this conversation as resolved.
Show resolved Hide resolved

private static final Logger log = LoggerFactory.getLogger(FaqResource.class);

private static final String ENTITY_NAME = "faq";

@Value("${jhipster.clientApp.name}")
private String applicationName;

cremertim marked this conversation as resolved.
Show resolved Hide resolved
cremertim marked this conversation as resolved.
Show resolved Hide resolved
private final CourseRepository courseRepository;

private final AuthorizationCheckService authCheckService;

private final FaqRepository faqRepository;

public FaqResource(CourseRepository courseRepository, AuthorizationCheckService authCheckService, FaqRepository faqRepository) {

this.courseRepository = courseRepository;
this.authCheckService = authCheckService;
this.faqRepository = faqRepository;
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved

/**
* POST /courses/:courseId/faqs : Create a new faq.
*
* @param faq the faq to create *
* @param courseId the id of the course the faq belongs to
cremertim marked this conversation as resolved.
Show resolved Hide resolved
* @return the ResponseEntity with status 201 (Created) and with body the new faq, or with status 400 (Bad Request)
* if the faq has already an ID or if the faq course id does not match with the path variable
cremertim marked this conversation as resolved.
Show resolved Hide resolved
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("courses/{courseId}/faqs")
@EnforceAtLeastInstructor
public ResponseEntity<FaqDTO> createFaq(@RequestBody Faq faq, @PathVariable Long courseId) throws URISyntaxException {
log.debug("REST request to save Faq : {}", faq);
cremertim marked this conversation as resolved.
Show resolved Hide resolved
if (faq.getId() != null) {
throw new BadRequestAlertException("A new faq cannot already have an ID", ENTITY_NAME, "idExists");
}

if (faq.getCourse() == null || !faq.getCourse().getId().equals(courseId)) {
throw new BadRequestAlertException("Course ID in path and FAQ do not match", ENTITY_NAME, "courseIdMismatch");
}
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, faq.getCourse(), null);

cremertim marked this conversation as resolved.
Show resolved Hide resolved
Faq savedFaq = faqRepository.save(faq);
FaqDTO dto = new FaqDTO(savedFaq);
return ResponseEntity.created(new URI("/api/courses/" + courseId + "/faqs/" + savedFaq.getId())).body(dto);
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved

/**
* PUT /courses/:courseId/faqs/:faqId : Updates an existing faq.
*
* @param faq the faq to update
* @param faqId id of the faq to be updated *
* @param courseId the id of the course the faq belongs to
* @return the ResponseEntity with status 200 (OK) and with body the updated faq, or with status 400 (Bad Request)
* if the faq is not valid or if the faq course id does not match with the path variable
*/
@PutMapping("courses/{courseId}/faqs/{faqId}")
@EnforceAtLeastInstructor
public ResponseEntity<FaqDTO> updateFaq(@RequestBody Faq faq, @PathVariable Long faqId, @PathVariable Long courseId) {
log.debug("REST request to update Faq : {}", faq);
if (faqId == null || !faqId.equals(faq.getId())) {
throw new BadRequestAlertException("Id of FAQ and path must match", ENTITY_NAME, "idNull");
cremertim marked this conversation as resolved.
Show resolved Hide resolved
}
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, faq.getCourse(), null);
cremertim marked this conversation as resolved.
Show resolved Hide resolved
Faq existingFaq = faqRepository.findByIdElseThrow(faqId);
if (!Objects.equals(existingFaq.getCourse().getId(), courseId)) {
throw new BadRequestAlertException("Course ID of the FAQ provided courseID must match", ENTITY_NAME, "idNull");
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved
Faq updatedFaq = faqRepository.save(faq);
FaqDTO dto = new FaqDTO(updatedFaq);
return ResponseEntity.ok().body(dto);
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved
cremertim marked this conversation as resolved.
Show resolved Hide resolved

/**
* GET /courses/:courseId/faqs/:faqId : get the faq with the id faqId.
*
* @param faqId the faqId of the faq to retrieve *
* @param courseId the id of the course the faq belongs to
* @return the ResponseEntity with status 200 (OK) and with body the faq, or with status 404 (Not Found)
*/
cremertim marked this conversation as resolved.
Show resolved Hide resolved
@GetMapping("courses/{courseId}/faqs/{faqId}")
@EnforceAtLeastStudent
public ResponseEntity<FaqDTO> getFaq(@PathVariable Long faqId, @PathVariable Long courseId) {
log.debug("REST request to get faq {}", faqId);
Faq faq = faqRepository.findByIdElseThrow(faqId);
if (faq.getCourse() == null || !faq.getCourse().getId().equals(courseId)) {
throw new BadRequestAlertException("Course ID in path and FAQ do not match", ENTITY_NAME, "courseIdMismatch");
}
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, faq.getCourse(), null);
cremertim marked this conversation as resolved.
Show resolved Hide resolved
FaqDTO dto = new FaqDTO(faq);
return ResponseEntity.ok(dto);
cremertim marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* DELETE /courses/:courseId/faqs/:faqId : delete the "id" faq.
*
* @param faqId the id of the faq to delete
* @param courseId the id of the course the faq belongs to
* @return the ResponseEntity with status 200 (OK)
*/
cremertim marked this conversation as resolved.
Show resolved Hide resolved
@DeleteMapping("courses/{courseId}/faqs/{faqId}")
@EnforceAtLeastInstructor
public ResponseEntity<Void> deleteFaq(@PathVariable Long faqId, @PathVariable Long courseId) {

log.debug("REST request to delete faq {}", faqId);
Faq existingFaq = faqRepository.findByIdElseThrow(faqId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, existingFaq.getCourse(), null);
if (!Objects.equals(existingFaq.getCourse().getId(), courseId)) {
throw new BadRequestAlertException("Course ID of the FAQ provided courseID must match", ENTITY_NAME, "idNull");
}
faqRepository.deleteById(faqId);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, faqId.toString())).build();
cremertim marked this conversation as resolved.
Show resolved Hide resolved
cremertim marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* GET /courses/:courseId/faqs : get all the faqs of a course
*
* @param courseId the courseId of the course for which all faqs should be returned
* @return the ResponseEntity with status 200 (OK) and the list of faqs in body
*/
cremertim marked this conversation as resolved.
Show resolved Hide resolved
cremertim marked this conversation as resolved.
Show resolved Hide resolved
@GetMapping("courses/{courseId}/faqs")
@EnforceAtLeastStudent
public ResponseEntity<Set<FaqDTO>> getFaqForCourse(@PathVariable Long courseId) {
log.debug("REST request to get all Faqs for the course with id : {}", courseId);

Course course = courseRepository.findByIdElseThrow(courseId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null);
Set<Faq> faqs = faqRepository.findAllByCourseId(courseId);
Set<FaqDTO> faqDTOS = faqs.stream().map(FaqDTO::new).collect(Collectors.toSet());
return ResponseEntity.ok().body(faqDTOS);
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved

/**
* GET /courses/:courseId/faq-categories : get all the faq categories of a course
*
* @param courseId the courseId of the course for which all faq categories should be returned
* @return the ResponseEntity with status 200 (OK) and the list of faqs in body
*/
cremertim marked this conversation as resolved.
Show resolved Hide resolved
cremertim marked this conversation as resolved.
Show resolved Hide resolved
@GetMapping("courses/{courseId}/faq-categories")
@EnforceAtLeastStudent
public ResponseEntity<Set<String>> getFaqCategoriesForCourse(@PathVariable Long courseId) {
log.debug("REST request to get all Faq Categories for the course with id : {}", courseId);

Course course = courseRepository.findByIdElseThrow(courseId);
authCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.STUDENT, course, null);
Set<String> faqs = faqRepository.findAllCategoriesByCourseId(courseId);
cremertim marked this conversation as resolved.
Show resolved Hide resolved

return ResponseEntity.ok().body(faqs);
}
cremertim marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading