package com.tcm.training.admin.points.controller; import com.tcm.training.admin.common.ApiResponse; import com.tcm.training.admin.points.service.PointsLedgerAppService; import com.tcm.training.admin.points.vo.PointsLedgerPageVO; import com.tcm.training.admin.points.vo.PointsRegionOptionVO; 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.LocalDateTime; import java.util.List; @Validated @RestController @RequestMapping({"/api/v1", "/api"}) public class PointsLedgerController { private final PointsLedgerAppService pointsLedgerAppService; public PointsLedgerController(PointsLedgerAppService pointsLedgerAppService) { this.pointsLedgerAppService = pointsLedgerAppService; } @GetMapping("/points-ledger") public ApiResponse page(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int pageSize, @RequestParam(required = false) String userPhone, @RequestParam(required = false) String regionCode, @RequestParam(required = false) String clinicName, @RequestParam(required = false) String incomeExpenseType, @RequestParam(required = false) String businessType, @RequestParam(required = false) String contentKeyword, @RequestParam(required = false) String referenceNo, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime operatedFrom, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime operatedTo) { return ApiResponse.ok(pointsLedgerAppService.page( page, pageSize, userPhone, regionCode, clinicName, incomeExpenseType, businessType, contentKeyword, referenceNo, operatedFrom, operatedTo )); } @GetMapping("/points-ledger/export") public void export(HttpServletResponse response, @RequestParam(required = false) String userPhone, @RequestParam(required = false) String regionCode, @RequestParam(required = false) String clinicName, @RequestParam(required = false) String incomeExpenseType, @RequestParam(required = false) String businessType, @RequestParam(required = false) String contentKeyword, @RequestParam(required = false) String referenceNo, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime operatedFrom, @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime operatedTo) throws IOException { pointsLedgerAppService.export(response, userPhone, regionCode, clinicName, incomeExpenseType, businessType, contentKeyword, referenceNo, operatedFrom, operatedTo); } @GetMapping("/points-ledger/regions") public ApiResponse> regionOptions() { return ApiResponse.ok(pointsLedgerAppService.regionOptions()); } }