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.IndexBanner;
import com.younike.service.service.IIndexBannerService;
import com.younike.common.core.page.TableResult;

/**
 * 首页轮播Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/indexBanner")
public class IndexBannerController extends BaseController {
    @Autowired
    private IIndexBannerService indexBannerService;

    /**
     * 查询首页轮播列表
     */
    @RequiresPermissions("banner:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<IndexBanner> page) {

        return indexBannerService.page(page);
    }


    /**
     * 获取首页轮播详细信息
     */
    @RequiresPermissions("banner:query")
    @GetMapping(value = "/{indexBannerId}")
    public APIResult getInfo(@PathVariable("indexBannerId") String indexBannerId) {
        return ResultGenerator.getSuccessResult(indexBannerService.getById(indexBannerId));
    }

    /**
     * 新增首页轮播
     */
    @RequiresPermissions("banner:add")
    @OpLog(title = "首页轮播", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody IndexBanner indexBanner) {
        return ResultGenerator.getSuccessResult(indexBannerService.save(indexBanner));
    }

    /**
     * 修改首页轮播
     */
    @RequiresPermissions("banner:edit")
    @OpLog(title = "首页轮播", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody IndexBanner indexBanner) {
        return ResultGenerator.getSuccessResult(indexBannerService.updateById(indexBanner));
    }

    /**
     * 删除首页轮播
     */
    @RequiresPermissions("banner:remove")
    @OpLog(title = "首页轮播", type = BusinessType.DELETE)
    @DeleteMapping("/{indexBannerIds}")
    public APIResult remove(@PathVariable List<String> indexBannerIds) {
        return ResultGenerator.getSuccessResult(indexBannerService.removeByIds(indexBannerIds));
    }
}
