178 lines
7.0 KiB
Go
178 lines
7.0 KiB
Go
package questions
|
|
|
|
import (
|
|
"Yimaru-Backend/internal/domain"
|
|
"Yimaru-Backend/internal/ports"
|
|
"context"
|
|
)
|
|
|
|
type Service struct {
|
|
questionStore ports.QuestionStore
|
|
}
|
|
|
|
func NewService(questionStore ports.QuestionStore) *Service {
|
|
return &Service{
|
|
questionStore: questionStore,
|
|
}
|
|
}
|
|
|
|
// Questions
|
|
|
|
func (s *Service) CreateQuestion(ctx context.Context, input domain.CreateQuestionInput) (domain.Question, error) {
|
|
return s.questionStore.CreateQuestion(ctx, input)
|
|
}
|
|
|
|
func (s *Service) GetQuestionByID(ctx context.Context, id int64) (domain.Question, error) {
|
|
return s.questionStore.GetQuestionByID(ctx, id)
|
|
}
|
|
|
|
func (s *Service) GetQuestionWithDetails(ctx context.Context, id int64) (domain.QuestionWithDetails, error) {
|
|
return s.questionStore.GetQuestionWithDetails(ctx, id)
|
|
}
|
|
|
|
func (s *Service) ListQuestions(ctx context.Context, questionType, difficulty, status *string, limit, offset int32) ([]domain.Question, int64, error) {
|
|
return s.questionStore.ListQuestions(ctx, questionType, difficulty, status, limit, offset)
|
|
}
|
|
|
|
func (s *Service) SearchQuestions(ctx context.Context, query string, limit, offset int32) ([]domain.Question, int64, error) {
|
|
return s.questionStore.SearchQuestions(ctx, query, limit, offset)
|
|
}
|
|
|
|
func (s *Service) UpdateQuestion(ctx context.Context, id int64, input domain.CreateQuestionInput) error {
|
|
return s.questionStore.UpdateQuestion(ctx, id, input)
|
|
}
|
|
|
|
func (s *Service) ArchiveQuestion(ctx context.Context, id int64) error {
|
|
return s.questionStore.ArchiveQuestion(ctx, id)
|
|
}
|
|
|
|
func (s *Service) DeleteQuestion(ctx context.Context, id int64) error {
|
|
return s.questionStore.DeleteQuestion(ctx, id)
|
|
}
|
|
|
|
// Question Options
|
|
|
|
func (s *Service) CreateQuestionOption(ctx context.Context, questionID int64, optionText string, optionOrder *int32, isCorrect bool) (domain.QuestionOption, error) {
|
|
return s.questionStore.CreateQuestionOption(ctx, questionID, optionText, optionOrder, isCorrect)
|
|
}
|
|
|
|
func (s *Service) GetOptionsByQuestionID(ctx context.Context, questionID int64) ([]domain.QuestionOption, error) {
|
|
return s.questionStore.GetOptionsByQuestionID(ctx, questionID)
|
|
}
|
|
|
|
func (s *Service) UpdateQuestionOption(ctx context.Context, id int64, optionText *string, optionOrder *int32, isCorrect *bool) error {
|
|
return s.questionStore.UpdateQuestionOption(ctx, id, optionText, optionOrder, isCorrect)
|
|
}
|
|
|
|
func (s *Service) DeleteQuestionOption(ctx context.Context, id int64) error {
|
|
return s.questionStore.DeleteQuestionOption(ctx, id)
|
|
}
|
|
|
|
func (s *Service) DeleteOptionsByQuestionID(ctx context.Context, questionID int64) error {
|
|
return s.questionStore.DeleteOptionsByQuestionID(ctx, questionID)
|
|
}
|
|
|
|
// Question Short Answers
|
|
|
|
func (s *Service) CreateQuestionShortAnswer(ctx context.Context, questionID int64, acceptableAnswer string, matchType *string) (domain.QuestionShortAnswer, error) {
|
|
return s.questionStore.CreateQuestionShortAnswer(ctx, questionID, acceptableAnswer, matchType)
|
|
}
|
|
|
|
func (s *Service) GetShortAnswersByQuestionID(ctx context.Context, questionID int64) ([]domain.QuestionShortAnswer, error) {
|
|
return s.questionStore.GetShortAnswersByQuestionID(ctx, questionID)
|
|
}
|
|
|
|
func (s *Service) UpdateQuestionShortAnswer(ctx context.Context, id int64, acceptableAnswer, matchType *string) error {
|
|
return s.questionStore.UpdateQuestionShortAnswer(ctx, id, acceptableAnswer, matchType)
|
|
}
|
|
|
|
func (s *Service) DeleteQuestionShortAnswer(ctx context.Context, id int64) error {
|
|
return s.questionStore.DeleteQuestionShortAnswer(ctx, id)
|
|
}
|
|
|
|
func (s *Service) DeleteShortAnswersByQuestionID(ctx context.Context, questionID int64) error {
|
|
return s.questionStore.DeleteShortAnswersByQuestionID(ctx, questionID)
|
|
}
|
|
|
|
// Question Sets
|
|
|
|
func (s *Service) CreateQuestionSet(ctx context.Context, input domain.CreateQuestionSetInput) (domain.QuestionSet, error) {
|
|
return s.questionStore.CreateQuestionSet(ctx, input)
|
|
}
|
|
|
|
func (s *Service) GetQuestionSetByID(ctx context.Context, id int64) (domain.QuestionSet, error) {
|
|
return s.questionStore.GetQuestionSetByID(ctx, id)
|
|
}
|
|
|
|
func (s *Service) GetQuestionSetsByOwner(ctx context.Context, ownerType string, ownerID int64) ([]domain.QuestionSet, error) {
|
|
return s.questionStore.GetQuestionSetsByOwner(ctx, ownerType, ownerID)
|
|
}
|
|
|
|
func (s *Service) GetQuestionSetsByType(ctx context.Context, setType string, limit, offset int32) ([]domain.QuestionSet, int64, error) {
|
|
return s.questionStore.GetQuestionSetsByType(ctx, setType, limit, offset)
|
|
}
|
|
|
|
func (s *Service) GetPublishedQuestionSetsByOwner(ctx context.Context, ownerType string, ownerID int64) ([]domain.QuestionSet, error) {
|
|
return s.questionStore.GetPublishedQuestionSetsByOwner(ctx, ownerType, ownerID)
|
|
}
|
|
|
|
func (s *Service) GetInitialAssessmentSet(ctx context.Context) (domain.QuestionSet, error) {
|
|
return s.questionStore.GetInitialAssessmentSet(ctx)
|
|
}
|
|
|
|
func (s *Service) UpdateQuestionSet(ctx context.Context, id int64, input domain.CreateQuestionSetInput) error {
|
|
return s.questionStore.UpdateQuestionSet(ctx, id, input)
|
|
}
|
|
|
|
func (s *Service) ArchiveQuestionSet(ctx context.Context, id int64) error {
|
|
return s.questionStore.ArchiveQuestionSet(ctx, id)
|
|
}
|
|
|
|
func (s *Service) DeleteQuestionSet(ctx context.Context, id int64) error {
|
|
return s.questionStore.DeleteQuestionSet(ctx, id)
|
|
}
|
|
|
|
// Question Set Items
|
|
|
|
func (s *Service) AddQuestionToSet(ctx context.Context, setID, questionID int64, displayOrder *int32) (domain.QuestionSetItem, error) {
|
|
return s.questionStore.AddQuestionToSet(ctx, setID, questionID, displayOrder)
|
|
}
|
|
|
|
func (s *Service) GetQuestionSetItems(ctx context.Context, setID int64) ([]domain.QuestionSetItemWithQuestion, error) {
|
|
return s.questionStore.GetQuestionSetItems(ctx, setID)
|
|
}
|
|
|
|
func (s *Service) GetPublishedQuestionsInSet(ctx context.Context, setID int64) ([]domain.QuestionSetItemWithQuestion, error) {
|
|
return s.questionStore.GetPublishedQuestionsInSet(ctx, setID)
|
|
}
|
|
|
|
func (s *Service) RemoveQuestionFromSet(ctx context.Context, setID, questionID int64) error {
|
|
return s.questionStore.RemoveQuestionFromSet(ctx, setID, questionID)
|
|
}
|
|
|
|
func (s *Service) UpdateQuestionOrder(ctx context.Context, setID, questionID int64, displayOrder int32) error {
|
|
return s.questionStore.UpdateQuestionOrder(ctx, setID, questionID, displayOrder)
|
|
}
|
|
|
|
func (s *Service) CountQuestionsInSet(ctx context.Context, setID int64) (int64, error) {
|
|
return s.questionStore.CountQuestionsInSet(ctx, setID)
|
|
}
|
|
|
|
func (s *Service) GetQuestionSetsContainingQuestion(ctx context.Context, questionID int64) ([]domain.QuestionSet, error) {
|
|
return s.questionStore.GetQuestionSetsContainingQuestion(ctx, questionID)
|
|
}
|
|
|
|
// User Personas in Question Sets
|
|
|
|
func (s *Service) AddUserPersonaToQuestionSet(ctx context.Context, questionSetID, userID int64, displayOrder int32) error {
|
|
return s.questionStore.AddUserPersonaToQuestionSet(ctx, questionSetID, userID, displayOrder)
|
|
}
|
|
|
|
func (s *Service) RemoveUserPersonaFromQuestionSet(ctx context.Context, questionSetID, userID int64) error {
|
|
return s.questionStore.RemoveUserPersonaFromQuestionSet(ctx, questionSetID, userID)
|
|
}
|
|
|
|
func (s *Service) GetUserPersonasByQuestionSetID(ctx context.Context, questionSetID int64) ([]domain.UserPersona, error) {
|
|
return s.questionStore.GetUserPersonasByQuestionSetID(ctx, questionSetID)
|
|
}
|