PageRenderTime 25ms CodeModel.GetById 3ms RepoModel.GetById 0ms app.codeStats 0ms

/app/models/Post.scala

https://bitbucket.org/edofic/poster
Scala | 30 lines | 19 code | 6 blank | 5 comment | 0 complexity | a6061f52f0765acd95e745eacf5a485f MD5 | raw file
  1. package models
  2. import play.api.Play.current
  3. import com.novus.salat._
  4. import com.novus.salat.dao._
  5. import com.novus.salat.global._
  6. import com.mongodb.casbah.Imports._
  7. import se.radley.plugin.salat._
  8. /**
  9. * User: andraz
  10. * Date: 12/6/12
  11. * Time: 8:04 AM
  12. */
  13. case class Post(_id: ObjectId = new ObjectId,
  14. content: String,
  15. user: String,
  16. tags: Seq[String]
  17. )
  18. object Post{
  19. object dao extends SalatDAO[Post, ObjectId](collection = mongoCollection("posts"))
  20. def all =
  21. dao.find(MongoDBObject()).sort(MongoDBObject("_id" -> -1))
  22. def tagged(tag: String) = dao.find(MongoDBObject("tags" -> tag)).sort(MongoDBObject("_id" -> -1))
  23. def fromUser(user: String) = dao.find(MongoDBObject("user" -> user)).sort(MongoDBObject("_id" -> -1))
  24. }