Added non registered statistic

This commit is contained in:
Filip Izydorczyk 2021-01-21 15:50:20 +01:00
parent 676070c8c7
commit 6a0d425c37
3 changed files with 54 additions and 0 deletions

View File

@ -186,4 +186,11 @@ public class UserService {
return response; return response;
} }
/**
* @return ammount of how many users haven't created an assignment yet
*/
public Integer getAmmountOfUsersWithNoAssignedGroups() {
return this.getAllStudents().size() - this.getAmmountOfUsersWithAssignedGroups();
}
} }

View File

@ -55,4 +55,15 @@ public class StatisticsController {
return new ResponseEntity<>(response, HttpStatus.OK); return new ResponseEntity<>(response, HttpStatus.OK);
} }
/**
* @return amount of students not registered to any groups
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/users/noregistered")
public ResponseEntity<StatisticSimpleNumberResponse> getNonCommisionsAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.userService.getAmmountOfUsersWithNoAssignedGroups());
return new ResponseEntity<>(response, HttpStatus.OK);
}
} }

View File

@ -24,6 +24,7 @@ public class StatisticsControllerTest extends AbstractControllerTest {
private static final String GROUP_AMMOUNTS_ENDPOINT = "/api/v1/statistics/groups/created"; private static final String GROUP_AMMOUNTS_ENDPOINT = "/api/v1/statistics/groups/created";
private static final String USER_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/registered"; private static final String USER_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/registered";
private static final String USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/noregistered";
@Autowired @Autowired
private UserService userService; private UserService userService;
@ -97,4 +98,39 @@ public class StatisticsControllerTest extends AbstractControllerTest {
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError()); mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
} }
/* USERS NO ASSIGNED TESTS */
@Test
public void shouldFailWithWrongAccesNoRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldFailWithWrongAccesNoRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.TEST_USER));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().is4xxClientError());
}
@Test
public void shouldOkGettingNoRegisteredStudentsAmmount() throws Exception {
final String mail = "shouldOkGettingNoRegisteredStudentsAmmount@StatisticsController.test";
final User usr = this.userService.save(new User(null, null, mail, UserRoles.DEANERY));
final String token = this.userService.login(usr).getToken();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
.andExpect(status().isOk());
}
@Test
public void shouldFailWithNoTokenNoRegisteredStudentsAmmount() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
}
} }