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

import jj.tech.paolu.repository.mybatis.dao.SysRoleMapper;
import jj.tech.paolu.repository.mybatis.entity.SysRole;
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/sysRole")
public class SysRoleController {

    @Autowired
    public SysRoleMapper sysRoleMapper;

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

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

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

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