Fully accepted statistic
This commit is contained in:
parent
6a0d425c37
commit
270e31f120
@ -1,10 +1,12 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Commision;
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
import com.plannaplan.exceptions.UserNotFoundException;
|
import com.plannaplan.exceptions.UserNotFoundException;
|
||||||
import com.plannaplan.models.UserApiResponse;
|
import com.plannaplan.models.UserApiResponse;
|
||||||
@ -29,6 +31,9 @@ public class UserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CommisionRepository comRepo;
|
private CommisionRepository comRepo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CommisionService comService;
|
||||||
|
|
||||||
public UserService() {
|
public UserService() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -193,4 +198,25 @@ public class UserService {
|
|||||||
return this.getAllStudents().size() - this.getAmmountOfUsersWithAssignedGroups();
|
return this.getAllStudents().size() - this.getAmmountOfUsersWithAssignedGroups();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ammount of how many users have full schedule accepted
|
||||||
|
*/
|
||||||
|
public Integer getAmmountOfUsersWithAcceptedSchedules() {
|
||||||
|
final List<User> students = this.getAllStudents();
|
||||||
|
Integer accepted = 0;
|
||||||
|
|
||||||
|
final Iterator<User> it = students.iterator();
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
final User user = it.next();
|
||||||
|
final Optional<Commision> com = this.comService.getNewestCommision(user);
|
||||||
|
if (com.isPresent() && user.getStudentRegisteredGrups().size() == com.get().getAssignments().size()) {
|
||||||
|
accepted += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return accepted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -66,4 +66,15 @@ public class StatisticsController {
|
|||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return amount of registered to some groups
|
||||||
|
*/
|
||||||
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
|
@GetMapping(path = "/users/accepted")
|
||||||
|
public ResponseEntity<StatisticSimpleNumberResponse> getAcceptedAmmounts() {
|
||||||
|
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||||
|
this.userService.getAmmountOfUsersWithAcceptedSchedules());
|
||||||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,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";
|
private static final String USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/noregistered";
|
||||||
|
private static final String USER_ACCEPTED_AMMOUNTS_ENDPOINT = "/api/v1/statistics/users/accepted";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@ -133,4 +134,39 @@ public class StatisticsControllerTest extends AbstractControllerTest {
|
|||||||
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
mockMvc.perform(get(USER_NO_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* USERS FULL ACCPTED TESTS */
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithWrongAccessAcceptedStudentsAmmount() throws Exception {
|
||||||
|
final String mail = "shouldFailWithWrongAccessAcceptedStudentsAmmount@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_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldOkGettingAcceptedStudentsAmmount() throws Exception {
|
||||||
|
final String mail = "shouldOkGettingAcceptedStudentsAmmount@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_ACCEPTED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithNoTokenAcceptedStudentsAmmount() throws Exception {
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(USER_ACCEPTED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user