package com.example.controller;

import com.example.common.Result;
import com.example.entity.Adminstore;
import com.example.service.AdminStoreService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 店铺管理员
 */
@RestController
@RequestMapping("/adminstore")
public class AdminstoreController {

    @Resource
    private AdminStoreService adminstoreService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Adminstore adminstore) {
        adminstoreService.add(adminstore);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        adminstoreService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        adminstoreService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Adminstore adminstore) {
        adminstoreService.updateById(adminstore);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Adminstore adminstore = adminstoreService.selectById(id);
        return Result.success(adminstore);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Adminstore adminstore) {
        List<Adminstore> list = adminstoreService.selectAll(adminstore);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Adminstore adminstore,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Adminstore> page = adminstoreService.selectPage(adminstore, pageNum, pageSize);
        return Result.success(page);
    }



}