From d8dd4d7bc4b9180ee2e30670beeaf00e222428de Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 13 Oct 2020 07:31:13 +0200 Subject: [PATCH] Rename struct to fit namescheme --- clientapi/routing/receipt.go | 2 +- roomserver/api/api.go | 2 +- roomserver/api/api_trace.go | 4 ++-- roomserver/api/receipt.go | 2 +- roomserver/internal/api.go | 2 +- roomserver/internal/perform/perform_receipt.go | 2 +- roomserver/inthttp/client.go | 4 ++-- roomserver/inthttp/server.go | 13 +++++++++++++ 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/clientapi/routing/receipt.go b/clientapi/routing/receipt.go index d705034e7..dee5f93fd 100644 --- a/clientapi/routing/receipt.go +++ b/clientapi/routing/receipt.go @@ -30,7 +30,7 @@ func SetReceipt(req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI, de "eventId": eventId, "userId": device.UserID, }).Debug("Setting receipt") - userReq := &roomserverAPI.PerformUserReceiptUpdate{ + userReq := &roomserverAPI.PerformUserReceiptUpdateRequest{ RoomID: roomId, ReceiptType: receiptType, EventID: eventId, diff --git a/roomserver/api/api.go b/roomserver/api/api.go index 6608adc34..f169ab6f1 100644 --- a/roomserver/api/api.go +++ b/roomserver/api/api.go @@ -196,5 +196,5 @@ type RoomserverInternalAPI interface { response *RemoveRoomAliasResponse, ) error - PerformUserReceiptUpdate(ctx context.Context, req *PerformUserReceiptUpdate, res *PerformUserReceiptUpdateResponse) error + PerformUserReceiptUpdate(ctx context.Context, req *PerformUserReceiptUpdateRequest, res *PerformUserReceiptUpdateResponse) error } diff --git a/roomserver/api/api_trace.go b/roomserver/api/api_trace.go index a486c602f..41616dcca 100644 --- a/roomserver/api/api_trace.go +++ b/roomserver/api/api_trace.go @@ -315,10 +315,10 @@ func js(thing interface{}) string { func (t *RoomserverInternalAPITrace) PerformUserReceiptUpdate( ctx context.Context, - req *PerformUserReceiptUpdate, + req *PerformUserReceiptUpdateRequest, res *PerformUserReceiptUpdateResponse, ) error { err := t.Impl.PerformUserReceiptUpdate(ctx, req, res) - util.GetLogger(ctx).WithError(err).Infof("PerformUserReceiptUpdate req=%+v res=%+v", js(req), js(res)) + util.GetLogger(ctx).WithError(err).Infof("PerformUserReceiptUpdateRequest req=%+v res=%+v", js(req), js(res)) return err } diff --git a/roomserver/api/receipt.go b/roomserver/api/receipt.go index 5f07f0917..5d12f75eb 100644 --- a/roomserver/api/receipt.go +++ b/roomserver/api/receipt.go @@ -1,6 +1,6 @@ package api -type PerformUserReceiptUpdate struct { +type PerformUserReceiptUpdateRequest struct { RoomID string ReceiptType string EventID string diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go index 22d41e38b..0b5a863a2 100644 --- a/roomserver/internal/api.go +++ b/roomserver/internal/api.go @@ -150,7 +150,7 @@ func (r *RoomserverInternalAPI) PerformLeave( func (r *RoomserverInternalAPI) PerformUserReceiptUpdate( ctx context.Context, - req *api.PerformUserReceiptUpdate, + req *api.PerformUserReceiptUpdateRequest, res *api.PerformUserReceiptUpdateResponse, ) error { return r.Receipter.PerformUserReceiptUpdate(ctx, req, res) diff --git a/roomserver/internal/perform/perform_receipt.go b/roomserver/internal/perform/perform_receipt.go index e8f975866..9f81c177f 100644 --- a/roomserver/internal/perform/perform_receipt.go +++ b/roomserver/internal/perform/perform_receipt.go @@ -11,6 +11,6 @@ type Receipter struct { DB storage.Database } -func (r *Receipter) PerformUserReceiptUpdate(ctx context.Context, req *api.PerformUserReceiptUpdate, res *api.PerformUserReceiptUpdateResponse) error { +func (r *Receipter) PerformUserReceiptUpdate(ctx context.Context, req *api.PerformUserReceiptUpdateRequest, res *api.PerformUserReceiptUpdateResponse) error { return r.DB.StoreReceipt(ctx, req.RoomID, req.ReceiptType, req.UserID, req.EventID) } diff --git a/roomserver/inthttp/client.go b/roomserver/inthttp/client.go index 735c64eda..4dadb6c5c 100644 --- a/roomserver/inthttp/client.go +++ b/roomserver/inthttp/client.go @@ -496,10 +496,10 @@ func (h *httpRoomserverInternalAPI) QueryServerBannedFromRoom( func (h *httpRoomserverInternalAPI) PerformUserReceiptUpdate( ctx context.Context, - req *api.PerformUserReceiptUpdate, + req *api.PerformUserReceiptUpdateRequest, res *api.PerformUserReceiptUpdateResponse, ) error { - span, ctx := opentracing.StartSpanFromContext(ctx, "PerformUserReceiptUpdate") + span, ctx := opentracing.StartSpanFromContext(ctx, "PerformUserReceiptUpdateRequest") defer span.Finish() apiURL := h.roomserverURL + RoomserverPerformReceiptUpdatePath diff --git a/roomserver/inthttp/server.go b/roomserver/inthttp/server.go index 9c9d4d4ae..7036a37b4 100644 --- a/roomserver/inthttp/server.go +++ b/roomserver/inthttp/server.go @@ -427,4 +427,17 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) { return util.JSONResponse{Code: http.StatusOK, JSON: &response} }), ) + internalAPIMux.Handle(RoomserverPerformReceiptUpdatePath, + httputil.MakeInternalAPI("performReceiptUpdate", func(req *http.Request) util.JSONResponse { + request := api.PerformUserReceiptUpdateRequest{} + response := api.PerformUserReceiptUpdateResponse{} + if err := json.NewDecoder(req.Body).Decode(&request); err != nil { + return util.MessageResponse(http.StatusBadRequest, err.Error()) + } + if err := r.PerformUserReceiptUpdate(req.Context(), &request, &response); err != nil { + return util.ErrorResponse(err) + } + return util.JSONResponse{Code: http.StatusOK, JSON: &response} + }), + ) }