-
Notifications
You must be signed in to change notification settings - Fork 3
/
issues.go
73 lines (56 loc) · 1.53 KB
/
issues.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
/*
Copyright 2020 Adevinta
*/
package api
import (
"net/http"
"github.com/labstack/echo/v4"
)
// ListIssues returns a paginated JSON containing issues.
func (api *API) ListIssues(c echo.Context) error {
filter, err := api.parseFilter(c)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
issues, pagination, err := api.storage.ListIssues(filter)
if err != nil {
return err
}
return response(c, http.StatusOK, issues, "issues", pagination)
}
// IssuesSummary returns a summary of affected assets by issue.
func (api *API) IssuesSummary(c echo.Context) error {
filter, err := api.parseFilter(c)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
issues, pagination, err := api.storage.IssuesSummary(filter)
if err != nil {
return err
}
return response(c, http.StatusOK, issues, "issues", pagination)
}
// GetIssue returns a JSON containing a specific issue.
func (api *API) GetIssue(c echo.Context) error {
id := c.Param("id")
issue, err := api.storage.GetIssue(id)
if err != nil {
return err
}
if issue.ID == "" {
return echo.NewHTTPError(http.StatusNotFound)
}
return response(c, http.StatusOK, issue, "issue")
}
// GetIssueMTTR returns a JSON containing the mean time to remediate an issue.
func (api *API) GetIssueMTTR(c echo.Context) error {
id := c.Param("id")
mttr, err := api.storage.GetIssueMTTR(id)
if err != nil {
return err
}
if mttr == 0 {
return echo.NewHTTPError(http.StatusNotFound)
}
return response(c, http.StatusOK, mttr, "mttr")
}