ublog WIP
parent
8abe61d0c9
commit
fb8b6de80e
|
@ -38,7 +38,8 @@ lazy val modules = Seq(
|
|||
playban, insight, perfStat, irc, quote, challenge,
|
||||
study, studySearch, fishnet, explorer, learn, plan,
|
||||
event, coach, practice, evalCache, irwin,
|
||||
activity, relay, streamer, bot, clas, swiss, storm, racer
|
||||
activity, relay, streamer, bot, clas, swiss, storm, racer,
|
||||
ublog
|
||||
)
|
||||
|
||||
lazy val moduleRefs = modules map projectToRef
|
||||
|
@ -111,6 +112,11 @@ lazy val blog = module("blog",
|
|||
Seq(prismic, specs2) ++ reactivemongo.bundle
|
||||
)
|
||||
|
||||
lazy val ublog = module("ublog",
|
||||
Seq(common, memo, timeline),
|
||||
Seq(specs2) ++ reactivemongo.bundle
|
||||
)
|
||||
|
||||
lazy val evaluation = module("evaluation",
|
||||
Seq(common, hub, db, user, game, analyse),
|
||||
Seq(specs2) ++ reactivemongo.bundle
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package lila.ublog
|
||||
|
||||
import com.softwaremill.macwire._
|
||||
|
||||
import lila.common.config._
|
||||
|
||||
@Module
|
||||
final class Env(
|
||||
db: lila.db.Db,
|
||||
userRepo: lila.user.UserRepo
|
||||
)(implicit
|
||||
ec: scala.concurrent.ExecutionContext
|
||||
) {
|
||||
private val postColl = db(CollName("ublog_post"))
|
||||
|
||||
val api = wire[UblogApi]
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package lila.ublog
|
||||
|
||||
import lila.db.dsl._
|
||||
import lila.user.User
|
||||
import scala.concurrent.ExecutionContext
|
||||
|
||||
final class UblogApi(coll: Coll)(implicit ec: ExecutionContext) {
|
||||
|
||||
import UblogBsonHandlers._
|
||||
|
||||
def create(data: UblogForm.UblogPostData, user: User): Fu[UblogPost] = {
|
||||
val post = UblogPost.make(user, data.title, data.intro, data.markdown)
|
||||
coll.insert.one(post) inject post
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package lila.ublog
|
||||
|
||||
import lila.db.dsl._
|
||||
import reactivemongo.api.bson._
|
||||
|
||||
private[ublog] object UblogBsonHandlers {
|
||||
|
||||
implicit val postIdBSONHandler = stringAnyValHandler[UblogPost.Id](_.value, UblogPost.Id.apply)
|
||||
implicit val postBSONHandler = Macros.handler[UblogPost]
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package lila.ublog
|
||||
|
||||
import play.api.data._
|
||||
import play.api.data.Forms._
|
||||
import lila.common.Form.{ cleanNonEmptyText, cleanText }
|
||||
|
||||
final class UblogForm {
|
||||
|
||||
import UblogForm._
|
||||
|
||||
val form = Form(
|
||||
mapping(
|
||||
"title" -> cleanNonEmptyText(minLength = 3, maxLength = 100),
|
||||
"intro" -> cleanNonEmptyText(minLength = 0, maxLength = 2_000),
|
||||
"markdown" -> cleanNonEmptyText(minLength = 0, maxLength = 100_000)
|
||||
)(UblogPostData.apply)(UblogPostData.unapply)
|
||||
)
|
||||
}
|
||||
|
||||
object UblogForm {
|
||||
|
||||
case class UblogPostData(title: String, intro: String, markdown: String)
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package lila.ublog
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
import lila.user.User
|
||||
|
||||
case class UblogPost(
|
||||
_id: UblogPost.Id,
|
||||
user: User.ID,
|
||||
title: String,
|
||||
intro: String,
|
||||
markdown: String,
|
||||
createdAt: DateTime,
|
||||
updatedAt: DateTime
|
||||
) {
|
||||
|
||||
lazy val slug = {
|
||||
val s = lila.common.String slugify title
|
||||
if (s.isEmpty) "-" else s
|
||||
}
|
||||
}
|
||||
|
||||
object UblogPost {
|
||||
|
||||
def make(user: User, title: String, intro: String, markdown: String) =
|
||||
UblogPost(
|
||||
_id = Id(lila.common.ThreadLocalRandom nextString 8),
|
||||
user = user.id,
|
||||
title = title,
|
||||
intro = intro,
|
||||
markdown = markdown,
|
||||
createdAt = DateTime.now,
|
||||
updatedAt = DateTime.now
|
||||
)
|
||||
|
||||
case class Id(value: String) extends AnyVal with StringValue
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package lila
|
||||
|
||||
package object ublog extends PackageObject {
|
||||
|
||||
private[ublog] val logger = lila.log("ublog")
|
||||
}
|
Loading…
Reference in New Issue