-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstrument_incl.go
99 lines (94 loc) · 3.34 KB
/
instrument_incl.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
package handler
import (
"net/http"
"time"
"github.com/USACE/instrumentation-api/api/internal/db"
"github.com/USACE/instrumentation-api/api/internal/dto"
"github.com/USACE/instrumentation-api/api/internal/httperr"
"github.com/USACE/instrumentation-api/api/internal/util"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)
// ListInclSegmentsForInstrument godoc
//
// @Summary gets all incl segments for an instrument
// @Tags instrument-incl
// @Produce json
// @Param instrument_id path string true "instrument uuid" Format(uuid)
// @Success 200 {array} db.VInclSegment
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /instruments/incl/{instrument_id}/segments [get]
func (h *ApiHandler) ListInclSegmentsForInstrument(c echo.Context) error {
iID, err := uuid.Parse(c.Param("instrument_id"))
if err != nil {
return httperr.MalformedID(err)
}
ss, err := h.DBService.InclSegmentListForInstrument(c.Request().Context(), iID)
if err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, ss)
}
// GetInclMeasurementsForInstrument godoc
//
// @Summary creates instrument notes
// @Tags instrument-incl
// @Produce json
// @Param instrument_id path string true "instrument uuid" Format(uuid)
// @Param after query string false "after time" Format(date-time)
// @Param before query string true "before time" Format(date-time)
// @Success 200 {array} db.VInclMeasurement
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /instruments/incl/{instrument_id}/measurements [get]
func (h *ApiHandler) GetInclMeasurementsForInstrument(c echo.Context) error {
iID, err := uuid.Parse(c.Param("instrument_id"))
if err != nil {
return httperr.MalformedID(err)
}
var tw util.TimeWindow
a, b := c.QueryParam("after"), c.QueryParam("before")
if err := tw.SetWindow(a, b, time.Now().AddDate(0, 0, -7), time.Now()); err != nil {
return httperr.MalformedDateRFC3339(err)
}
mm, err := h.DBService.InclMeasurementListForInstrumentRange(c.Request().Context(), db.InclMeasurementListForInstrumentRangeParams{
InstrumentID: iID,
StartTime: tw.After,
EndTime: tw.Before,
})
if err != nil {
return httperr.MalformedID(err)
}
return c.JSON(http.StatusOK, mm)
}
// UpdateInclSegments godoc
//
// @Summary updates multiple segments for an incl instrument
// @Tags instrument-incl
// @Produce json
// @Param instrument_id path string true "instrument uuid" Format(uuid)
// @Param instrument_segments body []dto.InclSegment true "incl instrument segments payload"
// @Param key query string false "api key"
// @Success 200 {array} dto.InclSegment
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /instruments/incl/{instrument_id}/segments [put]
// @Security Bearer
func (h *ApiHandler) UpdateInclSegments(c echo.Context) error {
iID, err := uuid.Parse(c.Param("instrument_id"))
if err != nil {
return httperr.MalformedID(err)
}
segs := make([]dto.InclSegment, 0)
if err := c.Bind(&segs); err != nil {
return httperr.MalformedBody(err)
}
if err := h.DBService.InclSegmentUpdateBatch(c.Request().Context(), iID, segs); err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, segs)
}