forked from goffee/goffee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
41 lines (31 loc) · 943 Bytes
/
results.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
package controllers
import (
"net/http"
"strconv"
"github.com/gophergala/goffee/Godeps/_workspace/src/github.com/zenazn/goji/web" // ResultsIndex renders results JSON
"github.com/gophergala/goffee/web/helpers"
"github.com/gophergala/goffee/web/render"
)
func ResultsIndex(c web.C, w http.ResponseWriter, req *http.Request) {
user, err := helpers.CurrentUser(c)
if err != nil {
renderError(c, w, req,"You need to re-authenticate", http.StatusUnauthorized)
return
}
checkId, err := strconv.ParseInt(c.URLParams["check_id"], 10, 64)
if err != nil {
renderError(c, w, req,"Check not found", http.StatusNotFound)
return
}
check, err := user.Check(checkId)
if err != nil {
renderError(c, w, req,"Check not found", http.StatusNotFound)
return
}
results, err := check.Results()
if err != nil {
renderError(c, w, req,"No results found", http.StatusNotFound)
return
}
render.JSON(w, http.StatusOK, results)
}