answerService.go 664 B

12345678910111213141516171819202122232425
  1. package chat
  2. import (
  3. "confrontation-training/global"
  4. "confrontation-training/models/chat"
  5. )
  6. type AnswerService struct {
  7. }
  8. func (a *AnswerService) CreateNewAnswer(param models.CreateAnswer) (models.Answer, int64) {
  9. answer := models.Answer{
  10. Answer: param.Answer,
  11. QuestionId: param.QuestionId,
  12. NextQuestionId: param.NextQuestionId,
  13. }
  14. count := global.Db.Create(&answer).RowsAffected
  15. return answer, count
  16. }
  17. func (a *AnswerService) FindAnswerByQuestionId(id uint8) ([]models.Answer, int64) {
  18. answerList := make([]models.Answer, 0)
  19. count := global.Db.Where(" question_id = ?", id).Find(&answerList).RowsAffected
  20. return answerList, count
  21. }