2021-01-21 15:05:45 +01:00
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 ;
2021-01-21 15:41:56 +01:00
import com.plannaplan.responses.models.StatisticSimpleNumberResponse ;
2021-01-21 15:05:45 +01:00
import com.plannaplan.services.GroupService ;
2021-01-21 15:41:56 +01:00
import com.plannaplan.services.UserService ;
2021-01-21 15:05:45 +01:00
/ * *
* 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 ;
2021-01-21 15:41:56 +01:00
@Autowired
private UserService userService ;
2021-01-21 15:05:45 +01:00
/ * *
* @return if tour was set
* /
@PreAuthorize ( " hasRole('ROLE_DEANERY') " )
@GetMapping ( path = " /groups/created " )
2021-01-21 15:41:56 +01:00
public ResponseEntity < StatisticSimpleNumberResponse > getGroupsAmmounts ( ) {
final StatisticSimpleNumberResponse response = new StatisticSimpleNumberResponse (
2021-01-21 15:05:45 +01:00
this . groupService . getGroupsAmmount ( ) ) ;
return new ResponseEntity < > ( response , HttpStatus . OK ) ;
}
2021-01-21 16:22:14 +01:00
/ * *
* @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 ) ;
}
2021-01-21 15:41:56 +01:00
/ * *
* @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 ) ;
}
2021-01-21 15:50:20 +01:00
/ * *
* @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 ) ;
}
2021-01-21 16:08:53 +01:00
/ * *
2021-01-21 16:15:01 +01:00
* @return amount of students that have fully accepted schedules
2021-01-21 16:08:53 +01:00
* /
@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 ) ;
}
2021-01-21 16:15:01 +01:00
/ * *
* @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 ) ;
}
2021-01-21 15:05:45 +01:00
}