package com.keao.edu.user.controller;

import com.keao.edu.common.controller.BaseController;
import com.keao.edu.common.entity.HttpResponseResult;
import com.keao.edu.common.page.PageInfo;
import com.keao.edu.common.tenant.TenantContextHolder;
import com.keao.edu.user.entity.ExamSong;
import com.keao.edu.user.page.ExamSongQueryInfo;
import com.keao.edu.user.service.ExamSongService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author Joburgess
 * @Date 2020.06.16
 */
@RestController
@RequestMapping("examSong")
@Api(tags = "曲库服务")
public class ExamSongController extends BaseController {

    @Autowired
    private ExamSongService examSongService;

    @ApiOperation("分页查询")
    @GetMapping(value = "/list")
    public HttpResponseResult<PageInfo<ExamSong>> getList(ExamSongQueryInfo queryInfo) {
        return succeed(examSongService.queryPage(queryInfo));
    }

    @ApiOperation("学生端分页查询考级曲库")
    @GetMapping(value = "/queryPage")
    public HttpResponseResult<PageInfo<ExamSong>> queryPage(ExamSongQueryInfo queryInfo) {
        return succeed(examSongService.querySongPage(queryInfo));
    }

    @ApiOperation("查询曲库详情")
    @ApiImplicitParam(name = "id", value = "机构ID", required = true, dataType = "Integer", paramType = "path")
    @GetMapping(value = "/query")
    public HttpResponseResult<ExamSong> query(Integer id) {
        return succeed(examSongService.get(id));
    }

    @ApiOperation("新增曲库")
    @PostMapping(value = "/add")
    public HttpResponseResult add(@RequestBody ExamSong examSong) {
        examSong.setTenantId(TenantContextHolder.getTenantId());
        examSongService.insert(examSong);
        return succeed();
    }

    @ApiOperation("更新曲库")
    @PostMapping(value = "/update")
    public HttpResponseResult update(@RequestBody ExamSong examSong) {
        examSong.setUpdateTime(new Date());
        examSongService.update(examSong);
        return succeed();
    }

    @ApiOperation("删除曲库")
    @PostMapping(value = "/del")
    public HttpResponseResult add(Integer id) {
        return succeed(examSongService.delete(id));
    }

    @ApiOperation("根据专业获取曲目")
    @GetMapping(value = "/getWithSubject")
    public HttpResponseResult<List<ExamSong>> getWithSubject(Integer subjectId){
        return succeed(examSongService.getWithSubject(subjectId));
    }
}
