package com.ruoyi.web.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.bst.driver.domain.Driver;
import com.ruoyi.bst.driver.service.DriverConverter;
import com.ruoyi.bst.driver.service.DriverService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.ValidGroup;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/app/driver")
public class AppDriverController extends BaseController {

    @Autowired
    private DriverService driverService;

    @Autowired
    private DriverConverter driverConverter;

    @ApiOperation("添加驾驶证认证")
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Driver data) {
        data.setUserId(getUserId());
        Driver driver = driverConverter.toPoByAppCreate(data);
        return toAjax(driverService.insertDriver(driver));
    }

    @ApiOperation("查询最后一次认证数据")
    @GetMapping("/last")
    public AjaxResult last() {
        return success(driverService.selectLastOneByUserId(getUserId()));
    }

}
