-
Notifications
You must be signed in to change notification settings - Fork 0
/
questions.go
44 lines (37 loc) · 1.14 KB
/
questions.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 actions
import (
"errors"
"github.com/YaleSpinup/proctor/libs/helpers"
"github.com/YaleSpinup/proctor/models"
"github.com/gobuffalo/buffalo"
)
// QuestionsGet gets a list of questions for a given campaign
// Optional "version" query param can specify a version, otherwise the latest one will be used
func QuestionsGet(c buffalo.Context) error {
questions := models.Questions{}
campaign := c.Param("campaign")
version := c.Param("version")
// determine latest version if none specified
if len(version) == 0 {
vl, err := S3.GetVersions(questions.Path(campaign))
if err != nil {
return errors.New("Unable to determine latest questions version")
}
version, err = helpers.LatestVersion(vl)
if err != nil {
return errors.New("Unable to determine latest questions version")
}
}
if err := S3.Load(&questions, questions.Object(campaign, version)); err != nil {
return err
}
// sanitize questions as to not show the data types in the answers
for k, v := range questions.List {
for x, y := range v.Answers {
y.Datatypes = nil
v.Answers[x] = y
}
questions.List[k] = v
}
return c.Render(200, r.JSON(questions))
}