Merge pull request #46 from pedronasser/image-filter

added route filter: image
This commit is contained in:
Travis Reeder
2016-08-11 08:38:56 -07:00
committed by GitHub
4 changed files with 11 additions and 1 deletions

View File

@@ -275,6 +275,10 @@ func buildFilterQuery(filter *models.RouteFilter) string {
filterQueries = append(filterQueries, fmt.Sprintf("app_name = '%s'", filter.AppName))
}
if filter.Image != "" {
filterQueries = append(filterQueries, fmt.Sprintf("image = '%s'", filter.Image))
}
for i, field := range filterQueries {
if i == 0 {
filterQuery = fmt.Sprintf("WHERE %s ", field)

View File

@@ -32,5 +32,6 @@ func ApplyAppFilter(app *App, filter *AppFilter) bool {
func ApplyRouteFilter(route *Route, filter *RouteFilter) bool {
return (filter.Path == "" || route.Path == filter.Path) &&
(filter.AppName == "" || route.AppName == filter.AppName)
(filter.AppName == "" || route.AppName == filter.AppName) &&
(filter.Image == "" || route.Image == filter.Image)
}

View File

@@ -64,4 +64,5 @@ func (r *Route) Validate() error {
type RouteFilter struct {
Path string
AppName string
Image string
}

View File

@@ -21,6 +21,10 @@ func handleRouteList(c *gin.Context) {
AppName: appName,
}
if img := c.Query("image"); img != "" {
filter.Image = img
}
routes, err := Api.Datastore.GetRoutes(filter)
if err != nil {
log.WithError(err).Error(models.ErrRoutesGet)