This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update(article: ArticleForUpdate): Try[Unit] = database.withSession { implicit db: Session => | |
Try((ArticleTable.filter(a => a.id === article.id).map(a => a.name ~ a.body ~ a.displayOrder)) | |
.update(article.name, article.body, article.displayOrder)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit val ArticleCreate = Json.reads[ArticleForCreation] | |
def create = IsAuthenticated { username => | |
implicit request => | |
userIdOpt.map { userId => | |
request.body.asJson.map { json => | |
json.validate[ArticleForCreation].fold( | |
invalid => { | |
BadRequest(Json.toJson(Map("error" -> invalid.head.toString))) | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait ArticlePublishedState | |
case object UNPUBLISHED extends ArticlePublishedState | |
case object PUBLISHED extends ArticlePublishedState | |
case object DIRTY extends ArticlePublishedState | |
val articlePublishedMappings = Map(UNPUBLISHED.toString() -> UNPUBLISHED, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit object ArticlePublishedReads extends Reads[ArticlePublishedState] { | |
def reads(json: JsValue) = json match { | |
case JsString(cat) => { | |
val res = articlePublishedMappings collectFirst { case (s, a) if cat.equals(s) => JsSuccess(a) } | |
res.getOrElse(JsError(Seq(JsPath() -> Seq(ValidationError("no such category"))))) | |
} | |
case _ => JsError(Seq(JsPath() -> Seq(ValidationError("validate.error.expected.jsnumber")))) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
import java.sql.Date | |
import play.Logger | |
import scala.util.{ Try, Success, Failure } | |
import play.cache.Cache | |
import org.mindrot.jbcrypt.BCrypt | |
import play.api.libs.Crypto | |
import play.libs.Scala | |
import be.objectify.deadbolt.core.models.Subject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models | |
//import play.api.db._ | |
import java.sql.Date | |
import play.Logger | |
import scala.util.{ Try, Success, Failure } | |
import play.cache.Cache | |
import org.mindrot.jbcrypt.BCrypt | |
import play.api.libs.Crypto | |
import play.libs.Scala |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo{ | |
private var fooState = 0 | |
def next:Int = { fooState = fooState + 1; fooState } | |
def getFooState:Int = fooState | |
} | |
val foo = new Foo() | |
foo.next | |
foo.next | |
val result = foo.next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Node(id:Int) | |
type SyncResponse = Either[String,List[Node]] | |
class Network { | |
var nodes: ListBuffer[Node] = ListBuffer.empty | |
val rng = scala.util.Random | |
/** | |
* Removes dead nodes | |
*/ | |
def purge:SyncResponse = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
import Scalaz._ | |
object StateTLearning extends App with StateTFunctions { | |
case class DB(v: Int) | |
val initial = DB(1) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MutableBad{ | |
class MDate(dayIn:Int){ var day = dayIn } | |
type Task = Int | |
def scheduleTask(task:Task,date:MDate) = ??? | |
var d = new MDate(22) |