diff --git a/internal/admin/apiservices.go b/internal/admin/apiservices.go index 526d95b..85172ef 100644 --- a/internal/admin/apiservices.go +++ b/internal/admin/apiservices.go @@ -186,6 +186,24 @@ func (h *AdminHandler) GetApiService(w http.ResponseWriter, r *http.Request) { } } +func (h *AdminHandler) GetApiServiceCID(w http.ResponseWriter, r *http.Request) { + clientId := chi.URLParam(r, "client_id") + + service, err := h.repo.GetApiServiceCID(r.Context(), clientId) + if err != nil { + web.Error(w, "service with provided client id not found", http.StatusNotFound) + return + } + + encoder := json.NewEncoder(w) + + w.Header().Set("Content-Type", "application/json") + + if err := encoder.Encode(NewApiServiceDTO(service)); err != nil { + web.Error(w, "failed to encode response", http.StatusInternalServerError) + } +} + func (h *AdminHandler) RegenerateApiServiceSecret(w http.ResponseWriter, r *http.Request) { serviceId := chi.URLParam(r, "id") parsed, err := uuid.Parse(serviceId) diff --git a/internal/admin/routes.go b/internal/admin/routes.go index a39e177..d26709b 100644 --- a/internal/admin/routes.go +++ b/internal/admin/routes.go @@ -27,6 +27,7 @@ func (h *AdminHandler) RegisterRoutes(router chi.Router) { r.Get("/api-services", h.GetApiServices) r.Get("/api-services/{id}", h.GetApiService) + r.Get("/api-services/{client_id}", h.GetApiServiceCID) r.Post("/api-services", h.AddApiService) r.Patch("/api-services/{id}", h.RegenerateApiServiceSecret) r.Put("/api-services/{id}", h.UpdateApiService)