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.ExamLocation;
import com.keao.edu.user.entity.ExamSong;
import com.keao.edu.user.page.ExamLocationQueryInfo;
import com.keao.edu.user.service.ExamLocationService;
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;

/**
 * @Author Joburgess
 * @Date 2020.06.16
 */
@RestController
@RequestMapping("examLocation")
@Api(tags = "线下考点服务")
public class ExamLocationController extends BaseController {

    @Autowired
    private ExamLocationService examLocationService;

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

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

    @ApiOperation("新增考点")
    @PostMapping(value = "/add")
    public HttpResponseResult add(ExamLocation examLocation) {
        examLocation.setTenantId(TenantContextHolder.getTenantId().toString());
        examLocationService.insert(examLocation);
        return succeed();
    }

    @ApiOperation("更新考点")
    @PostMapping(value = "/update")
    public HttpResponseResult update(ExamLocation examLocation) {
        examLocation.setUpdateTime(new Date());
        examLocationService.update(examLocation);
        return succeed();
    }

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

}
