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

import jj.tech.paolu.repository.mybatis.dao.SysUrlsMapper;
import jj.tech.paolu.repository.mybatis.entity.SysUrls;
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/sysUrls")
public class SysUrlsController {

    @Autowired
    public SysUrlsMapper sysUrlsMapper;

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

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

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

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