diff --git a/eduserver/inthttp/client.go b/eduserver/inthttp/client.go index 0690ed827..51497a980 100644 --- a/eduserver/inthttp/client.go +++ b/eduserver/inthttp/client.go @@ -15,6 +15,7 @@ const ( EDUServerInputTypingEventPath = "/eduserver/input" EDUServerInputSendToDeviceEventPath = "/eduserver/sendToDevice" EDUServerInputReceiptEventPath = "/eduserver/receipt" + EDUServerInputPresencePath = "/eduserver/presence" ) // NewEDUServerClient creates a EDUServerInputAPI implemented by talking to a HTTP POST API. @@ -68,3 +69,16 @@ func (h *httpEDUServerInputAPI) InputReceiptEvent( apiURL := h.eduServerURL + EDUServerInputReceiptEventPath return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response) } + +// InputPresence implements EDUServerInputAPI +func (h *httpEDUServerInputAPI) InputPresence( + ctx context.Context, + request *api.InputPresenceRequest, + response *api.InputPresenceResponse, +) error { + span, ctx := opentracing.StartSpanFromContext(ctx, "InputPresencePath") + defer span.Finish() + + apiURL := h.eduServerURL + EDUServerInputPresencePath + return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response) +} diff --git a/eduserver/inthttp/server.go b/eduserver/inthttp/server.go index a34943750..d9e1a3a0b 100644 --- a/eduserver/inthttp/server.go +++ b/eduserver/inthttp/server.go @@ -51,4 +51,17 @@ func AddRoutes(t api.EDUServerInputAPI, internalAPIMux *mux.Router) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) + internalAPIMux.Handle(EDUServerInputPresencePath, + httputil.MakeInternalAPI("inputPresence", func(req *http.Request) util.JSONResponse { + var request api.InputPresenceRequest + var response api.InputPresenceResponse + if err := json.NewDecoder(req.Body).Decode(&request); err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + if err := t.InputPresence(req.Context(), &request, &response); err != nil { + return util.ErrorResponse(err) + } + return util.JSONResponse{Code: http.StatusOK, JSON: &response} + }), + ) }