2023-12-27 17:31:49 +09:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"learnsteam/cslms-api/internal/models"
|
|
|
|
"learnsteam/cslms-api/internal/repositories"
|
|
|
|
)
|
|
|
|
|
|
|
|
type userQuizService struct {
|
|
|
|
repository repositories.UserQuizRepository
|
|
|
|
quizRepository repositories.QuizRepository
|
|
|
|
}
|
|
|
|
|
|
|
|
type UserQuizService interface {
|
|
|
|
List(int64, int, int) (*[]models.UserQuiz, error)
|
|
|
|
Total(int64) (int64, error)
|
|
|
|
|
|
|
|
Find(int64) (*models.UserQuiz, error)
|
|
|
|
Create(*models.UserQuiz) (*models.UserQuiz, error)
|
|
|
|
Insert([]models.UserQuiz) ([]models.UserQuiz, error)
|
|
|
|
Update(*models.UserQuiz) (*models.UserQuiz, error)
|
|
|
|
Delete(int64) error
|
|
|
|
Generate(int64, *models.UserQuizPaper) ([]models.UserQuiz, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewUserQuizService(repository repositories.UserQuizRepository, quizRepository repositories.QuizRepository) UserQuizService {
|
|
|
|
return &userQuizService{
|
|
|
|
repository: repository,
|
|
|
|
quizRepository: quizRepository,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) List(user_quiz_paper_id int64, page int, limit int) (*[]models.UserQuiz, error) {
|
|
|
|
return s.repository.List(user_quiz_paper_id, page, limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) Total(user_quiz_paper_id int64) (int64, error) {
|
|
|
|
return s.repository.Total(user_quiz_paper_id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) Find(id int64) (*models.UserQuiz, error) {
|
|
|
|
return s.repository.Find(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) Create(quiz *models.UserQuiz) (*models.UserQuiz, error) {
|
|
|
|
result, err := s.repository.Create(quiz)
|
|
|
|
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) Insert(items []models.UserQuiz) ([]models.UserQuiz, error) {
|
|
|
|
result, err := s.repository.Insert(items)
|
|
|
|
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) Update(quiz *models.UserQuiz) (*models.UserQuiz, error) {
|
|
|
|
result, err := s.repository.Update(quiz)
|
|
|
|
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) Delete(id int64) error {
|
|
|
|
err := s.repository.Delete(id)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *userQuizService) Generate(quiz_paper_id int64, userQuizPaper *models.UserQuizPaper) ([]models.UserQuiz, error) {
|
|
|
|
var userQuizzes []models.UserQuiz
|
|
|
|
quizzes, err := s.quizRepository.List(quiz_paper_id, 1, 1000)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, quiz := range *quizzes {
|
|
|
|
userQuiz := models.UserQuiz{
|
|
|
|
GUID: quiz.GUID,
|
|
|
|
CenterID: quiz.CenterID,
|
|
|
|
UserQuizPaperID: userQuizPaper.ID,
|
|
|
|
UserID: userQuizPaper.UserID,
|
|
|
|
No: quiz.No,
|
2023-12-29 00:27:12 +09:00
|
|
|
QuizID: quiz.ID,
|
2023-12-27 17:31:49 +09:00
|
|
|
QuestionType: quiz.QuestionType,
|
|
|
|
Question: quiz.Question,
|
|
|
|
Content: quiz.Content,
|
2024-02-19 22:43:31 +09:00
|
|
|
Status: "ready",
|
2023-12-27 17:31:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(userQuiz.Content)
|
|
|
|
// fmt.Println(userQuiz.Answer)
|
|
|
|
userQuizzes = append(userQuizzes, userQuiz)
|
|
|
|
}
|
|
|
|
|
|
|
|
return userQuizzes, nil
|
|
|
|
}
|