package org.springblade.modules.martial.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.martial.pojo.entity.MartialBanner;
import org.springblade.modules.martial.service.IMartialBannerService;
import org.springframework.web.bind.annotation.*;

/**
 * 轮播图 控制器
 *
 * @author BladeX
 */
@RestController
@AllArgsConstructor
@RequestMapping("/martial/banner")
@Tag(name = "轮播图管理", description = "轮播图接口")
public class MartialBannerController extends BladeController {

	private final IMartialBannerService bannerService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@Operation(summary = "详情", description = "传入ID")
	public R<MartialBanner> detail(@RequestParam Long id) {
		MartialBanner detail = bannerService.getById(id);
		return R.data(detail);
	}

	/**
	 * 分页列表
	 */
	@GetMapping("/list")
	@Operation(summary = "分页列表", description = "分页查询")
	public R<IPage<MartialBanner>> list(MartialBanner banner, Query query) {
		IPage<MartialBanner> pages = bannerService.page(Condition.getPage(query), Condition.getQueryWrapper(banner));
		return R.data(pages);
	}

	/**
	 * 新增或修改
	 */
	@PostMapping("/submit")
	@Operation(summary = "新增或修改", description = "传入实体")
	public R submit(@RequestBody MartialBanner banner) {
		return R.status(bannerService.saveOrUpdate(banner));
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@Operation(summary = "删除", description = "传入ID")
	public R remove(@RequestParam String ids) {
		return R.status(bannerService.removeByIds(Func.toLongList(ids)));
	}

}
