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

import jj.tech.paolu.repository.mybatis.dao.SysAdminRoleMapper;
import jj.tech.paolu.repository.mybatis.entity.SysAdminRole;
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/sysAdminRole")
public class SysAdminRoleController {

    @Autowired
    public SysAdminRoleMapper sysAdminRoleMapper;

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

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

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

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