backend/restservice/src/main/java/com/plannaplan/controllers/StatisticsController.java

103 lines
4.0 KiB
Java
Executable File

package com.plannaplan.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.plannaplan.App;
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
*/
@RestController
@CrossOrigin
@RequestMapping("/api/" + App.API_VERSION + "/statistics")
@Api(tags = {
"StatisticsController" }, value = "StatisticsController", description = "Statistics are meant to be used by deanery only so in every endpoint you need to provide DEANERY token.")
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<StatisticSimpleNumberResponse> getGroupsAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.groupService.getGroupsAmmount());
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* @return if tour was set
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/groups/full")
public ResponseEntity<StatisticSimpleNumberResponse> getGroupsFullAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.groupService.getFullgroupsAmmount());
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);
}
/**
* @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);
}
/**
* @return amount of students that have fully accepted schedules
*/
@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);
}
/**
* @return amount of students that have purtly accepted schedules
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/users/accepted/partly")
public ResponseEntity<StatisticSimpleNumberResponse> getAcceptedPartlyAmmounts() {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse(
this.userService.getAmmountOfUsersWithNoAcceptedSchedules());
return new ResponseEntity<>(response, HttpStatus.OK);
}
}