parent
232e5eb841
commit
a20c1ecadc
|
@ -25,15 +25,10 @@ final class Env(
|
|||
}
|
||||
import settings._
|
||||
|
||||
private lazy val paginator = new VideoPaginator(
|
||||
videoColl = videoColl,
|
||||
viewColl = viewColl)
|
||||
|
||||
lazy val api = new VideoApi(
|
||||
videoColl = videoColl,
|
||||
viewColl = viewColl,
|
||||
filterColl = filterColl,
|
||||
paginator = paginator)
|
||||
filterColl = filterColl)
|
||||
|
||||
private lazy val sheet = new Sheet(
|
||||
url = SheetUrl,
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package lila.video
|
||||
|
||||
import lila.common.paginator._
|
||||
import lila.db.paginator._
|
||||
|
||||
private[video] final class PaginatorBuilder(
|
||||
videoColl: Coll,
|
||||
viewColl: Coll,
|
||||
maxPerPage: Int) {
|
||||
|
||||
import handlers._
|
||||
|
||||
def byUser(user: User, page: Int): Fu[Paginator[VideoView]] =
|
||||
paginator(new UserAdapter(user), page)
|
||||
|
||||
private def paginator(adapter: AdapterLike[VideoView], page: Int): Fu[Paginator[VideoView]] =
|
||||
Paginator(
|
||||
adapter,
|
||||
currentPage = page,
|
||||
maxPerPage = maxPerPage
|
||||
)
|
||||
|
||||
final class UserAdapter(user: User) extends AdapterLike[VideoView] {
|
||||
|
||||
def nbResults: Fu[Int] = $count(selector)
|
||||
|
||||
def slice(offset: Int, length: Int): Fu[Seq[VideoView]] = for {
|
||||
gameIds ← $primitive(
|
||||
selector,
|
||||
"g",
|
||||
_ sort sorting skip offset,
|
||||
length.some)(_.asOpt[String])
|
||||
games ← lila.game.tube.gameTube |> { implicit t =>
|
||||
$find.byOrderedIds[Game](gameIds)
|
||||
}
|
||||
} yield games map { g => VideoView(g, user) }
|
||||
|
||||
private def selector = BookmarkRepo userIdQuery user.id
|
||||
private def sorting = $sort desc "d"
|
||||
}
|
||||
}
|
|
@ -14,10 +14,17 @@ import lila.user.{ User, UserRepo }
|
|||
private[video] final class VideoApi(
|
||||
videoColl: Coll,
|
||||
viewColl: Coll,
|
||||
filterColl: Coll,
|
||||
paginator: VideoPaginator) {
|
||||
filterColl: Coll) {
|
||||
|
||||
import handlers._
|
||||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
import reactivemongo.bson.Macros
|
||||
private implicit val YoutubeBSONHandler = {
|
||||
import Youtube.Metadata
|
||||
Macros.handler[Metadata]
|
||||
}
|
||||
private implicit val VideoBSONHandler = Macros.handler[Video]
|
||||
private implicit val TagNbBSONHandler = Macros.handler[TagNb]
|
||||
import View.viewBSONHandler
|
||||
|
||||
object video {
|
||||
|
||||
|
@ -68,7 +75,7 @@ private[video] final class VideoApi(
|
|||
doc flatMap (_.getAs[String]("_id"))
|
||||
}
|
||||
|
||||
def popular(page: Int): Fu[Paginator[VideoView]] = Paginator(
|
||||
def popular(page: Int): Fu[Paginator[Video]] = Paginator(
|
||||
adapter = new BSONAdapter[Video](
|
||||
collection = videoColl,
|
||||
selector = BSONDocument(),
|
||||
|
|
|
@ -8,8 +8,6 @@ case class View(
|
|||
userId: String,
|
||||
date: DateTime)
|
||||
|
||||
case class VideoView(video: Video, view: Boolean)
|
||||
|
||||
object View {
|
||||
|
||||
def makeId(videoId: Video.ID, userId: String) = s"$videoId/$userId"
|
||||
|
@ -26,4 +24,24 @@ object View {
|
|||
val userId = "u"
|
||||
val date = "d"
|
||||
}
|
||||
|
||||
import reactivemongo.bson._
|
||||
import lila.db.BSON
|
||||
import BSON.BSONJodaDateTimeHandler
|
||||
implicit val viewBSONHandler = new BSON[View] {
|
||||
|
||||
import BSONFields._
|
||||
|
||||
def reads(r: BSON.Reader): View = View(
|
||||
id = r str id,
|
||||
videoId = r str videoId,
|
||||
userId = r str userId,
|
||||
date = r.get[DateTime](date))
|
||||
|
||||
def writes(w: BSON.Writer, o: View) = BSONDocument(
|
||||
id -> o.id,
|
||||
videoId -> o.videoId,
|
||||
userId -> o.userId,
|
||||
date -> o.date)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package lila.video
|
||||
|
||||
import lila.db.BSON
|
||||
import lila.db.BSON.BSONJodaDateTimeHandler
|
||||
import reactivemongo.bson.Macros
|
||||
|
||||
private[video] object handlers {
|
||||
|
||||
implicit val YoutubeBSONHandler = {
|
||||
import Youtube.Metadata
|
||||
Macros.handler[Metadata]
|
||||
}
|
||||
|
||||
implicit val VideoBSONHandler = Macros.handler[Video]
|
||||
|
||||
implicit val TagNbBSONHandler = Macros.handler[TagNb]
|
||||
|
||||
implicit val viewBSONHandler = new BSON[View] {
|
||||
|
||||
import View.BSONFields._
|
||||
|
||||
def reads(r: BSON.Reader): View = View(
|
||||
id = r str id,
|
||||
videoId = r str videoId,
|
||||
userId = r str userId,
|
||||
date = r.get[DateTime](date))
|
||||
|
||||
def writes(w: BSON.Writer, o: View) = BSONDocument(
|
||||
id -> o.id,
|
||||
videoId -> o.videoId,
|
||||
userId -> o.userId,
|
||||
date -> o.date)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue