-
Notifications
You must be signed in to change notification settings - Fork 0
/
risklevels.go
36 lines (30 loc) · 951 Bytes
/
risklevels.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
package actions
import (
"errors"
"log"
"github.com/YaleSpinup/proctor/libs/helpers"
"github.com/YaleSpinup/proctor/models"
"github.com/gobuffalo/buffalo"
)
// RiskLevelsGet gets a list of supported risk levels and data types
// Optional "version" query param can specify a version, otherwise the latest one will be used
func RiskLevelsGet(c buffalo.Context) error {
risklevels := models.RiskLevels{}
version := c.Param("version")
// determine latest version if none specified
if len(version) == 0 {
vl, err := S3.GetVersions(risklevels.Path())
if err != nil {
return errors.New("Unable to determine latest risklevels version")
}
version, err = helpers.LatestVersion(vl)
if err != nil {
return errors.New("Unable to determine latest risklevels version")
}
}
if err := S3.Load(&risklevels, risklevels.Object(version)); err != nil {
return err
}
log.Println(risklevels)
return c.Render(200, r.JSON(risklevels))
}