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 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:05:45 +01:00
}