Skip to content

Commit

Permalink
added getFilterCategoriesOfFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFireMike committed Apr 7, 2020
1 parent d24af9a commit 58d7e81
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions cve-alert-restapi/request-handler/requestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ func StartWebServer(database *sqlx.DB, port string) {
// description: Returns a string that the specified filter is not in the DB.
e.GET("/filter/:id/cases", getFilterCases)

// swagger:operation GET /filter/{id}/categories filter getFilterCategoriesOfFilter
// ---
// summary: Gets all filter categories of a specific filter.
// produces:
// - application/json
// parameters:
// - name: id
// in: path
// description: ID of the filter.
// type: integer
// required: true
// responses:
// 200:
// description: Returns the filter categories.
// schema:
// type: array
// items:
// $ref: '#/definitions/FilterCategory'
// 404:
// description: Returns a string that there are no filter categories for the specified filter.
e.GET("/filter/:id/categories", getFilterCategoriesOfFilter)

// swagger:operation Post /filter/import filter importFilter
// ---
// summary: Imports filter from a file.
Expand Down Expand Up @@ -602,6 +624,31 @@ func getFilterCases(c echo.Context) error {
return c.JSON(http.StatusOK, cases)
}

func getFilterCategoriesOfFilter(c echo.Context) error {
var filterCategories []alertmanager.FilterCategory
sb := sqlbuilder.MySQL.NewSelectBuilder()
sb.Select("*").From("filter_categories").Where(sb.Equal("filter_id", c.Param("id")))
sql, args := sb.Build()
query, err := sqlbuilder.MySQL.Interpolate(sql, args)
if err != nil {
log.Error().
AnErr("Error", err).
Msg("Could not build sql query")
return err
}
err = db.Select(&filterCategories, query)
if err != nil {
log.Error().
AnErr("Error", err).
Msg("Could not search db")
return err
}
if filterCategories == nil {
return c.String(http.StatusNotFound, "No filter categories found!\n")
}
return c.JSON(http.StatusOK, filterCategories)
}

func importFilter(c echo.Context) error {
requestFile, err := c.FormFile("filterConfig")
if err != nil {
Expand Down

0 comments on commit 58d7e81

Please sign in to comment.