feat: get api service by client handler and endpoint

This commit is contained in:
2025-06-07 19:22:44 +02:00
parent 3ceeab04e1
commit 14c69349cc
2 changed files with 19 additions and 0 deletions

View File

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

View File

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