package com.om.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.om.entity.po.Guide;
import com.om.service.IGuideService;
import com.om.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author henry-ong
 * @since 2024-02-27
 */
@RestController
@RequestMapping("/guide")
@Api(tags = "使用手册视频管理类")
public class GuideController {
  IGuideService guideService;

  @Value("${files.upload.path}")
  private String fileUploadPath;

  @Autowired
  public GuideController(IGuideService guideService) {
    this.guideService = guideService;
  }

  @ApiOperation("新增手册视频")
  @PostMapping("/save")
  public Result<Object> save(@RequestBody Guide guide) {
    return Result.succ(guideService.save(guide));
  }

  @ApiOperation("编辑手册视频接口")
  @PostMapping("/edit")
  public Result<Object> edit(@RequestBody Guide guide) {
    return Result.succ(guideService.saveOrUpdate(guide));
  }

  @ApiOperation("根据ID删除单个手册视频接口")
  @DeleteMapping("/delete/{id}")
  public Result<Object> delete(@PathVariable(name = "id") Integer id) {
    return Result.succ(guideService.removeById(id));
  }

  @ApiOperation("分页查询全部手册视频接口")
  @GetMapping("/page")
  public Result<Object> findPage(@RequestParam Integer pageNum,
                         @RequestParam Integer pageSize,
                         @RequestParam(defaultValue = "") String title) {
    return Result.succ(guideService.findGuide(new Page<>(pageNum, pageSize), title));
  }
}
