mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-29 13:41:58 +08:00
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/SigNoz/signoz/pkg/query-service/dao"
|
|
"github.com/SigNoz/signoz/pkg/query-service/model"
|
|
"github.com/SigNoz/signoz/pkg/types/authtypes"
|
|
)
|
|
|
|
func (aH *APIHandler) setApdexSettings(w http.ResponseWriter, r *http.Request) {
|
|
claims, ok := authtypes.ClaimsFromContext(r.Context())
|
|
if !ok {
|
|
RespondError(w, &model.ApiError{Err: errors.New("unauthorized"), Typ: model.ErrorUnauthorized}, nil)
|
|
return
|
|
}
|
|
req, err := parseSetApdexScoreRequest(r)
|
|
if aH.HandleError(w, err, http.StatusBadRequest) {
|
|
return
|
|
}
|
|
|
|
if err := dao.DB().SetApdexSettings(r.Context(), claims.OrgID, req); err != nil {
|
|
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")
|
|
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), ","))
|
|
if err != nil {
|
|
RespondError(w, &model.ApiError{Err: err, Typ: model.ErrorInternal}, nil)
|
|
return
|
|
}
|
|
|
|
aH.WriteJSON(w, r, apdexSet)
|
|
}
|