package api

import (
	"copter-train/db/model"
	"copter-train/db/repo"
	"copter-train/log"
	"errors"

	"github.com/gin-gonic/gin"
)

// 提交考核试题
func SubmitExeamLog(c *gin.Context, apictx *ApiSession) (interface{}, error) {
	db := c.Param("scope")
	if len(db) == 0 {
		return nil, errors.New("scope不能为空")
	}
	exeamLog := &model.ExeamLog{}
	err := c.ShouldBindJSON(exeamLog)
	if err != nil {
		log.Error(err)
		return nil, err
	}
	exeamLog.Uid = apictx.User.ID
	return repo.RepoAddDbDoc(apictx.CreateRepoCtx(), db, repo.CollectionExeamLog, exeamLog)
}

// 考核记录列表
// /exeamLog/list/:scope
func ExeamLogList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
	db := c.Param("scope")
	if len(db) == 0 {
		return nil, errors.New("scope不能为空")
	}
	page, size, query := UtilQueryPageSize(c)
	return repo.RepoDbPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
		Db:          db,
		CollectName: repo.CollectionExeamLog,
		Page:        page,
		Size:        size,
		Query:       query,
		// Sort:        bson.D{bson.E{Key: "sort", Value: 1}, bson.E{Key: "createTime", Value: 1}},
	})
}
