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.page.QueryInfo;
import com.keao.edu.common.tenant.TenantContextHolder;
import com.keao.edu.user.entity.MusicTheory;
import com.keao.edu.user.service.MusicTheoryService;
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.*;

/**
 * @Author wangyp
 * @Date 2020/6/27 9:17
 * @Description TODO
 */
@RestController
@RequestMapping("musicTheory")
@Api(tags = "乐理信息")
public class MusicTheoryController extends BaseController {

    @Autowired
    private MusicTheoryService musicTheoryService;

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

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

    @ApiOperation("新增乐理")
    @PostMapping(value = "/add")
    public HttpResponseResult add(MusicTheory musicTheory) {
        musicTheory.setTenantId(TenantContextHolder.getTenantId());
        musicTheoryService.addMusicTheory(musicTheory);
        return succeed();
    }

    @ApiOperation("更新乐理")
    @PostMapping(value = "/update")
    public HttpResponseResult update(MusicTheory musicTheory) {
        musicTheoryService.update(musicTheory);
        return succeed();
    }

    @ApiOperation("删除乐理")
    @PostMapping(value = "/del/{id}")
    public HttpResponseResult add(@PathVariable("id") Integer id) {
        return succeed(musicTheoryService.delete(id));
    }


}
