package com.ruoyi.applet.contoller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.model.domain.AppletPet;
import com.ruoyi.model.service.IAppletPetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "伴宠师-我的宠物相关")
@RestController
@RequestMapping("/applet/pet")
public class ApiAppletPetController {

    @Autowired
    private IAppletPetService appletPetService;

    //查询我的宠物列表
    @ApiOperation("查询我的宠物列表")
    @GetMapping("/list")
    public AjaxResult list(AppletPet appletPet)
    {

        List<AppletPet> list = appletPetService.selectAppletPetList(appletPet);

        return AjaxResult.success("查询成功",list);
    }


    @ApiOperation("根据宠物标识查询宠物信息")
    @GetMapping("/getByPetId")
    public AjaxResult getByPetId(AppletPet appletPet)
    {
        if(appletPet.getId() == null){
            return AjaxResult.error("标识不能为空");
        }
        AppletPet pet = appletPetService.selectAppletPetById(appletPet.getId());
        return AjaxResult.success("查询成功",pet);
    }







    //增加宠物
    @ApiOperation("增加宠物")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AppletPet appletPet)
    {
        int i = appletPetService.insertAppletPet(appletPet);
        return AjaxResult.success("增加成功");
    }


    //修改宠物信息
    @ApiOperation("修改宠物信息")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody AppletPet appletPet)
    {
        int i = appletPetService.updateAppletPet(appletPet);
        return AjaxResult.success("修改成功");
    }


    //删除宠物信息
    @ApiOperation("删除宠物信息")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody AppletPet appletPet)
    {
        int i = appletPetService.deleteAppletPetById(appletPet.getId());
        return AjaxResult.success("删除成功");
    }

}
