Skip to content
Snippets Groups Projects
Commit 66d30274 authored by Chris Lemaire's avatar Chris Lemaire
Browse files

Change the get by person and module to return one

Only one group can exist for a specific Person/Module combination,
therefore we should return only one group from this endpoint.
parent ce513e44
No related branches found
No related tags found
No related merge requests found
Pipeline #342342 passed
......@@ -26,6 +26,7 @@ import nl.tudelft.labracore.dto.helper.GroupGenerateDTO;
import nl.tudelft.labracore.dto.patch.StudentGroupPatchDTO;
import nl.tudelft.labracore.dto.view.other.StudentGroupShortDetailsDTO;
import nl.tudelft.labracore.dto.view.other.StudentGroupSummaryDTO;
import nl.tudelft.labracore.dto.view.structured.details.StudentGroupDetailsDTO;
import nl.tudelft.labracore.dto.view.structured.summary.RoleSummaryDTO;
import nl.tudelft.labracore.repository.StudentGroupRepository;
import nl.tudelft.labracore.service.RoleService;
......@@ -278,10 +279,10 @@ public class StudentGroupController {
*/
@GetMapping("/by-person-and-module/{personId}/{moduleId}")
@PreAuthorize("hasAuthority('STUDENT_GROUP_READ')")
public List<StudentGroupSummaryDTO> getGroupsForPersonAndModule(@PathVariable Long personId,
public StudentGroupDetailsDTO getGroupsForPersonAndModule(@PathVariable Long personId,
@PathVariable Long moduleId) {
return View.convert(sgr.findAllByModuleAndPersonIn(personId, moduleId),
StudentGroupSummaryDTO.class);
return View.convert(sgr.findByModuleAndPersonIn(personId, moduleId),
StudentGroupDetailsDTO.class);
}
}
......@@ -98,12 +98,14 @@ public interface StudentGroupRepository
/**
* @param personId The id of the person to lookup.
* @param moduleId The id of the module to lookup.
* @return All groups that contain the given person in the given module.
* @return The group that contains the given person in the given module.
*/
default List<StudentGroup> findAllByModuleAndPersonIn(Long personId, Long moduleId) {
default StudentGroup findByModuleAndPersonIn(Long personId, Long moduleId) {
BooleanExpression q = studentGroup.module.id.eq(moduleId).and(
studentGroup.members.any().id.personId.eq(personId));
return findAll(q);
return findOne(q)
.orElseThrow(() -> new ResourceNotFoundException(
"StudentGroup was not found for person, module: " + personId + ", " + moduleId));
}
}
......@@ -33,6 +33,7 @@ import nl.tudelft.labracore.dto.create.StudentGroupCreateDTO;
import nl.tudelft.labracore.dto.helper.GroupGenerateDTO;
import nl.tudelft.labracore.dto.patch.StudentGroupPatchDTO;
import nl.tudelft.labracore.dto.view.other.StudentGroupSummaryDTO;
import nl.tudelft.labracore.dto.view.structured.details.StudentGroupDetailsDTO;
import nl.tudelft.labracore.model.Course;
import nl.tudelft.labracore.model.Person;
import nl.tudelft.labracore.model.StudentGroup;
......@@ -173,13 +174,12 @@ class StudentGroupControllerIntegrationTest extends RestControllerTest {
@Test
@WithUserDetails("All-access Key")
void getGroupsForPersonAndModuleWorks() throws Exception {
void getGroupForPersonAndModuleWorks() throws Exception {
mockMvc.perform(
get("/api/studentGroup/by-person-and-module/{p}/{m}", p.getId(), sg1.getModule().getId()))
.andExpect(status().isOk())
.andExpect(jsonContent(StudentGroupSummaryList.class)
.test(l -> assertThat(l).containsExactlyInAnyOrder(
View.convert(sg1, StudentGroupSummaryDTO.class))));
.andExpect(jsonContent(StudentGroupDetailsDTO.class)
.isEqualTo(View.convert(sg1, StudentGroupDetailsDTO.class)));
}
@WithUserDetails("No-access Key")
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment