Skip to content

Commit

Permalink
#609 Add stats API for responder actions
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jul 30, 2018
1 parent 115d9ce commit 546a054
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class CortexCtrl @Inject() (
case POST(p"/action") createAction
case GET(p"/action") findAction
case POST(p"/action/_search") findAction
case POST(p"/action/_stats") statsAction
case GET(p"/action/$entityType<[^/]*>/$entityId<[^/]*>") getActions(entityType, entityId)
case GET(p"/action/$actionId<[^/]*>") getAction(actionId)

Expand Down Expand Up @@ -197,6 +198,12 @@ class CortexCtrl @Inject() (
renderer.toOutput(OK, actions, total)
}

def statsAction: Action[Fields] = authenticated(Roles.read).async(fieldsBodyParser) { implicit request
val query = request.body.getValue("query").fold[QueryDef](QueryDSL.any)(_.as[QueryDef])
val aggs = request.body.getValue("stats").getOrElse(throw BadRequestError("Parameter \"stats\" is missing")).as[Seq[Agg]]
cortexActionSrv.stats(query, aggs).map(s Ok(s))
}

def getActions(entityType: String, entityId: String): Action[Fields] = authenticated(Roles.read).async(fieldsBodyParser) { implicit request
import org.elastic4play.services.QueryDSL._
val range = request.body.getString("range")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class CortexActionSrv @Inject() (
findSrv[ActionModel, Action](actionModel, queryDef, range, sortBy)
}

def stats(queryDef: QueryDef, aggs: Seq[Agg]): Future[JsObject] = findSrv(actionModel, queryDef, aggs: _*)

def getAction(actionId: String): Future[Action] = {
getSrv[ActionModel, Action](actionModel, actionId)
}
Expand Down

0 comments on commit 546a054

Please sign in to comment.