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

44 lines
1.5 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.StatisticCreatedGroupsResponse;
import com.plannaplan.services.GroupService;
/**
* 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;
/**
* @return if tour was set
*/
@PreAuthorize("hasRole('ROLE_DEANERY')")
@GetMapping(path = "/groups/created")
public ResponseEntity<StatisticCreatedGroupsResponse> getGroupsAmmounts() {
final StatisticCreatedGroupsResponse response = new StatisticCreatedGroupsResponse(
this.groupService.getGroupsAmmount());
return new ResponseEntity<>(response, HttpStatus.OK);
}
}