-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsubmittal.go
148 lines (135 loc) · 4.96 KB
/
submittal.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package handler
import (
"net/http"
"strings"
"github.com/USACE/instrumentation-api/api/internal/db"
"github.com/USACE/instrumentation-api/api/internal/httperr"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)
// ListProjectSubmittals godoc
//
// @Summary lists all submittals for a project
// @Tags submittal
// @Produce json
// @Param project_id path string true "project uuid" Format(uuid)
// @Param missing query bool false "filter by missing projects only"
// @Success 200 {array} db.VSubmittal
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /projects/{project_id}/submittals [get]
func (h *ApiHandler) ListProjectSubmittals(c echo.Context) error {
pID, err := uuid.Parse(c.Param("project_id"))
if err != nil {
return httperr.MalformedID(err)
}
showMissing := strings.ToLower(c.QueryParam("missing")) == "true"
subs, err := h.DBService.SubmittalListForProject(c.Request().Context(), db.SubmittalListForProjectParams{
ProjectID: pID,
ShowIncompleteMissing: showMissing,
})
if err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, subs)
}
// ListInstrumentSubmittals godoc
//
// @Summary lists all submittals for an instrument
// @Tags submittal
// @Produce json
// @Param instrument_id path string true "instrument uuid" Format(uuid)
// @Param missing query bool false "filter by missing projects only"
// @Success 200 {array} db.VSubmittal
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /instruments/{instrument_id}/submittals [get]
func (h *ApiHandler) ListInstrumentSubmittals(c echo.Context) error {
instID, err := uuid.Parse(c.Param("instrument_id"))
if err != nil {
return httperr.MalformedID(err)
}
showMissing := strings.ToLower(c.QueryParam("missing")) == "true"
subs, err := h.DBService.SubmittalListForInstrument(c.Request().Context(), db.SubmittalListForInstrumentParams{
InstrumentID: instID,
ShowIncompleteMissing: showMissing,
})
if err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, subs)
}
// ListAlertConfigSubmittals godoc
//
// @Summary lists all submittals for an instrument
// @Tags submittal
// @Produce json
// @Param alert_config_id path string true "alert config uuid" Format(uuid)
// @Success 200 {array} db.VSubmittal
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /alert_configs/{alert_config_id}/submittals [get]
func (h *ApiHandler) ListAlertConfigSubmittals(c echo.Context) error {
acID, err := uuid.Parse(c.Param("alert_config_id"))
if err != nil {
return httperr.MalformedID(err)
}
showMissing := strings.ToLower(c.QueryParam("missing")) == "true"
subs, err := h.DBService.SubmittalListForAlertConfig(c.Request().Context(), db.SubmittalListForAlertConfigParams{
AlertConfigID: acID,
ShowIncompleteMissing: showMissing,
})
if err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, subs)
}
// VerifyMissingSubmittal godoc
//
// @Summary verifies the specified submittal is "missing" and will not be completed
// @Tags submittal
// @Produce json
// @Param submittal_id path string true "submittal uuid" Format(uuid)
// @Param key query string false "api key"
// @Success 200 {object} map[string]interface{}
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /submittals/{submittal_id}/verify_missing [put]
// @Security Bearer
func (h *ApiHandler) VerifyMissingSubmittal(c echo.Context) error {
subID, err := uuid.Parse(c.Param("submittal_id"))
if err != nil {
return httperr.MalformedID(err)
}
if err := h.DBService.SubmittalUpdateVerifyMissing(c.Request().Context(), subID); err != nil {
return httperr.ServerErrorOrNotFound(err)
}
return c.JSON(http.StatusOK, map[string]interface{}{"submittal_id": subID})
}
// VerifyMissingAlertConfigSubmittals godoc
//
// @Summary verifies all current submittals for the alert config are "missing" and will not be completed
// @Tags submittal
// @Produce json
// @Param alert_config_id path string true "alert config uuid" Format(uuid)
// @Param key query string false "api key"
// @Success 200 {object} map[string]interface{}
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /alert_configs/{alert_config_id}/submittals/verify_missing [put]
// @Security Bearer
func (h *ApiHandler) VerifyMissingAlertConfigSubmittals(c echo.Context) error {
acID, err := uuid.Parse(c.Param("alert_config_id"))
if err != nil {
return httperr.MalformedID(err)
}
if err := h.DBService.SubmittalUpdateVerifyMissingForAlertConfig(c.Request().Context(), &acID); err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, map[string]interface{}{"alert_config_id": acID})
}