lila/modules/ublog/src/main/UblogPost.scala

55 lines
1.0 KiB
Scala
Raw Normal View History

2021-08-29 03:03:02 -06:00
package lila.ublog
import org.joda.time.DateTime
2021-08-30 04:32:06 -06:00
import lila.memo.PicfitImage
2021-08-29 03:03:02 -06:00
import lila.user.User
case class UblogPost(
_id: UblogPost.Id,
user: User.ID,
title: String,
intro: String,
markdown: String,
2021-08-30 04:32:06 -06:00
image: Option[PicfitImage.Id],
2021-08-29 03:58:31 -06:00
live: Boolean,
2021-08-29 03:03:02 -06:00
createdAt: DateTime,
2021-08-29 03:58:31 -06:00
updatedAt: DateTime,
liveAt: Option[DateTime]
2021-08-29 03:03:02 -06:00
) {
2021-08-29 03:58:31 -06:00
def id = _id
2021-09-01 01:26:15 -06:00
lazy val slug = UblogPost slug title
2021-08-29 04:36:52 -06:00
def isBy(u: User) = user == u.id
2021-08-29 03:03:02 -06:00
}
object UblogPost {
case class Id(value: String) extends AnyVal with StringValue
2021-08-31 05:10:05 -06:00
case class Create(post: UblogPost) extends AnyVal
2021-09-01 01:26:15 -06:00
case class LightPost(_id: UblogPost.Id, title: String) {
def id = _id
def slug = UblogPost slug title
}
2021-09-01 04:57:19 -06:00
// case class PreviewPost(
// _id: UblogPost.Id,
// title: String,
// intro: String,
// image: Option[PicfitImage.Id],
// liveAt: DateTime
// ) {
// def id = _id
// def slug = UblogPost slug title
// }
2021-09-01 01:26:15 -06:00
def slug(title: String) = {
val s = lila.common.String slugify title
if (s.isEmpty) "-" else s
}
2021-08-29 03:03:02 -06:00
}