CaptionSetController.java 1.98 KB
package com.viontech.storage.controller;

import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.viontech.storage.entity.Message;
import com.viontech.storage.model.CaptionSet;
import com.viontech.storage.service.CaptionSetService;
import com.viontech.storage.vo.CaptionSetVo;
import org.h2.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * .
 *
 * @author 谢明辉
 * @date 2021/11/8
 */

@RestController
@RequestMapping("/captionSets")
public class CaptionSetController {

    @Resource
    private CaptionSetService captionSetService;

    @GetMapping("/{id}")
    public Message<CaptionSet> getById(@PathVariable("id") Long id) {
        CaptionSet byId = captionSetService.getById(id);
        return Message.success(byId);
    }

    @GetMapping
    public Message<List<CaptionSet>> listAll(CaptionSetVo captionSetVo) {
        QueryChainWrapper<CaptionSet> query = captionSetService.query();
        if (!StringUtils.isNullOrEmpty(captionSetVo.getNameLike())) {
            query.like("name", captionSetVo.getNameLike());
        }
        List<CaptionSet> list = captionSetService.list(query.getWrapper());
        return Message.success(list);
    }

    @PostMapping
    public Message<CaptionSet> add(@RequestBody CaptionSet captionSet) {
        boolean save = captionSetService.save(captionSet);
        if (save) {
            return Message.success(captionSet);
        } else {
            return Message.error();
        }
    }

    @PutMapping("/{id}")
    public Message<CaptionSet> updateById(@PathVariable Long id, @RequestBody CaptionSet captionSet) {
        captionSet.setId(id);
        boolean b = captionSetService.updateById(captionSet);
        return Message.success(captionSet);
    }

    @DeleteMapping("/{id}")
    public Message<CaptionSet> deleteById(@PathVariable Long id) {
        boolean b = captionSetService.removeById(id);
        return Message.success();
    }

}