|
@@ -58,7 +58,7 @@ func (s *QuizStore) Create(quiz *models.Quiz) (*models.Quiz, error) {
|
|
|
answers = append(answers, storedAnswer)
|
|
|
}
|
|
|
|
|
|
- tags := make([]*models.Tag, 0)
|
|
|
+ tags := make([]string, 0)
|
|
|
|
|
|
q, err := s.Store.Create(&models.Quiz{
|
|
|
Meta: quiz.Meta,
|
|
@@ -96,7 +96,7 @@ func (s *QuizStore) Update(quiz *models.Quiz, id string) (*models.Quiz, error) {
|
|
|
answers = append(answers, storedAnswer)
|
|
|
}
|
|
|
|
|
|
- tags := make([]*models.Tag, 0)
|
|
|
+ tags := make([]string, 0)
|
|
|
|
|
|
q, err := s.Store.Update(&models.Quiz{
|
|
|
Question: parseTags[*models.Question](&tags, question)[0],
|
|
@@ -112,49 +112,7 @@ func (s *QuizStore) Update(quiz *models.Quiz, id string) (*models.Quiz, error) {
|
|
|
return q, nil
|
|
|
}
|
|
|
|
|
|
-func (s *QuizStore) FilterInCollection(collection *models.Collection, filter map[string]string) []*models.Quiz {
|
|
|
- quizzes := s.ReadAll()
|
|
|
-
|
|
|
- if filter == nil {
|
|
|
- return quizzes
|
|
|
- }
|
|
|
-
|
|
|
- tagsValue := filter["tags"]
|
|
|
-
|
|
|
- if tagsValue == "" || len(tagsValue) == 0 {
|
|
|
- return quizzes
|
|
|
- }
|
|
|
-
|
|
|
- fTags := strings.Split(tagsValue, ",")
|
|
|
-
|
|
|
- filteredQuizzes := s.Filter(quizzes, func(q *models.Quiz) bool {
|
|
|
- count := 0
|
|
|
- for _, qTag := range q.Tags {
|
|
|
- if s.isTagInFilter(qTag, fTags) {
|
|
|
- count++
|
|
|
- }
|
|
|
- }
|
|
|
- if count == len(fTags) {
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
- })
|
|
|
-
|
|
|
- collection.Quizzes = filteredQuizzes
|
|
|
-
|
|
|
- return collection.Quizzes
|
|
|
-}
|
|
|
-
|
|
|
-func (s *QuizStore) isTagInFilter(tag *models.Tag, fTags []string) bool {
|
|
|
- for _, t := range fTags {
|
|
|
- if tag.Name == strings.TrimSpace(t) {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
-}
|
|
|
-
|
|
|
-func parseTags[T fmt.Stringer](tags *[]*models.Tag, entities ...T) []T {
|
|
|
+func parseTags[T fmt.Stringer](tags *[]string, entities ...T) []T {
|
|
|
for _, entity := range entities {
|
|
|
// Trim the following chars
|
|
|
trimChars := "*:.,/\\@()[]{}<>"
|
|
@@ -168,7 +126,7 @@ func parseTags[T fmt.Stringer](tags *[]*models.Tag, entities ...T) []T {
|
|
|
// Check if the tag already exists in the tags slice
|
|
|
exists := false
|
|
|
for _, tag := range *tags {
|
|
|
- if tag.Name == word {
|
|
|
+ if tag == word {
|
|
|
exists = true
|
|
|
break
|
|
|
}
|
|
@@ -176,7 +134,7 @@ func parseTags[T fmt.Stringer](tags *[]*models.Tag, entities ...T) []T {
|
|
|
|
|
|
// If the tag does not exist in the tags slice, add it
|
|
|
if !exists {
|
|
|
- *tags = append(*tags, &models.Tag{Name: strings.TrimRight(word, trimChars)})
|
|
|
+ *tags = append(*tags, strings.TrimRight(word, trimChars))
|
|
|
}
|
|
|
}
|
|
|
}
|