| 1 | package edu.ucsb.cs156.dining.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.dining.repositories.ReviewRepository; | |
| 4 | import edu.ucsb.cs156.dining.statuses.ModerationStatus; | |
| 5 | import io.swagger.v3.oas.annotations.Operation; | |
| 6 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 7 | import java.time.LocalDateTime; | |
| 8 | import lombok.extern.slf4j.Slf4j; | |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 11 | import org.springframework.web.bind.annotation.GetMapping; | |
| 12 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 13 | import org.springframework.web.bind.annotation.RestController; | |
| 14 | ||
| 15 | @Tag(name = "Statistics") | |
| 16 | @RequestMapping("/api/statistics") | |
| 17 | @RestController | |
| 18 | @Slf4j | |
| 19 | public class StatisticsController extends ApiController { | |
| 20 | ||
| 21 | @Autowired ReviewRepository reviewRepository; | |
| 22 | ||
| 23 | public record StatisticsSummary( | |
| 24 | long totalApprovedReviews, | |
| 25 | long totalMenuItemsReviewed, | |
| 26 | long totalCommonsCovered, | |
| 27 | LocalDateTime lastReviewDate) {} | |
| 28 | ||
| 29 | @Operation(summary = "Get a summary of review statistics") | |
| 30 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 31 | @GetMapping(value = "", produces = "application/json") | |
| 32 | public StatisticsSummary getSummary() { | |
| 33 |
1
1. getSummary : replaced return value with null for edu/ucsb/cs156/dining/controllers/StatisticsController::getSummary → KILLED |
return new StatisticsSummary( |
| 34 | reviewRepository.countByStatus(ModerationStatus.APPROVED), | |
| 35 | reviewRepository.countDistinctItemsByStatus(ModerationStatus.APPROVED), | |
| 36 | reviewRepository.countDistinctCommonsByStatus(ModerationStatus.APPROVED), | |
| 37 | reviewRepository.findMaxDateItemServedByStatus(ModerationStatus.APPROVED)); | |
| 38 | } | |
| 39 | } | |
Mutations | ||
| 33 |
1.1 |