mirror of https://github.com/coder/coder.git
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package coderd
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/coder/coder/coderd/httpapi"
|
|
"github.com/coder/coder/coderd/rbac"
|
|
"github.com/coder/coder/codersdk"
|
|
)
|
|
|
|
// @Summary Get deployment DAUs
|
|
// @ID get-deployment-daus
|
|
// @Security CoderSessionToken
|
|
// @Produce json
|
|
// @Tags Insights
|
|
// @Success 200 {object} codersdk.DAUsResponse
|
|
// @Router /insights/daus [get]
|
|
func (api *API) deploymentDAUs(rw http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceDeploymentValues) {
|
|
httpapi.Forbidden(rw)
|
|
return
|
|
}
|
|
|
|
vals := r.URL.Query()
|
|
p := httpapi.NewQueryParamParser()
|
|
tzOffset := p.Int(vals, 0, "tz_offset")
|
|
p.ErrorExcessParams(vals)
|
|
if len(p.Errors) > 0 {
|
|
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
|
Message: "Query parameters have invalid values.",
|
|
Validations: p.Errors,
|
|
})
|
|
return
|
|
}
|
|
|
|
_, resp, _ := api.metricsCache.DeploymentDAUs(tzOffset)
|
|
if resp == nil || resp.Entries == nil {
|
|
httpapi.Write(ctx, rw, http.StatusOK, &codersdk.DAUsResponse{
|
|
Entries: []codersdk.DAUEntry{},
|
|
})
|
|
return
|
|
}
|
|
httpapi.Write(ctx, rw, http.StatusOK, resp)
|
|
}
|