package com.jiayue.ipfcst.fileupload.controller;

import com.jiayue.ipfcst.aop.SaveValidate;
import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.UploadFileCode;
import com.jiayue.ipfcst.fileupload.service.UploadFileCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("uploadFileCode")
public class UploadFileCodeController {
  @Autowired
  private UploadFileCodeService uploadFileCodeService;


  public UploadFileCodeController(UploadFileCodeService uploadFileCodeService){
    this.uploadFileCodeService = uploadFileCodeService;
  }

  /**
   * 获取文件类型code数据
   *
   * @return
   */
  @GetMapping
  public ResponseVO getAll(){
    List<UploadFileCode> uploadFileCodes = uploadFileCodeService.get();
    return ResponseVO.success(uploadFileCodes);
  }

  /**
   * 修改文件类型code数据
   *
   * @param uploadFileCode
   * @return
   */
  @PostMapping
  @SaveValidate
  public ResponseVO update(@RequestBody UploadFileCode uploadFileCode){
    return ResponseVO.success(uploadFileCodeService.save(uploadFileCode));
  }

  /**
   * 新增文件类型code数据
   * @param uploadFileCode
   *
   * @return
   */
  @PutMapping
  @SaveValidate
  public ResponseVO add(@RequestBody UploadFileCode uploadFileCode){
    return ResponseVO.success(uploadFileCodeService.save(uploadFileCode));
  }

  /**
   * 删除文件类型code数据
   *
   * @param id
   * @return
   */
  @DeleteMapping("/{id}")
  @SaveValidate
  public ResponseVO delete(@PathVariable Integer id){
    UploadFileCode uploadFileCode = new UploadFileCode();
    uploadFileCode.setId(id);
    uploadFileCodeService.delete(uploadFileCode);
    return ResponseVO.success(1);
  }
}
