This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
repository_handlers.go
77 lines (67 loc) · 1.81 KB
/
repository_handlers.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"github.com/datatogether/api/apiutil"
"github.com/datatogether/coverage/repositories"
"net/http"
)
// Concrete CoverateRequests instance
var RepositoryRequests = new(repositories.RepositoryRequests)
// func CoverageSummaryHandler(w http.ResponseWriter, r *http.Request) {
// args := &coverage.CoverageSummaryParams{
// Pattern: r.FormValue("pattern"),
// }
// res := &coverage.Summary{}
// err := CoverageRequests.Summary(args, res)
// if err != nil {
// log.Info(err.Error())
// apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
// return
// }
// apiutil.WriteResponse(w, res)
// }
// func GetCoverageTreeHandler(w http.ResponseWriter, r *http.Request) {
// args := &coverage.CoverageTreeParams{
// Pattern: r.FormValue("pattern"),
// }
// res := &tree.Node{}
// err := CoverageRequests.Tree(args, res)
// if err != nil {
// log.Info(err.Error())
// apiutil.WriteErrResponse(w, http.StatusInternalServerError, err)
// return
// }
// apiutil.WriteResponse(w, res)
// }
func ListRepositoriesHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "OPTIONS":
EmptyOkHandler(w, r)
case "GET":
ListRepositories(w, r)
default:
NotFoundHandler(w, r)
}
}
func ListRepositories(w http.ResponseWriter, r *http.Request) {
apiutil.WriteResponse(w, repositories.Repositories)
}
func RepositoriesHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "OPTIONS":
EmptyOkHandler(w, r)
case "GET":
GetRepository(w, r)
default:
NotFoundHandler(w, r)
}
}
func GetRepository(w http.ResponseWriter, r *http.Request) {
id := r.URL.Path[len("/repositories/"):]
for _, r := range repositories.Repositories {
if r.GetId() == id {
apiutil.WriteResponse(w, r)
return
}
}
NotFoundHandler(w, r)
}