package com.keyware.shandan.mark.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keyware.shandan.common.entity.Result;
import com.keyware.shandan.mark.pojo.MarkType;
import com.keyware.shandan.mark.services.MarkTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author GuoXin
 * @date 2022-05-13
 */
@RestController
@RequestMapping("/mark/api/type")
public class MarkTypeController {

    @Autowired
    private MarkTypeService typeService;

    @GetMapping("/page")
    public Result<Page<MarkType>> page(Page<MarkType> page, MarkType type) {
        return Result.of(typeService.page(page, new QueryWrapper<>(type)));
    }

    @GetMapping("/list")
    public Result<List<MarkType>> list(){
        return Result.of(typeService.list());
    }

    @PostMapping("/save")
    public Result<Object> save(MarkType type) {
        return Result.of(typeService.saveOrUpdate(type));
    }

    @DeleteMapping("/{id}")
    public Result<Object> delete(@PathVariable String id) {
        Assert.hasText(id, "id不能为空");
        List<String> ids = Arrays.asList(id.split(","));
        return Result.of(typeService.removeByIds(ids));
    }
}
