Students registered satistics
This commit is contained in:
parent
7045844653
commit
676070c8c7
@ -10,15 +10,13 @@ import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* CommisionRepository.getUsers:
|
||||
* Return list of:
|
||||
* SELECT * FROM Commision WHERE owner_id = i .
|
||||
* CommisionRepository.getUsers: Return list of: SELECT * FROM Commision WHERE
|
||||
* owner_id = i .
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*
|
||||
* CommisionRepository.getNewestCommision
|
||||
* Return list of:
|
||||
* SELECT * FROM Commision WHERE owner_id = i Order by commisionDate desc.
|
||||
* CommisionRepository.getNewestCommision Return list of: SELECT * FROM
|
||||
* Commision WHERE owner_id = i Order by commisionDate desc.
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*/
|
||||
@ -30,4 +28,10 @@ public interface CommisionRepository extends JpaRepository<Commision, Long> {
|
||||
@Query("FROM Commision WHERE owner_id = ?1 order by commisionDate desc")
|
||||
List<Commision> getNewestCommision(@Param("owner_id") Long id);
|
||||
|
||||
/**
|
||||
* @return ammount of uniqe users that have a commision placed on first array
|
||||
* element
|
||||
*/
|
||||
@Query("SELECT COUNT(DISTINCT owner_id) AS count FROM Commision")
|
||||
Object[] getUsersAssigned();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.stream.Collectors;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.models.UserApiResponse;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
import com.plannaplan.repositories.UserRepository;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
@ -25,6 +26,9 @@ public class UserService {
|
||||
@Autowired
|
||||
private UsosApiService service;
|
||||
|
||||
@Autowired
|
||||
private CommisionRepository comRepo;
|
||||
|
||||
public UserService() {
|
||||
super();
|
||||
}
|
||||
@ -169,4 +173,17 @@ public class UserService {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount of how many users created an assignment
|
||||
*/
|
||||
public int getAmmountOfUsersWithAssignedGroups() {
|
||||
int response = 0;
|
||||
|
||||
final Object dbResponse = this.comRepo.getUsersAssigned()[0];
|
||||
if (dbResponse != null) {
|
||||
response = ((Long) dbResponse).intValue();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,8 +12,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.responses.models.StatisticCreatedGroupsResponse;
|
||||
import com.plannaplan.responses.models.StatisticSimpleNumberResponse;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.UserService;
|
||||
|
||||
/**
|
||||
* Rest controller to enpoint that help deveopler test the app
|
||||
@ -29,15 +30,29 @@ public class StatisticsController {
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* @return if tour was set
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/groups/created")
|
||||
public ResponseEntity<StatisticCreatedGroupsResponse> getGroupsAmmounts() {
|
||||
final StatisticCreatedGroupsResponse response = new StatisticCreatedGroupsResponse(
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getGroupsAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.groupService.getGroupsAmmount());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return amount of registered to some groups
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping(path = "/users/registered")
|
||||
public ResponseEntity<StatisticSimpleNumberResponse> getCommisionsAmmounts() {
|
||||
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
|
||||
this.userService.getAmmountOfUsersWithAssignedGroups());
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
/**
|
||||
* Api response for created groups statistics
|
||||
*/
|
||||
public class StatisticCreatedGroupsResponse {
|
||||
private Integer ammount;
|
||||
|
||||
/**
|
||||
* @param ammount created groups
|
||||
*/
|
||||
public StatisticCreatedGroupsResponse(Integer ammount) {
|
||||
this.ammount = ammount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount of created groups
|
||||
*/
|
||||
public Integer getAmmount() {
|
||||
return ammount;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
/**
|
||||
* Simple api response for number statistics
|
||||
*/
|
||||
public class StatisticSimpleNumberResponse {
|
||||
private Integer ammount;
|
||||
|
||||
/**
|
||||
* @param ammount to return as api response
|
||||
*/
|
||||
public StatisticSimpleNumberResponse(Integer ammount) {
|
||||
this.ammount = ammount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ammount
|
||||
*/
|
||||
public Integer getAmmount() {
|
||||
return ammount;
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ import com.plannaplan.types.UserRoles;
|
||||
public class StatisticsControllerTest extends AbstractControllerTest {
|
||||
|
||||
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";
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@ -61,4 +62,39 @@ public class StatisticsControllerTest extends AbstractControllerTest {
|
||||
mockMvc.perform(get(GROUP_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
/* USERS ASSIGNED TESTS */
|
||||
|
||||
@Test
|
||||
public void shouldFailWithWrongAccesRegisteredStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldFailWithWrongAccesRegisteredStudentsAmmount@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_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOkGettingRegisteredStudentsAmmount() throws Exception {
|
||||
final String mail = "shouldOkGettingRegisteredStudentsAmmount@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_ASSIGNED_AMMOUNTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoTokenRegisteredStudentsAmmount() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(USER_ASSIGNED_AMMOUNTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user