package com.yonge.cooleshow.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.yonge.toolset.mybatis.support.PageUtil;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.base.util.StringUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import com.yonge.cooleshow.biz.dal.vo.StudentCourseHomeworkVo;
import com.yonge.cooleshow.biz.dal.dto.search.StudentCourseHomeworkSearch;
import com.yonge.cooleshow.biz.dal.entity.StudentCourseHomework;
import com.yonge.cooleshow.biz.dal.service.StudentCourseHomeworkService;

@RestController
@RequestMapping("/studentCourseHomework")
@Api(value = "学生课程作业", tags = "学生课程作业")
public class StudentCourseHomeworkController extends BaseController {

    @Autowired
    private StudentCourseHomeworkService studentCourseHomeworkService;

	/**
     * 查询单条
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情", notes = "传入id")
    public HttpResponseResult<StudentCourseHomeworkVo> detail(@PathVariable("id") Long id) {
    	return succeed(studentCourseHomeworkService.detail(id));
	}
    
    /**
     * 查询分页
     */
    @PostMapping("/page")
    @ApiOperation(value = "查询分页", notes = "传入studentCourseHomeworkSearch")
    public HttpResponseResult<PageInfo<StudentCourseHomeworkVo>> page(@RequestBody StudentCourseHomeworkSearch query) {
		IPage<StudentCourseHomeworkVo> pages = studentCourseHomeworkService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
	}
    
    /**
	 * 新增
	 */
	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入studentCourseHomework")
	public HttpResponseResult save(@Valid @RequestBody StudentCourseHomework studentCourseHomework) {
    	return status(studentCourseHomeworkService.save(studentCourseHomework));
	}
    
    /**
	 * 修改
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "传入studentCourseHomework")
	public HttpResponseResult update(@Valid @RequestBody StudentCourseHomework studentCourseHomework) {
        return status(studentCourseHomeworkService.updateById(studentCourseHomework));
	}
    
    /**
	 * 新增或修改
	 */
    @PostMapping("/submit")
    @ApiOperation(value = "新增或修改", notes = "传入studentCourseHomework")
	public HttpResponseResult submit(@Valid @RequestBody StudentCourseHomework studentCourseHomework) {
        return status(studentCourseHomeworkService.saveOrUpdate(studentCourseHomework));
    }

 	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids")
	public HttpResponseResult remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        if (StringUtil.isEmpty(ids)) {
			return failed("参数不能为空");
		}
		return status(studentCourseHomeworkService.removeByIds(StringUtil.toLongList(ids)));
	}
}