expose created hook/seek id in mobile API

This commit is contained in:
Thibault Duplessis 2014-12-26 11:43:50 +01:00
parent 103d77c677
commit e5858b5f2c
2 changed files with 17 additions and 6 deletions

View file

@ -93,7 +93,12 @@ object Setup extends LilaController with TheftPrevention with play.api.http.Cont
api = _ => BadRequest(err.errorsAsJson).fuccess),
config => (ctx.userId ?? Env.relation.api.blocking) flatMap { blocking =>
JsonOk {
env.processor.hook(config, uid, lila.common.HTTPRequest sid req, blocking) inject Json.obj("ok" -> true)
env.processor.hook(config, uid, lila.common.HTTPRequest sid req, blocking) map { hookId =>
Json.obj(
"ok" -> true,
"hook" -> Json.obj(
"id" -> hookId))
}
}
}
)

View file

@ -53,12 +53,18 @@ private[setup] final class Processor(
config: HookConfig,
uid: String,
sid: Option[String],
blocking: Set[String])(implicit ctx: UserContext): Funit =
saveConfig(_ withHook config) >>- {
blocking: Set[String])(implicit ctx: UserContext): Fu[String] =
saveConfig(_ withHook config) >> {
config.hook(uid, ctx.me, sid, blocking) match {
case Left(hook) => lobby ! AddHook(hook)
case Right(Some(seek)) => lobby ! AddSeek(seek)
case _ =>
case Left(hook) => fuccess {
lobby ! AddHook(hook)
hook.id
}
case Right(Some(seek)) => fuccess {
lobby ! AddSeek(seek)
seek.id
}
case _ => fufail("Can't create seek")
}
}