| package router |
|
|
| import ( |
| "net/http" |
|
|
| "github.com/samber/lo" |
|
|
| "github.com/openmeterio/openmeter/api" |
| planhttpdriver "github.com/openmeterio/openmeter/openmeter/productcatalog/plan/httpdriver" |
| "github.com/openmeterio/openmeter/pkg/featuregate" |
| ) |
|
|
| |
| |
| func (a *Router) ListPlans(w http.ResponseWriter, r *http.Request, params api.ListPlansParams) { |
| a.planHandler.ListPlans().With(params).ServeHTTP(w, r) |
| } |
|
|
| |
| |
| func (a *Router) CreatePlan(w http.ResponseWriter, r *http.Request) { |
| a.planHandler.CreatePlan(). |
| Chain(featuregate.NewMiddleware[planhttpdriver.CreatePlanRequest, planhttpdriver.CreatePlanResponse]( |
| a.config.NamespaceDecoder.GetNamespace, |
| a.config.FeatureGate, |
| )).ServeHTTP(w, r) |
| } |
|
|
| |
| |
| func (a *Router) DeletePlan(w http.ResponseWriter, r *http.Request, planId string) { |
| a.planHandler.DeletePlan().With(planId).ServeHTTP(w, r) |
| } |
|
|
| |
| |
| func (a *Router) GetPlan(w http.ResponseWriter, r *http.Request, planIdOrKey string, params api.GetPlanParams) { |
| a.planHandler.GetPlan().With(planhttpdriver.GetPlanRequestParams{ |
| IDOrKey: planIdOrKey, |
| IncludeLatest: lo.FromPtrOr(params.IncludeLatest, false), |
| }).ServeHTTP(w, r) |
| } |
|
|
| |
| |
| func (a *Router) UpdatePlan(w http.ResponseWriter, r *http.Request, planId string) { |
| a.planHandler.UpdatePlan(). |
| Chain(featuregate.NewMiddleware[planhttpdriver.UpdatePlanRequest, planhttpdriver.UpdatePlanResponse]( |
| a.config.NamespaceDecoder.GetNamespace, |
| a.config.FeatureGate, |
| )).With(planId).ServeHTTP(w, r) |
| } |
|
|
| |
| |
| func (a *Router) NextPlan(w http.ResponseWriter, r *http.Request, planIdOrKey string) { |
| |
| a.planHandler.NextPlan().With(planIdOrKey).ServeHTTP(w, r) |
| } |
|
|
| |
| |
| func (a *Router) PublishPlan(w http.ResponseWriter, r *http.Request, planId string) { |
| a.planHandler.PublishPlan().With(planId).ServeHTTP(w, r) |
| } |
|
|
| |
| |
| func (a *Router) ArchivePlan(w http.ResponseWriter, r *http.Request, planId string) { |
| a.planHandler.ArchivePlan().With(planId).ServeHTTP(w, r) |
| } |
|
|