-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplot_config.go
93 lines (87 loc) · 3.04 KB
/
plot_config.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
package handler
import (
"net/http"
"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"
)
// ListPlotConfigs godoc
//
// @Summary lists plot configs
// @Tags plot-config
// @Produce json
// @Param project_id path string true "project uuid" Format(uuid)
// @Success 200 {array} db.VPlotConfiguration
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /projects/{project_id}/plot_configs [get]
// @Router /projects/{project_id}/plot_configurations [get]
func (h *ApiHandler) ListPlotConfigs(c echo.Context) error {
pID, err := uuid.Parse(c.Param("project_id"))
if err != nil {
return httperr.MalformedID(err)
}
cc, err := h.DBService.PlotConfigListForProject(c.Request().Context(), pID)
if err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, cc)
}
// GetPlotConfig godoc
//
// @Summary gets a single plot configuration by id
// @Tags plot-config
// @Produce json
// @Param project_id path string true "project uuid" Format(uuid)
// @Param plot_configuration_id path string true "plot config uuid" Format(uuid)
// @Success 200 {object} db.VPlotConfiguration
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /projects/{project_id}/plot_configs/{plot_configuration_id} [get]
// @Router /projects/{project_id}/plot_configurations/{plot_configuration_id} [get]
func (h *ApiHandler) GetPlotConfig(c echo.Context) error {
cID, err := uuid.Parse(c.Param("plot_configuration_id"))
if err != nil {
return httperr.MalformedID(err)
}
g, err := h.DBService.PlotConfigGet(c.Request().Context(), cID)
if err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, g)
}
// DeletePlotConfig godoc
//
// @Summary deletes a plot configuration in a project
// @Tags plot-config
// @Produce json
// @Param project_id path string true "project uuid" Format(uuid)
// @Param plot_configuration_id path string true "plot 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 /projects/{project_id}/plot_configs/{plot_configuration_id} [delete]
// @Router /projects/{project_id}/plot_configurations/{plot_configuration_id} [delete]
// @Security Bearer
func (h *ApiHandler) DeletePlotConfig(c echo.Context) error {
pID, err := uuid.Parse(c.Param("project_id"))
if err != nil {
return httperr.MalformedID(err)
}
cID, err := uuid.Parse(c.Param("plot_configuration_id"))
if err != nil {
return httperr.MalformedID(err)
}
if err := h.DBService.PlotConfigDelete(c.Request().Context(), db.PlotConfigDeleteParams{
ID: cID,
ProjectID: pID,
}); err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, make(map[string]interface{}))
}