package com.ym.mec.education.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.ym.mec.education.base.BaseResponse;
import com.ym.mec.education.base.PageResponse;
import com.ym.mec.education.enums.ReturnCodeEnum;
import com.ym.mec.education.req.ClassGroupReq;
import com.ym.mec.education.req.MusicGroupReq;
import com.ym.mec.education.service.IMusicGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author : chengp
 * @version V1.0
 * @Description: TODO
 * @date Date : 2019年09月25日 17:39
 */
@RestController
@RequestMapping("/api/musicGroup")
@DefaultProperties(defaultFallback = "defaultFallback")
@Slf4j
public class MusicGroupController {

    @Autowired
    private IMusicGroupService musicGroupService;


    /**
     * 服务降级处理
     *
     * @return
     */
    private BaseResponse defaultFallback() {
        BaseResponse response = new BaseResponse();
        response.setReturnCode(500);
        response.setMessage("太拥挤了, 请稍后再试!");
        return response;
    }

    /**
     * 乐团列表
     * @param req
     * @return
     */
    @PostMapping(value = "/groupList")
    public PageResponse groupList(@RequestBody MusicGroupReq req) {

        return musicGroupService.groupList(req);
    }

    /**
     * 乐团详情
     * @param groupId
     * @return
     */
    @GetMapping(value = "/groupDetail")
    public BaseResponse groupDetail(@RequestParam("groupId") Integer groupId) {

        BaseResponse baseResponse = new BaseResponse();
        if (groupId == null) {
            baseResponse.setReturnCode(ReturnCodeEnum.CODE_206.getCode());
            baseResponse.setMessage(ReturnCodeEnum.CODE_206.getValue());
            return baseResponse;
        }

        return musicGroupService.groupDetail(groupId);

    }

    /**
     * 班级列表
     * @param req
     * @return
     */
    @PostMapping(value = "/classGroupList")
    public PageResponse classGroupList(@RequestBody ClassGroupReq req){

        return musicGroupService.classGroupList(req);

    }


}
