package cn.reghao.tnb.content.app.exam.controller;

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.common.db.KeyValue;
import cn.reghao.tnb.content.app.exam.model.vo.SubjectInfo;
import cn.reghao.tnb.content.app.exam.service.SubjectService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author reghao
 * @date 2024-08-24 23:23:28
 */
@Tag(name = "科目接口")
@RestController
@RequestMapping("/api/content/exam/subject")
public class SubjectController {
    private final SubjectService subjectService;

    public SubjectController(SubjectService subjectService) {
        this.subjectService = subjectService;
    }

    @Operation(summary = "获取科目列表", description = "N")
    @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getSubjects(@RequestParam(value = "pn", required = false) Integer pageNumber,
                              @RequestParam(value = "pz", required = false) Integer pageSize) {
        pageNumber = 1;
        pageSize = 10;
        PageList<SubjectInfo> pageList = subjectService.getSubjectInfos(pageNumber, pageSize);
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取科目 KV 列表", description = "N")
    @GetMapping(value = "/kv", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getSubjectKeyValue() {
        List<KeyValue> list = subjectService.getKeyValues();
        return WebResult.success(list);
    }
}
