-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
36 lines (29 loc) · 818 Bytes
/
get.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 apps
import (
"fmt"
"net/http"
"github.com/frohwerk/deputy-backend/internal/params"
"github.com/frohwerk/deputy-backend/internal/request"
"github.com/frohwerk/deputy-backend/pkg/httputil"
)
func (h *handler) Get(resp http.ResponseWriter, req *http.Request) {
id := fmt.Sprint(req.Context().Value(params.App))
envId, _ := request.StringParam(req.URL.Query(), "env")
before, _ := request.TimeParam(req.URL.Query(), "before")
fmt.Printf("AppsHandler.Get(%v, %v, %v)\n", id, envId, before)
var (
repo = Repository{h.DB}
result *App
err error
)
if before == nil {
result, err = repo.CurrentView(id, envId)
} else {
result, err = repo.History(id, envId, before)
}
if err != nil {
httputil.WriteErrorResponse(resp, err)
} else {
httputil.WriteJsonResponse(resp, result)
}
}