Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Last active September 16, 2015 01:43
Show Gist options
  • Select an option

  • Save paulosuzart/bca3beb8f5742598cde1 to your computer and use it in GitHub Desktop.

Select an option

Save paulosuzart/bca3beb8f5742598cde1 to your computer and use it in GitHub Desktop.
def delete(groupName: String, teamName: String, seqNumber: Int) = (baseAction andThen authAction) { request =>
apiActor ! DeleteCommand(CommandKey(seqNumber, teamName, groupName))
Ok("Command enqueued for deletion")
}
def delete(command: Future[Command]): Future[Int] = command.flatMap { c =>
val q = commands.filter(_.id === c.id).map(_.deleted)
Logger.debug(q.updateStatement)
dbConfig.db.run(q.update(true))
}
def findAndDelete = find _ >>> delete _
def comment(command: Future[Command])(content: Option[String]): Future[Int] = command.flatMap { c =>
val q = commands.filter(_.id === c.id).map(_.comment)
Logger.debug(q.updateStatement)
val commentF = dbConfig.db.run(q.update(content.getOrElse("")))
commentF onFailure {
case f => Logger.error(s"Failed badly while updatind comment for $c. ")
}
commentF
}
//====
@Singleton
class AuthAction @Inject()(developerDAO: DeveloperDAO) extends ActionRefiner[BaseRequest, AuthenticatedRequest] {
def refine[A](input: BaseRequest[A]) = {
val p = Promise[Either[Result, AuthenticatedRequest[A]]]
val authenticate: Future[Developer] = developerDAO.getDeveloperByToken(input.mhToken)
authenticate onFailure {
case _ => p.success(Left(Results.Status(Status.UNAUTHORIZED)))
}
authenticate map { developer: Developer =>
p.success(Right(new AuthenticatedRequest(developer.id.get, input)))
}
p.future
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment