Add internal api

This commit is contained in:
Till Faelligen 2021-06-18 20:53:09 +02:00
parent 9e795ce5e7
commit 0d3a6e1c37
2 changed files with 27 additions and 0 deletions

View file

@ -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)
}

View file

@ -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}
}),
)
}