package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.StudentCompetition;
import com.ym.mec.biz.dal.page.StudentCompetitionQueryInfo;
import com.ym.mec.biz.service.StudentCompetitionService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2020.11.10
 */
@RestController
@RequestMapping("studentCompetition")
@Api(tags = "长三角比赛服务")
public class StudentCompetitionController extends BaseController {

    @Autowired
    private StudentCompetitionService studentCompetitionService;

    @ApiOperation(value = "查询报名记录")
    @PostMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('studentCompetition/queryPage')")
    public HttpResponseResult<PageInfo<StudentCompetition>> queryPage(@RequestBody StudentCompetitionQueryInfo queryInfo){
        return succeed(studentCompetitionService.queryPage(queryInfo));
    }
    @ApiOperation(value = "更新报名记录")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('studentCompetition/update')")
    public HttpResponseResult update(@RequestBody StudentCompetition studentCompetition){
        if(Objects.isNull(studentCompetition.getId())){
            throw new BizException("请指定参赛作品");
        }
        studentCompetitionService.updateCompetition(studentCompetition);
        return succeed();
    }

}
