package com.xxfc.member.controller;

import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.msg.TableResultResponse;
import com.xxfc.member.service.MemberInfoService;
import com.xxfc.member.vo.MemberInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("member/info")
public class MemberInfoController {

    @Autowired
    MemberInfoService memberInfoService;

    @PostMapping("")
    public BaseResponse insert(@RequestBody MemberInfoVo memberInfoVo) {
        memberInfoService.insert(memberInfoVo);
        return new BaseResponse();
    }

    @DeleteMapping("/{id}")
    public BaseResponse delete(@PathVariable("id") Integer id) {
        memberInfoService.deleteById(id);
        return new BaseResponse();
    }

    @GetMapping("/{id}")
    public ObjectRestResponse<MemberInfoVo> get(@PathVariable("id") Integer id) {
        return new ObjectRestResponse<MemberInfoVo>().data(memberInfoService.selectById(id));
    }

    @GetMapping("/all")
    public TableResultResponse<MemberInfoVo> getAll(String name, Integer page, Integer limit) {
        return new TableResultResponse<MemberInfoVo>().data(memberInfoService.selectAll(name, page, limit));
    }

    @PutMapping("")
    public BaseResponse update(@RequestBody MemberInfoVo memberInfoVo) {
        memberInfoService.updateSelectiveById(memberInfoVo);
        return new BaseResponse();
    }

}
