12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package chat
- import (
- errors "confrontation-training/err"
- modelsChat "confrontation-training/models/chat"
- "confrontation-training/response"
- serviceChat "confrontation-training/service/chat"
- "fmt"
- "github.com/gin-gonic/gin"
- )
- type QuestionService struct {
- serviceChat.QuestionService
- }
- func GetQuestionService() *QuestionService {
- return &QuestionService{}
- }
- func (q *QuestionService) GetQuestion(c *gin.Context) {
- var id uint8
- if err := c.ShouldBind(&id); err != nil {
- fmt.Printf("参数绑定异常:%s", err.Error())
- response.Failed(errors.ParamInvalid, c)
- return
- }
- if id == 0 {
- id = 1
- }
- question, count := q.FindQuestionById(id)
- if count == 0 {
- response.Failed(errors.QuestionNotFound, c)
- } else {
- response.Success(errors.FindSuccess, question, c)
- }
- return
- }
- func (q *QuestionService) CreateQuestion(c *gin.Context) {
- var param modelsChat.CreateQuestion
- if err := c.ShouldBindJSON(¶m); err != nil {
- fmt.Printf("参数绑定异常:%s", err.Error())
- response.Failed(errors.ParamInvalid, c)
- return
- }
- question, count := q.CreateNewQuestion(param)
- if count == 0 {
- response.Failed(errors.QuestionCreateFailed, c)
- } else {
- response.Success(errors.FindSuccess, question, c)
- }
- return
- }
|