feat: get api service by client handler and endpoint
This commit is contained in:
@ -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)
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user