timeline JSON API - closes #1654
This commit is contained in:
parent
c8c4d3128e
commit
53278a4a27
|
@ -51,9 +51,4 @@ object Lobby extends LilaController {
|
|||
me =>
|
||||
Env.timeline.entryRepo.userEntries(me.id) map { html.timeline.entries(_) }
|
||||
}
|
||||
|
||||
def timelineMore = Auth { implicit ctx =>
|
||||
me =>
|
||||
Env.timeline.entryRepo.moreUserEntries(me.id) map { html.timeline.more(_) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,9 +14,15 @@ object Timeline extends LilaController {
|
|||
me =>
|
||||
if (HTTPRequest.isXhr(ctx.req))
|
||||
Env.timeline.entryRepo.userEntries(me.id) map { html.timeline.entries(_) }
|
||||
else negotiate(
|
||||
html = Env.timeline.entryRepo.moreUserEntries(me.id) map { html.timeline.more(_) },
|
||||
_ => ???)
|
||||
else {
|
||||
import lila.timeline.Entry.entryWrites
|
||||
val nb = getInt("nb").fold(100)(_ min 100)
|
||||
val entries = Env.timeline.entryRepo.moreUserEntries(me.id, nb)
|
||||
negotiate(
|
||||
html = entries map { html.timeline.more(_) },
|
||||
_ => entries map { es => Ok(Json.obj("entries" -> es)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def unsub(channel: String) = Auth { implicit ctx =>
|
||||
|
|
|
@ -62,4 +62,11 @@ object Entry {
|
|||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
import reactivemongo.bson.Macros
|
||||
implicit val EntryBSONHandler = Macros.handler[Entry]
|
||||
|
||||
implicit val entryWrites = OWrites[Entry] { e =>
|
||||
Json.obj(
|
||||
"type" -> e.typ,
|
||||
"data" -> e.data,
|
||||
"date" -> e.date)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ private[timeline] final class EntryRepo(coll: Coll, userMax: Int) {
|
|||
def userEntries(userId: String): Fu[List[Entry]] =
|
||||
userEntries(userId, userMax)
|
||||
|
||||
def moreUserEntries(userId: String): Fu[List[Entry]] =
|
||||
userEntries(userId, 100)
|
||||
def moreUserEntries(userId: String, nb: Int): Fu[List[Entry]] =
|
||||
userEntries(userId, nb)
|
||||
|
||||
private def userEntries(userId: String, max: Int): Fu[List[Entry]] =
|
||||
coll.find(BSONDocument("users" -> userId))
|
||||
|
|
Loading…
Reference in a new issue