Skip to content

Commit 0baa80b

Browse files
committed
stub for user-activity
1 parent c480f0f commit 0baa80b

File tree

6 files changed

+340
-0
lines changed

6 files changed

+340
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ func New(options *Options) *API {
895895
r.Route("/insights", func(r chi.Router) {
896896
r.Use(apiKeyMiddleware)
897897
r.Get("/daus", api.deploymentDAUs)
898+
r.Get("/user-activity", api.insightsUserActivity)
898899
r.Get("/user-latency", api.insightsUserLatency)
899900
r.Get("/templates", api.insightsTemplates)
900901
})

coderd/insights.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,56 @@ func (api *API) deploymentDAUs(rw http.ResponseWriter, r *http.Request) {
5959
httpapi.Write(ctx, rw, http.StatusOK, resp)
6060
}
6161

62+
// @Summary Get insights about user activity
63+
// @ID get-insights-about-user-activity
64+
// @Security CoderSessionToken
65+
// @Produce json
66+
// @Tags Insights
67+
// @Success 200 {object} codersdk.UserActivityInsightsResponse
68+
// @Router /insights/user-activity [get]
69+
func (api *API) insightsUserActivity(rw http.ResponseWriter, r *http.Request) {
70+
ctx := r.Context()
71+
72+
p := httpapi.NewQueryParamParser().
73+
Required("start_time").
74+
Required("end_time")
75+
vals := r.URL.Query()
76+
var (
77+
// The QueryParamParser does not preserve timezone, so we need
78+
// to parse the time ourselves.
79+
startTimeString = p.String(vals, "", "start_time")
80+
endTimeString = p.String(vals, "", "end_time")
81+
templateIDs = p.UUIDs(vals, []uuid.UUID{}, "template_ids")
82+
)
83+
p.ErrorExcessParams(vals)
84+
if len(p.Errors) > 0 {
85+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
86+
Message: "Query parameters have invalid values.",
87+
Validations: p.Errors,
88+
})
89+
return
90+
}
91+
92+
startTime, endTime, ok := parseInsightsStartAndEndTime(ctx, rw, startTimeString, endTimeString)
93+
if !ok {
94+
return
95+
}
96+
97+
// TODO
98+
99+
seenTemplateIDs := templateIDs // FIXME
100+
101+
resp := codersdk.UserActivityInsightsResponse{
102+
Report: codersdk.UserActivityInsightsReport{
103+
StartTime: startTime,
104+
EndTime: endTime,
105+
TemplateIDs: seenTemplateIDs,
106+
Users: nil, // FIXME
107+
},
108+
}
109+
httpapi.Write(ctx, rw, http.StatusOK, resp)
110+
}
111+
62112
// @Summary Get insights about user latency
63113
// @ID get-insights-about-user-latency
64114
// @Security CoderSessionToken

docs/api/insights.md

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)