-
Notifications
You must be signed in to change notification settings - Fork 4
/
survey.go
44 lines (39 loc) · 1.12 KB
/
survey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package model
import (
"context"
"github.com/bcc-code/bcc-media-platform/backend/common"
"github.com/bcc-code/bcc-media-platform/backend/user"
"github.com/bcc-code/bcc-media-platform/backend/utils"
)
// SurveyQuestionFrom returns a gql question from a question
func SurveyQuestionFrom(ctx context.Context, i *common.SurveyQuestion) SurveyQuestion {
ginCtx, _ := utils.GinCtx(ctx)
languages := user.GetLanguagesFromCtx(ginCtx)
id := i.ID.String()
title := i.Title.Get(languages)
description := i.Description.GetValueOrNil(languages)
switch i.Type {
case "rating":
return SurveyRatingQuestion{
ID: id,
Title: title,
Description: description,
}
default:
return SurveyTextQuestion{
ID: id,
Title: title,
Description: description,
}
}
}
// SurveyFrom returns a gql survey from a survey
func SurveyFrom(ctx context.Context, i *common.Survey) *Survey {
ginCtx, _ := utils.GinCtx(ctx)
languages := user.GetLanguagesFromCtx(ginCtx)
return &Survey{
ID: i.ID.String(),
Title: i.Title.Get(languages),
Description: i.Description.GetValueOrNil(languages),
}
}