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

import jj.tech.paolu.repository.mybatis.dao.SysRoleUrlMapper;
import jj.tech.paolu.repository.mybatis.entity.SysRoleUrl;
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/sysRoleUrl")
public class SysRoleUrlController {

    @Autowired
    public SysRoleUrlMapper sysRoleUrlMapper;

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

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

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

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