From 2eb5aeb30fb4ad1ccbf34f2bde2612f65ccc2d00 Mon Sep 17 00:00:00 2001 From: Raymond Tukpe Date: Sat, 11 Jun 2022 19:48:20 +0100 Subject: [PATCH] chore: add metadata to get one subscription --- docs/docs.go | 2 +- server/subscription.go | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index e25cb794c5..f1cd3e5964 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,6 +1,6 @@ // Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2022-06-11 17:01:18.028523 +0100 WAT m=+70.571493876 +// 2022-06-11 19:49:53.437188319 +0100 WAT m=+92.916961153 package docs import ( diff --git a/server/subscription.go b/server/subscription.go index 870a53c70d..359c305a8c 100644 --- a/server/subscription.go +++ b/server/subscription.go @@ -62,20 +62,34 @@ func (a *applicationHandler) GetSubscription(w http.ResponseWriter, r *http.Requ return } - source, err := a.sourceService.FindSourceByID(r.Context(), group, subscription.SourceID) - if err != nil { - _ = render.Render(w, r, newServiceErrResponse(err)) - return + if subscription.SourceID != "" { + source, err := a.sourceService.FindSourceByID(r.Context(), group, subscription.SourceID) + if err != nil { + _ = render.Render(w, r, newServiceErrResponse(err)) + return + } + subscription.Source = source } - endpoint, err := a.appRepo.FindApplicationEndpointByID(r.Context(), subscription.AppID, subscription.EndpointID) - if err != nil { - _ = render.Render(w, r, newServiceErrResponse(err)) - return + if subscription.EndpointID != "" { + endpoint, err := a.appRepo.FindApplicationEndpointByID(r.Context(), subscription.AppID, subscription.EndpointID) + if err != nil { + _ = render.Render(w, r, newServiceErrResponse(err)) + return + } + + subscription.Endpoint = endpoint } - subscription.Source = source - subscription.Endpoint = endpoint + if subscription.AppID != "" { + app, err := a.appRepo.FindApplicationByID(r.Context(), subscription.AppID) + if err != nil { + _ = render.Render(w, r, newServiceErrResponse(err)) + return + } + + subscription.App = app + } _ = render.Render(w, r, newServerResponse("Subscription fetched successfully", subscription, http.StatusOK)) }