优化题库代码
This commit is contained in:
@@ -24,6 +24,8 @@ func (c *ExamQuestionController) GetList() {
|
||||
tenantId, _ := c.Ctx.Input.GetData("tenantId").(int)
|
||||
keyword := c.GetString("keyword")
|
||||
typeStr := c.GetString("type")
|
||||
bankId, _ := c.GetInt64("bank_id", 0)
|
||||
|
||||
var qtype *int8
|
||||
if typeStr != "" {
|
||||
if iv, err := strconv.Atoi(typeStr); err == nil {
|
||||
@@ -31,12 +33,15 @@ func (c *ExamQuestionController) GetList() {
|
||||
qtype = &v
|
||||
}
|
||||
}
|
||||
|
||||
page, _ := c.GetInt("page", 1)
|
||||
pageSize, _ := c.GetInt("pageSize", 10)
|
||||
|
||||
list, total, err := services.GetExamQuestions(services.QuestionListParams{
|
||||
TenantId: tenantId,
|
||||
Keyword: keyword,
|
||||
QuestionType: qtype,
|
||||
BankId: bankId,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
})
|
||||
@@ -45,7 +50,7 @@ func (c *ExamQuestionController) GetList() {
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
// build minimal DTO to limit fields in response
|
||||
|
||||
items := make([]map[string]interface{}, 0, len(list))
|
||||
for _, q := range list {
|
||||
if q == nil {
|
||||
@@ -59,6 +64,7 @@ func (c *ExamQuestionController) GetList() {
|
||||
"score": q.Score,
|
||||
})
|
||||
}
|
||||
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
@@ -101,6 +107,7 @@ func (c *ExamQuestionController) Create() {
|
||||
QuestionAnalysis string `json:"question_analysis"`
|
||||
Options []map[string]string `json:"options"`
|
||||
Answer interface{} `json:"answer"`
|
||||
BankId int64 `json:"bank_id"`
|
||||
}
|
||||
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &payload); err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 1, "message": "请求参数错误: " + err.Error(), "data": nil}
|
||||
@@ -115,6 +122,9 @@ func (c *ExamQuestionController) Create() {
|
||||
Score: payload.Score,
|
||||
Status: 1,
|
||||
}
|
||||
if payload.BankId > 0 {
|
||||
q.BankId = payload.BankId
|
||||
}
|
||||
var opts []models.ExamQuestionOption
|
||||
for _, o := range payload.Options {
|
||||
opts = append(opts, models.ExamQuestionOption{OptionLabel: o["label"], OptionContent: o["content"]})
|
||||
@@ -149,6 +159,7 @@ func (c *ExamQuestionController) Create() {
|
||||
func (c *ExamQuestionController) BatchCreate() {
|
||||
tenantId, _ := c.Ctx.Input.GetData("tenantId").(int)
|
||||
var payload struct {
|
||||
BankId int64 `json:"bank_id"`
|
||||
Items []struct {
|
||||
QuestionTitle string `json:"question_title"`
|
||||
QuestionType int8 `json:"question_type"`
|
||||
@@ -182,6 +193,9 @@ func (c *ExamQuestionController) BatchCreate() {
|
||||
Score: item.Score,
|
||||
Status: 1,
|
||||
}
|
||||
if payload.BankId > 0 {
|
||||
q.BankId = payload.BankId
|
||||
}
|
||||
var opts []models.ExamQuestionOption
|
||||
for _, o := range item.Options {
|
||||
opts = append(opts, models.ExamQuestionOption{OptionLabel: o["label"], OptionContent: o["content"]})
|
||||
@@ -251,6 +265,7 @@ func (c *ExamQuestionController) Update() {
|
||||
QuestionAnalysis string `json:"question_analysis"`
|
||||
Options []map[string]string `json:"options"`
|
||||
Answer interface{} `json:"answer"`
|
||||
BankId int64 `json:"bank_id"`
|
||||
}
|
||||
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &payload); err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 1, "message": "请求参数错误: " + err.Error(), "data": nil}
|
||||
@@ -258,6 +273,9 @@ func (c *ExamQuestionController) Update() {
|
||||
return
|
||||
}
|
||||
q := &models.ExamQuestion{QuestionType: payload.QuestionType, QuestionTitle: payload.QuestionTitle, QuestionAnalysis: payload.QuestionAnalysis, Score: payload.Score}
|
||||
if payload.BankId > 0 {
|
||||
q.BankId = payload.BankId
|
||||
}
|
||||
var opts []models.ExamQuestionOption
|
||||
for _, o := range payload.Options {
|
||||
opts = append(opts, models.ExamQuestionOption{OptionLabel: o["label"], OptionContent: o["content"]})
|
||||
|
||||
Reference in New Issue
Block a user