package com.younike.store.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.dto.AjaxResult;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.StoreImage;
import com.younike.service.service.IStoreImageService;
import com.younike.common.core.page.TableResult;

/**
 * 门店图片Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/storeImage")
public class StoreImageController extends BaseController {
    @Autowired
    private IStoreImageService storeImageService;

    /**
     * 查询门店图片列表
     */
    @RequiresPermissions("image:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<StoreImage> page) {

        return storeImageService.page(page);
    }


    /**
     * 获取门店图片详细信息
     */
    @RequiresPermissions("image:query")
    @GetMapping(value = "/{storeImgId}")
    public APIResult getInfo(@PathVariable("storeImgId") String storeImgId) {
        return ResultGenerator.getSuccessResult(storeImageService.getById(storeImgId));
    }

    /**
     * 新增门店图片
     */
    @RequiresPermissions("image:add")
    @OpLog(title = "门店图片", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody StoreImage storeImage) {
        return ResultGenerator.getSuccessResult(storeImageService.save(storeImage));
    }

    /**
     * 修改门店图片
     */
    @RequiresPermissions("image:edit")
    @OpLog(title = "门店图片", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody StoreImage storeImage) {
        return ResultGenerator.getSuccessResult(storeImageService.updateById(storeImage));
    }

    /**
     * 删除门店图片
     */
    @RequiresPermissions("image:remove")
    @OpLog(title = "门店图片", type = BusinessType.DELETE)
    @DeleteMapping("/{storeImgIds}")
    public APIResult remove(@PathVariable List<String> storeImgIds) {
        return ResultGenerator.getSuccessResult(storeImageService.removeByIds(storeImgIds));
    }
}
