API for individual threads now working

This commit is contained in:
Mark Henle 2016-09-17 08:23:15 -04:00
parent 7a60a70221
commit 2d99ad4c46
2 changed files with 15 additions and 6 deletions

View file

@ -38,7 +38,7 @@ object Message extends LilaController {
html.message.thread(thread, forms.post, blocked)
}
} map NoCache,
api = _ => OptionFuOk(api.thread(id, me)) { thread => Env.message.jsonView.thread(thread) }
api = _ => JsonOptionFuOk(api.thread(id, me)) { thread => Env.message.jsonView.thread(thread) }
)
}
}

View file

@ -30,10 +30,19 @@ final class JsonView() {
"updateAt" -> thread.updatedAt
)
def thread(thread: Thread): Fu[Result] =
Fu {
Ok(
Json.obj()
def thread(thread: Thread): Fu[JsValue] =
fuccess (
Json.obj(
"id" -> thread.id,
"name" -> thread.name,
"posts" -> thread.posts.map { post => threadPost(thread, post)}
)
}
)
def threadPost(thread: Thread, post: Post): JsValue =
Json.obj(
"sender" -> thread.senderOf(post),
"receiver" -> thread.receiverOf(post),
"text" -> post.text
)
}