-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from openinfradev/add_dashboard
Add dashboard
- Loading branch information
Showing
21 changed files
with
1,127 additions
and
466 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package http | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/openinfradev/tks-api/internal/usecase" | ||
"github.com/openinfradev/tks-api/pkg/domain" | ||
"github.com/openinfradev/tks-api/pkg/httpErrors" | ||
"github.com/openinfradev/tks-api/pkg/log" | ||
) | ||
|
||
type DashboardHandler struct { | ||
usecase usecase.IDashboardUsecase | ||
} | ||
|
||
func NewDashboardHandler(h usecase.IDashboardUsecase) *DashboardHandler { | ||
return &DashboardHandler{ | ||
usecase: h, | ||
} | ||
} | ||
|
||
// GetCharts godoc | ||
// @Tags Dashboards | ||
// @Summary Get chart data | ||
// @Description Get chart data | ||
// @Accept json | ||
// @Produce json | ||
// @Param organizationId path string true "organizationId" | ||
// @Param chartType query string false "chartType" | ||
// @Param duration query string true "duration" | ||
// @Param interval query string true "interval" | ||
// @Success 200 {object} domain.GetDashboardChartsResponse | ||
// @Router /organizations/{organizationId}/dashboard/charts [get] | ||
// @Security JWT | ||
func (h *DashboardHandler) GetCharts(w http.ResponseWriter, r *http.Request) { | ||
vars := mux.Vars(r) | ||
organizationId, ok := vars["organizationId"] | ||
if !ok { | ||
ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid organizationId"))) | ||
return | ||
} | ||
|
||
query := r.URL.Query() | ||
strType := query.Get("chartType") | ||
chartType := new(domain.ChartType).FromString(strType) | ||
if strType == "" { | ||
chartType = domain.ChartType(domain.ChartType_ALL) | ||
} | ||
|
||
log.Info("a", chartType) | ||
duration := query.Get("duration") | ||
if duration == "" { | ||
duration = "1d" // default | ||
} | ||
|
||
interval := query.Get("interval") | ||
if interval == "" { | ||
interval = "1d" // default | ||
} | ||
|
||
charts, err := h.usecase.GetCharts(organizationId, chartType, duration, interval) | ||
if err != nil { | ||
ErrorJSON(w, err) | ||
return | ||
} | ||
|
||
var out domain.GetDashboardChartsResponse | ||
out.Charts = make([]domain.DashboardChartResponse, len(charts)) | ||
for i, chart := range charts { | ||
if err := domain.Map(chart, &out.Charts[i]); err != nil { | ||
log.Info(err) | ||
continue | ||
} | ||
} | ||
|
||
ResponseJSON(w, http.StatusOK, out) | ||
} |
Oops, something went wrong.