fix: finish update service endpoint
This commit is contained in:
@ -222,11 +222,11 @@ func (h *AdminHandler) RegenerateApiServiceSecret(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
type UpdateApiServiceRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
RedirectUris []string `json:"redirect_uris"`
|
||||
Scopes []string `json:"scopes"`
|
||||
GrantTypes []string `json:"grant_types"`
|
||||
Scopes []string `json:"scopes"`
|
||||
GrantTypes []string `json:"grant_types"`
|
||||
}
|
||||
|
||||
func (h *AdminHandler) UpdateApiService(w http.ResponseWriter, r *http.Request) {
|
||||
@ -236,22 +236,22 @@ func (h *AdminHandler) UpdateApiService(w http.ResponseWriter, r *http.Request)
|
||||
web.Error(w, "provided service id is not valid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var req UpdateApiServiceRequest
|
||||
|
||||
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
if err := decoder.Decode(&req); err != nil {
|
||||
web.Error(w, "missing required fields to update service", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if req.Name == "" {
|
||||
web.Error(w, "service name is required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Description == "" {
|
||||
web.Error(w, "service name is required", http.StatusBadRequest)
|
||||
|
||||
if len(req.Scopes) == 0 {
|
||||
web.Error(w, "at least 1 scope is required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@ -260,16 +260,26 @@ func (h *AdminHandler) UpdateApiService(w http.ResponseWriter, r *http.Request)
|
||||
web.Error(w, "service with provided id not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.repo.UpdateApiService(r.Context(), repository.UpdateApiServiceParams{
|
||||
ClientID: service.ClientID,
|
||||
Name: ,
|
||||
Description: pgtype.Text{},
|
||||
RedirectUris: []string{},
|
||||
Scopes: []string{},
|
||||
GrantTypes: []string{},
|
||||
}); err != nil {
|
||||
|
||||
updated, err := h.repo.UpdateApiService(r.Context(), repository.UpdateApiServiceParams{
|
||||
ClientID: service.ClientID,
|
||||
Name: req.Name,
|
||||
Description: pgtype.Text{
|
||||
String: req.Description,
|
||||
Valid: true,
|
||||
},
|
||||
RedirectUris: req.RedirectUris,
|
||||
Scopes: req.Scopes,
|
||||
GrantTypes: req.GrantTypes,
|
||||
})
|
||||
if err != nil {
|
||||
web.Error(w, "failed to update api service", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
|
||||
if err := encoder.Encode(NewApiServiceDTO(updated)); err != nil {
|
||||
web.Error(w, "failed to send updated api service", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user