package jj.tech.paolu.repository.mybatis.control;

import jj.tech.paolu.repository.mybatis.dao.SysResourceMapper;
import jj.tech.paolu.repository.mybatis.entity.SysResource;
import jj.tech.paolu.utils.IDHelp;
import jj.tech.paolu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("mybatis/sysResource")
public class SysResourceController {

    @Autowired
    public SysResourceMapper sysResourceMapper;

    @PostMapping("findById/{id}")
    public Object findById(@PathVariable("id") String id) {
        return R.SUCCESS(sysResourceMapper.selectByPrimaryKey(id).orElse(null));
    }

    @PostMapping("delete/{id}")
    public Object delete(@PathVariable("id") String id) {
        return R.SUCCESS(sysResourceMapper.deleteByPrimaryKey(id));
    }

    @PostMapping("save")
    public Object save(@RequestBody SysResource record) {
        record.setId(IDHelp.getInstance().nextId());
        return R.SUCCESS(sysResourceMapper.insertSelective(record));
    }

    @PostMapping("update")
    public Object update(@RequestBody SysResource record) {
        return R.SUCCESS(sysResourceMapper.updateByPrimaryKeySelective(record));
    }
}