-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathmodule_streams.go
More file actions
88 lines (71 loc) · 3.19 KB
/
Copy pathmodule_streams.go
File metadata and controls
88 lines (71 loc) · 3.19 KB
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
package handler
import (
"net/http"
"github.com/content-services/content-sources-backend/pkg/api"
"github.com/content-services/content-sources-backend/pkg/dao"
ce "github.com/content-services/content-sources-backend/pkg/errors"
"github.com/content-services/content-sources-backend/pkg/rbac"
"github.com/labstack/echo/v4"
)
type ModuleStreamsHandler struct {
Dao dao.DaoRegistry
}
func RegisterModuleStreamsRoutes(engine *echo.Group, rDao *dao.DaoRegistry) {
rh := ModuleStreamsHandler{
Dao: *rDao,
}
addRepoRoute(engine, http.MethodPost, "/snapshots/module_streams/search", rh.searchSnapshotModuleStreams, rbac.RbacVerbRead)
addRepoRoute(engine, http.MethodPost, "/module_streams/search", rh.searchRepoModuleStreams, rbac.RbacVerbRead)
}
// searchSnapshotModuleStreams godoc
// @Summary List modules and their streams for snapshots
// @ID searchSnapshotModuleStreams
// @Description List modules and their streams for snapshots
// @Tags module_streams
// @Accept json
// @Produce json
// @Param body body api.SearchSnapshotModuleStreamsRequest true "request body"
// @Success 200 {object} []api.SearchModuleStreams
// @Failure 400 {object} ce.ErrorResponse
// @Failure 401 {object} ce.ErrorResponse
// @Failure 404 {object} ce.ErrorResponse
// @Failure 500 {object} ce.ErrorResponse
// @Router /snapshots/module_streams/search [post]
func (rh *ModuleStreamsHandler) searchSnapshotModuleStreams(c echo.Context) error {
_, orgId := GetAccountIdOrgId(c)
dataInput := api.SearchSnapshotModuleStreamsRequest{}
if err := c.Bind(&dataInput); err != nil {
return ce.NewErrorResponse(http.StatusBadRequest, "Error binding parameters", err.Error())
}
apiResponse, err := rh.Dao.ModuleStream.SearchSnapshotModuleStreams(c.Request().Context(), orgId, dataInput)
if err != nil {
return ce.NewErrorResponse(ce.HttpCodeForDaoError(err), "Error searching modules streams", err.Error())
}
return c.JSON(200, apiResponse)
}
// searchRepoModuleStreams godoc
// @Summary List modules and their streams for repositories
// @ID searchRepositoryModuleStreams
// @Description List modules and their streams for repositories
// @Tags module_streams
// @Accept json
// @Produce json
// @Param body body api.SearchModuleStreamsRequest true "request body"
// @Success 200 {object} []api.SearchModuleStreams
// @Failure 400 {object} ce.ErrorResponse
// @Failure 401 {object} ce.ErrorResponse
// @Failure 404 {object} ce.ErrorResponse
// @Failure 500 {object} ce.ErrorResponse
// @Router /module_streams/search [post]
func (rh *ModuleStreamsHandler) searchRepoModuleStreams(c echo.Context) error {
_, orgId := GetAccountIdOrgId(c)
dataInput := api.SearchModuleStreamsRequest{}
if err := c.Bind(&dataInput); err != nil {
return ce.NewErrorResponse(http.StatusBadRequest, "Error binding parameters", err.Error())
}
apiResponse, err := rh.Dao.ModuleStream.SearchRepositoryModuleStreams(c.Request().Context(), orgId, dataInput)
if err != nil {
return ce.NewErrorResponse(ce.HttpCodeForDaoError(err), "Error searching modules streams", err.Error())
}
return c.JSON(200, apiResponse)
}