Commit 97758380 by Torkel Ödegaard

Worked on stars in search results

parent ad3d15e2
Subproject commit 1e3970c6e56af810047ab815acd7fd5e681b5139 Subproject commit b67f4dc390b5241339b8f2799110faf3d454e4c5
...@@ -45,6 +45,7 @@ func Register(r *macaron.Macaron) { ...@@ -45,6 +45,7 @@ func Register(r *macaron.Macaron) {
r.Put("/", bind(m.UpdateUserCommand{}), UpdateUser) r.Put("/", bind(m.UpdateUserCommand{}), UpdateUser)
r.Post("/using/:id", SetUsingAccount) r.Post("/using/:id", SetUsingAccount)
r.Get("/accounts", GetUserAccounts) r.Get("/accounts", GetUserAccounts)
r.Get("/stars/", GetUserStars)
r.Post("/stars/dashboard/:id", StarDashboard) r.Post("/stars/dashboard/:id", StarDashboard)
r.Delete("/stars/dashboard/:id", UnstarDashboard) r.Delete("/stars/dashboard/:id", UnstarDashboard)
}) })
......
...@@ -57,6 +57,10 @@ type MetricQueryResultDataDto struct { ...@@ -57,6 +57,10 @@ type MetricQueryResultDataDto struct {
DataPoints [][2]float64 `json:"datapoints"` DataPoints [][2]float64 `json:"datapoints"`
} }
type UserStars struct {
DashboardIds map[string]bool `json:"dashboardIds"`
}
func GetGravatarUrl(text string) string { func GetGravatarUrl(text string) string {
if text == "" { if text == "" {
return "" return ""
......
package api package api
import ( import (
"strconv"
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/bus" "github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware" "github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models" m "github.com/torkelo/grafana-pro/pkg/models"
...@@ -43,3 +46,20 @@ func UnstarDashboard(c *middleware.Context) { ...@@ -43,3 +46,20 @@ func UnstarDashboard(c *middleware.Context) {
c.JsonOK("Dashboard unstarred") c.JsonOK("Dashboard unstarred")
} }
func GetUserStars(c *middleware.Context) {
query := m.GetUserStarsQuery{UserId: c.UserId}
if err := bus.Dispatch(&query); err != nil {
c.JsonApiErr(500, "Failed to get user stars", err)
return
}
var result dtos.UserStars
result.DashboardIds = make(map[string]bool)
for _, star := range query.Result {
result.DashboardIds[strconv.FormatInt(star.DashboardId, 10)] = true
}
c.JSON(200, &result)
}
...@@ -7,6 +7,7 @@ type SearchResult struct { ...@@ -7,6 +7,7 @@ type SearchResult struct {
} }
type DashboardSearchHit struct { type DashboardSearchHit struct {
Id int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Slug string `json:"slug"` Slug string `json:"slug"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
......
...@@ -105,6 +105,7 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error { ...@@ -105,6 +105,7 @@ func SearchDashboards(query *m.SearchDashboardsQuery) error {
hit, exists := hits[item.Id] hit, exists := hits[item.Id]
if !exists { if !exists {
hit = &m.DashboardSearchHit{ hit = &m.DashboardSearchHit{
Id: item.Id,
Title: item.Title, Title: item.Title,
Slug: item.Slug, Slug: item.Slug,
Tags: []string{}, Tags: []string{},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment