package com.tcm.training.admin.statistics.controller; import com.tcm.training.admin.common.ApiResponse; import com.tcm.training.admin.statistics.service.RevenueStatisticsAppService; import com.tcm.training.admin.statistics.vo.RevenueStatisticsVO; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.time.LocalDate; @Validated @RestController @RequestMapping({"/api/v1", "/api"}) public class RevenueStatisticsController { private final RevenueStatisticsAppService revenueStatisticsAppService; public RevenueStatisticsController(RevenueStatisticsAppService revenueStatisticsAppService) { this.revenueStatisticsAppService = revenueStatisticsAppService; } @GetMapping("/revenue-statistics") public ApiResponse statistics( @RequestParam(required = false) String type, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dateFrom, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dateTo) { return ApiResponse.ok(revenueStatisticsAppService.statistics(type, dateFrom, dateTo)); } @GetMapping("/revenue-statistics/export") public void export(HttpServletResponse response, @RequestParam(required = false) String type, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dateFrom, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate dateTo) throws IOException { revenueStatisticsAppService.export(response, type, dateFrom, dateTo); } }