package com.izouma.nineth.web;

import com.izouma.nineth.domain.UserBankCard;
import com.izouma.nineth.dto.PageQuery;
import com.izouma.nineth.service.UserBankCardService;
import com.izouma.nineth.utils.excel.ExcelUtils;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/cardInfo")
@AllArgsConstructor
public class UserBankCardController extends BaseController {
    private UserBankCardService userBankCardService;

    /**
     * 银行卡信息列表
     * @param pageQuery
     * @return
     */
    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/all")
    public Page<UserBankCard> all(@RequestBody PageQuery pageQuery) {
        return userBankCardService.all(pageQuery);
    }

    @PostMapping("/excel")
    @ResponseBody
    public void excel(HttpServletResponse response, @RequestBody PageQuery pageQuery) throws IOException {
        List<UserBankCard> data = all(pageQuery).getContent();
        ExcelUtils.export(response, data);
    }
}

