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

import com.viontech.storage.entity.Message;
import com.viontech.storage.model.CaptionSet;
import com.viontech.storage.service.CaptionSetService;
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() {
        List<CaptionSet> list = captionSetService.list();
        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();
    }

}