lila/modules/video/src/main/View.scala

57 lines
1.1 KiB
Scala
Raw Normal View History

2015-03-22 03:34:35 -06:00
package lila.video
import org.joda.time.DateTime
case class View(
2017-08-23 17:56:39 -06:00
id: String, // userId/videoId
videoId: Video.ID,
userId: String,
date: DateTime
)
2015-03-22 03:34:35 -06:00
2015-04-15 03:51:53 -06:00
case class VideoView(video: Video, view: Boolean)
2015-03-22 03:34:35 -06:00
object View {
2015-03-22 03:39:10 -06:00
def makeId(videoId: Video.ID, userId: String) = s"$videoId/$userId"
2015-03-22 03:34:35 -06:00
2020-05-05 22:11:15 -06:00
def make(videoId: Video.ID, userId: String) =
View(
id = makeId(videoId, userId),
videoId = videoId,
userId = userId,
date = DateTime.now
)
2015-03-22 13:03:21 -06:00
2015-03-22 03:34:35 -06:00
object BSONFields {
2019-12-13 07:30:20 -07:00
val id = "_id"
2015-03-22 03:34:35 -06:00
val videoId = "v"
2019-12-13 07:30:20 -07:00
val userId = "u"
val date = "d"
2015-03-22 03:34:35 -06:00
}
2019-11-29 19:16:11 -07:00
import reactivemongo.api.bson._
import lila.db.BSON
import BSON.BSONJodaDateTimeHandler
implicit val viewBSONHandler = new BSON[View] {
import BSONFields._
2020-05-05 22:11:15 -06:00
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
)
}
2015-03-22 03:34:35 -06:00
}