2023-07-26 12:27:46 +05:30
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2025-03-06 15:39:45 +05:30
|
|
|
"errors"
|
2023-07-26 12:27:46 +05:30
|
|
|
"net/http"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"go.signoz.io/signoz/pkg/query-service/dao"
|
|
|
|
|
"go.signoz.io/signoz/pkg/query-service/model"
|
2025-03-06 15:39:45 +05:30
|
|
|
"go.signoz.io/signoz/pkg/types/authtypes"
|
2023-07-26 12:27:46 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (aH *APIHandler) setApdexSettings(w http.ResponseWriter, r *http.Request) {
|
2025-03-06 15:39:45 +05:30
|
|
|
claims, ok := authtypes.ClaimsFromContext(r.Context())
|
|
|
|
|
if !ok {
|
|
|
|
|
RespondError(w, &model.ApiError{Err: errors.New("unauthorized"), Typ: model.ErrorUnauthorized}, nil)
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-07-26 12:27:46 +05:30
|
|
|
req, err := parseSetApdexScoreRequest(r)
|
|
|
|
|
if aH.HandleError(w, err, http.StatusBadRequest) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-06 15:39:45 +05:30
|
|
|
if err := dao.DB().SetApdexSettings(r.Context(), claims.OrgID, req); err != nil {
|
2023-07-26 12:27:46 +05:30
|
|
|
RespondError(w, &model.ApiError{Err: err, Typ: model.ErrorInternal}, nil)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aH.WriteJSON(w, r, map[string]string{"data": "apdex score updated successfully"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (aH *APIHandler) getApdexSettings(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
services := r.URL.Query().Get("services")
|
2025-03-06 15:39:45 +05:30
|
|
|
claims, ok := authtypes.ClaimsFromContext(r.Context())
|
|
|
|
|
if !ok {
|
|
|
|
|
RespondError(w, &model.ApiError{Err: errors.New("unauthorized"), Typ: model.ErrorUnauthorized}, nil)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
apdexSet, err := dao.DB().GetApdexSettings(r.Context(), claims.OrgID, strings.Split(strings.TrimSpace(services), ","))
|
2023-07-26 12:27:46 +05:30
|
|
|
if err != nil {
|
|
|
|
|
RespondError(w, &model.ApiError{Err: err, Typ: model.ErrorInternal}, nil)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
aH.WriteJSON(w, r, apdexSet)
|
|
|
|
|
}
|