65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package quiz
|
|
|
|
import (
|
|
"resume-platform/internal/model"
|
|
"resume-platform/internal/repository"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type QuizService interface {
|
|
CreateQuizRecord(record *model.QuizRecord) error
|
|
GetQuizRecordsByResume(resumeRoute string) ([]*model.QuizRecord, error)
|
|
GetQuizRecord(id string) (*model.QuizRecord, error)
|
|
DeleteQuizRecord(id string) error
|
|
CreateFavoriteQuestion(fav *model.FavoriteQuestion) error
|
|
GetFavoriteQuestions(resumeRoute string, isFavorite, isCorrect *bool) ([]*model.FavoriteQuestion, error)
|
|
DeleteFavoriteQuestion(id string) error
|
|
ToggleFavorite(id string) error
|
|
}
|
|
|
|
type quizService struct {
|
|
repo repository.ResumeRepository
|
|
}
|
|
|
|
func NewQuizService(repo repository.ResumeRepository) QuizService {
|
|
return &quizService{repo: repo}
|
|
}
|
|
|
|
func (s *quizService) CreateQuizRecord(record *model.QuizRecord) error {
|
|
if record.ID == "" {
|
|
record.ID = uuid.New().String()
|
|
}
|
|
return s.repo.CreateQuizRecord(record)
|
|
}
|
|
|
|
func (s *quizService) GetQuizRecordsByResume(resumeRoute string) ([]*model.QuizRecord, error) {
|
|
return s.repo.GetQuizRecordsByResume(resumeRoute)
|
|
}
|
|
|
|
func (s *quizService) GetQuizRecord(id string) (*model.QuizRecord, error) {
|
|
return s.repo.GetQuizRecord(id)
|
|
}
|
|
|
|
func (s *quizService) DeleteQuizRecord(id string) error {
|
|
return s.repo.DeleteQuizRecord(id)
|
|
}
|
|
|
|
func (s *quizService) CreateFavoriteQuestion(fav *model.FavoriteQuestion) error {
|
|
if fav.ID == "" {
|
|
fav.ID = uuid.New().String()
|
|
}
|
|
return s.repo.CreateFavoriteQuestion(fav)
|
|
}
|
|
|
|
func (s *quizService) GetFavoriteQuestions(resumeRoute string, isFavorite, isCorrect *bool) ([]*model.FavoriteQuestion, error) {
|
|
return s.repo.GetFavoriteQuestions(resumeRoute, isFavorite, isCorrect)
|
|
}
|
|
|
|
func (s *quizService) DeleteFavoriteQuestion(id string) error {
|
|
return s.repo.DeleteFavoriteQuestion(id)
|
|
}
|
|
|
|
func (s *quizService) ToggleFavorite(id string) error {
|
|
return s.repo.ToggleFavorite(id)
|
|
} |