package com.elephant.framework.galaxy.aroad.module.test.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.elephant.framework.galaxy.aroad.module.test.entity.Car;
import com.elephant.framework.galaxy.aroad.module.test.service.CarService;
import com.elephant.framework.galaxy.aroad.response.R;
import com.elephant.framework.galaxy.aroad.module.common.annotation.SysLog;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;


/**
 * 汽车表
 *
 * @author xuzhitu
 * @date 2019-03-05 17:24:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/test/car")
public class CarController extends BaseController  {

  private final CarService carService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param car 汽车表
   * @return
   */
  @GetMapping("/page")
  public R getCarPage(Page page, Car car) {
    return  new R<>(carService.page(page,Wrappers.query(car)));
  }


  /**
   * 通过id查询汽车表
   * @param carId id
   * @return R
   */
  @GetMapping("/{carId}")
  public R getById(@PathVariable("carId") Integer carId){
    return new R<>(carService.getById(carId));
  }

  /**
   * 新增汽车表
   * @param car 汽车表
   * @return R
   */
  @SysLog("新增汽车表")
  @PostMapping
  public R save(@RequestBody Car car){
    return new R<>(carService.save(car));
  }

  /**
   * 修改汽车表
   * @param car 汽车表
   * @return R
   */
  @SysLog("修改汽车表")
  @PutMapping
  public R updateById(@RequestBody Car car){
    return new R<>(carService.updateById(car));
  }

  /**
   * 通过id删除汽车表
   * @param carId id
   * @return R
   */
  @SysLog("删除汽车表")
  @DeleteMapping("/{carId}")
  public R removeById(@PathVariable Integer carId){
    return new R<>(carService.removeById(carId));
  }

}
