package com.hc.web.controller.browser.app;

import com.hc.business.dto.PaperCommitDTO;
import com.hc.business.service.PaperService;
import com.hc.business.service.UserTestHistoryService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 用户考试记录表(UserTestHistory)表控制层
 *
 * @author java
 * @since 2020-12-07 11:28:22
 */

@RestController
@RequestMapping("/new/api/app/userTestHistory")
public class AppUserTestHistoryController {

    /**
     * 服务对象
     */
    private final UserTestHistoryService userTestHistoryService;

    private final PaperService paperService;

    public AppUserTestHistoryController(UserTestHistoryService userTestHistoryService,
                                        PaperService paperService) {
        this.userTestHistoryService = userTestHistoryService;
        this.paperService = paperService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 UserTestHistory", response = Result.class)
    public Result selectAppUserTestHistory(@PathVariable("id") Integer id) {
        return Result.success(this.userTestHistoryService.queryById(id));
    }

    @PostMapping("/commit")
    @ApiOperation(value = "提交试卷,获取成绩", response = Result.class)
    public Result paperAppCommit(@Valid @RequestBody PaperCommitDTO paperCommitDTO) {
        return paperService.paperCommit(paperCommitDTO);
    }

    @GetMapping("/max")
    @ApiOperation(value = "获取用户当前最高成绩", response = Result.class)
    public Result selectAppUserMaxTestHistory(@ApiParam(value = "用户id") @RequestParam Integer userId,
                                              @RequestParam Integer classId) {
        return Result.success(userTestHistoryService.queryMaxScore(userId, classId));
    }


}