package com.xiaoniu.system.usedcar.controller;

import com.xiaoniu.common.core.resdata.Result;
import com.xiaoniu.common.core.resdata.RowsData;
import com.xiaoniu.system.usedcar.dto.EditUsedCarDTO;
import com.xiaoniu.system.usedcar.dto.UsedCarQueryDTO;
import com.xiaoniu.system.usedcar.service.ITbUsedCarService;
import com.xiaoniu.system.usedcar.vo.UsedCarDetailsVO;
import com.xiaoniu.system.usedcar.vo.UsedCarListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 二手车信息表 前端控制器
 * </p>
 *
 * @author haoxuyang
 * @since 2024-10-18 05:07:14
 */
@Tag(name = "二手车管理")
@RestController
@RequestMapping("/usedCar")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbUsedCarController {

    private final ITbUsedCarService tbUsedCarService;

    @Operation(summary = "二手车列表")
    @PostMapping("/list")
    public Result<RowsData<UsedCarListVO>> list(@RequestBody UsedCarQueryDTO dto) {
        return Result.success("查询成功", tbUsedCarService.usedCarList(dto));
    }

    @Operation(summary = "修改二手车")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody @Validated EditUsedCarDTO dto) {
        tbUsedCarService.editUsedCar(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "二手车详情")
    @GetMapping("/details")
    public Result<UsedCarDetailsVO> details(@RequestParam Long id) {
        return Result.success("查询成功", tbUsedCarService.details(id));
    }
}
