package cn.ysk.cashier.controller;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
import cn.ysk.cashier.dto.TbPlatformDictDto;
import cn.ysk.cashier.dto.TbPlatformDictQueryCriteria;
import cn.ysk.cashier.pojo.TbPlatformDict;
import cn.ysk.cashier.service.TbPlatformDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @website https://eladmin.vip
 * @author ww
 * @date 2024-03-29
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "资源管理")
@RequestMapping("/api/tbPlatformDict")
public class TbPlatformDictController {

    private final TbPlatformDictService tbPlatformDictService;

    @GetMapping
    @ApiOperation("查询新字典")
    @AnonymousGetMapping
    public ResponseEntity<Object> queryTbPlatformDict(TbPlatformDictQueryCriteria criteria) {
        return new ResponseEntity<>(tbPlatformDictService.queryAllPage(criteria), HttpStatus.OK);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过Id查询新字典")
    public TbPlatformDictDto queryTbOrderInfo(@PathVariable("id") Integer id){
        return tbPlatformDictService.findById(id);
    }
    @PostMapping
    @ApiOperation("新增新字典")
    public ResponseEntity<Object> createTbPlatformDict(@Validated @RequestBody TbPlatformDict resources){
        return new ResponseEntity<>(tbPlatformDictService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @ApiOperation("修改新字典")
    public ResponseEntity<Object> updateTbPlatformDict(@Validated @RequestBody TbPlatformDict resources){
        tbPlatformDictService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @ApiOperation("删除新字典")
    public ResponseEntity<Object> deleteTbPlatformDict(@RequestBody Integer[] ids) {
        tbPlatformDictService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
