diff --git a/app/controllers/ElectionsApi.scala b/app/controllers/ElectionsApi.scala index f4ae368..443becd 100644 --- a/app/controllers/ElectionsApi.scala +++ b/app/controllers/ElectionsApi.scala @@ -928,6 +928,36 @@ object ElectionsApi )) }} + def getAuthoritiesState = Action.async { request => + Future.sequence( + authorities.keys.map { authorityId => + val url = eoUrl(authorityId, "public_api/check_state") + + WS.url(url).get().map { resp => + if(resp.status == HTTP.ACCEPTED) { + authorityId -> Json.obj( + "state" -> "ok", + "message" -> "" + ) + } else { + authorityId -> Json.obj( + "state" -> "error", + "message" -> s"Error: EO returned status ${resp.status} with body ${resp.body}" + ) + } + }.recover { + case e: Exception => authorityId -> Json.obj( + "state" -> "error", + "message" -> s"Exception: ${e.getMessage}" + ) + } + }.toSeq + ).map { results => + val res = results.toMap + Ok(response(res)) + } + } + def checkAuthorityUser(authority_id: String, username: String, password: String): Boolean = { if(!authorities.contains(authority_id)) { Logger.info(s"Authority id not found") diff --git a/conf/routes b/conf/routes index aaded31..a21cb9b 100644 --- a/conf/routes +++ b/conf/routes @@ -44,6 +44,7 @@ GET /api/election/:id/results controllers.Electi GET /api/election/:id/voters controllers.ElectionsApi.getElectionVoters(id: Long) GET /api/election/:id/stats controllers.ElectionsApi.getElectionStats(id: Long) GET /api/authorities controllers.ElectionsApi.getAuthorities +GET /api/authorities-state controllers.ElectionsApi.getAuthoritiesState # ballotbox POST /api/election/:id/voter/:voterId controllers.BallotboxApi.vote(id: Long, voterId: String)