63 lines
2.4 KiB
Java
63 lines
2.4 KiB
Java
package inc.sdt.controlcentermanagement.presentation;
|
|
|
|
import inc.sdt.controlcentermanagement.application.StatsService;
|
|
import inc.sdt.controlcentermanagement.infrastructure.amqp.ResourceMapping;
|
|
import inc.sdt.controlcentermanagement.presentation.support.CustomPageable;
|
|
import inc.sdt.controlcentermanagement.presentation.support.CustomPageableImpl;
|
|
import inc.sdt.controlcentermanagement.presentation.support.PageableResponse;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
public class StatsController {
|
|
|
|
private final Logger log = LoggerFactory.getLogger(StatsController.class);
|
|
private final StatsService statsService;
|
|
|
|
public StatsController(StatsService statsService) {
|
|
this.statsService = statsService;
|
|
}
|
|
|
|
|
|
@ResourceMapping(name = "Chambers_stats", method = "GET", uri = "/chambers/stats", description = "get chamber stats")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
@GetMapping("/chambers/stats")
|
|
public StatsResult chambers(
|
|
@RequestHeader("Authorization") String authorization
|
|
){
|
|
log.info("[chambers stats]");
|
|
|
|
List<StatsRecord> chamberStats = statsService.getChamberStats();
|
|
|
|
return new StatsResult(chamberStats);
|
|
}
|
|
|
|
@ResourceMapping(name = "Chambers_stats_detail", method = "GET", uri = "/chambers/stats/detail/{chamberNumber}", description = "get chamber stats detail")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
@GetMapping("/chambers/stats/detail/{chamberNumber}")
|
|
public PageableResponse<StatsDetailRecord> detail(
|
|
@RequestHeader("Authorization") String authorization,
|
|
@PathVariable String chamberNumber,
|
|
@RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
|
|
@RequestParam(value = "size", required = false, defaultValue = "20") Integer size
|
|
){
|
|
log.info("[chambers stats]");
|
|
Page<StatsDetailRecord> chamberStatsDetail = statsService.getChamberStatsDetail(Integer.max(0, page), (page >= 0 ? size : Integer.MAX_VALUE), chamberNumber);
|
|
|
|
if(chamberStatsDetail.hasContent()){
|
|
return PageableResponse.from(chamberStatsDetail, this::from);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private StatsDetailRecord from(StatsDetailRecord statsDetailRecord){
|
|
return statsDetailRecord;
|
|
}
|
|
}
|