package com.ningdatech.carapi.archives.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.archives.manage.PaperQuestionManage;
import com.ningdatech.carapi.archives.model.po.ReqQuestionListPO;
import com.ningdatech.carapi.archives.model.po.ReqSaveNewQuestionPO;
import com.ningdatech.carapi.archives.model.vo.ResQuestionDetailVO;
import com.ningdatech.carapi.archives.model.vo.ResQuestionListVO;
import com.ningdatech.log.annotation.WebLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LiuXinXin
 * @since 2022-10-11
 */
@RequestMapping("/api/v1/paper-question")
@Validated
@RestController
@Api(tags = "培训考题")
@RequiredArgsConstructor
public class PaperQuestionController {
    private final PaperQuestionManage paperQuestionManage;

    @PostMapping("/list")
    @ApiOperation("培训题库列表查询")
    public PageVo<ResQuestionListVO> questionList(@Valid @RequestBody ReqQuestionListPO po) {
        return paperQuestionManage.questionList(po);
    }

    @GetMapping("/detail/{questionId}")
    @ApiOperation("培训题库详情")
    public ResQuestionDetailVO questionDetail(@Valid @PathVariable("questionId") Long questionId) {
        return paperQuestionManage.questionDetail(questionId);
    }

    @PostMapping("/create")
    @ApiOperation("新增试题")
    @WebLog
    public void createNewQuestion(@Valid @RequestBody ReqSaveNewQuestionPO po) {
        paperQuestionManage.createNewQuestion(po);
    }

    @PostMapping("/save")
    @ApiOperation("保存试题")
    @WebLog
    public void saveQuestion(@Valid @RequestBody ReqSaveNewQuestionPO request) {
        paperQuestionManage.saveQuestion(request);
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除试题")
    @WebLog
    public void deleteQuestion(@PathVariable("id") Long id) {
        paperQuestionManage.deleteQuestion(id);
    }
}
