Commit 0f4c1b22 authored by Björn Eyselein's avatar Björn Eyselein
Browse files

Refactorings + update Scala 2.13

parent 3bf3582d
......@@ -11,7 +11,7 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class AdminController @Inject()(cc: ControllerComponents, protected val tableDefs: TableDefs)(implicit protected val ec: ExecutionContext)
extends AbstractController(cc) with ControllerHelpers with play.api.i18n.I18nSupport {
extends AbstractController(cc) with NewControllerHelpers with play.api.i18n.I18nSupport {
override protected val adminRightsRequired: Boolean = true
......
......@@ -11,7 +11,7 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class ApiController @Inject()(cc: ControllerComponents, protected val tableDefs: TableDefs)(implicit protected val ec: ExecutionContext)
extends AbstractController(cc) with ControllerHelpers {
extends AbstractController(cc) with NewControllerHelpers {
private val logger = Logger(classOf[ApiController])
......
......@@ -10,7 +10,7 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class HomeController @Inject()(cc: ControllerComponents, protected val tableDefs: TableDefs)(implicit protected val ec: ExecutionContext)
extends AbstractController(cc) with ControllerHelpers with play.api.i18n.I18nSupport {
extends AbstractController(cc) with NewControllerHelpers with play.api.i18n.I18nSupport {
// private val logger = Logger(classOf[HomeController])
......
......@@ -11,7 +11,7 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class LtiController @Inject()(cc: ControllerComponents, protected val tableDefs: TableDefs)(implicit protected val ec: ExecutionContext)
extends AbstractController(cc) with ControllerHelpers with play.api.i18n.I18nSupport {
extends AbstractController(cc) with NewControllerHelpers with play.api.i18n.I18nSupport {
override protected val adminRightsRequired: Boolean = false
......
......@@ -6,7 +6,7 @@ import play.api.mvc._
import scala.concurrent.{ExecutionContext, Future}
trait ControllerHelpers extends Secured {
trait NewControllerHelpers extends Secured {
self: AbstractController =>
protected implicit val ec: ExecutionContext
......
......@@ -12,25 +12,43 @@ object JsonFormats {
// Result
private implicit val charFormat: Format[Char] = Format({
private val charFormat: Format[Char] = Format({
case JsString(str) => JsSuccess(str.charAt(0))
case _ => JsError("")
}, x => JsString(x.toString))
private implicit val operationTypeFormat: Format[OperationType] = OperationType.jsonFormat
private val operationTypeFormat: Format[OperationType] = OperationType.jsonFormat
private implicit val editOperationFormat: Format[EditOperation] = Json.format[EditOperation]
private val editOperationFormat: Format[EditOperation] = {
implicit val cf: Format[Char] = charFormat
private implicit val answerSelectionResultFormat: Format[AnswerSelectionResult] = Json.format[AnswerSelectionResult]
implicit val otf: Format[OperationType] = operationTypeFormat
val completeCorrectionResultFormat: Format[CorrectionResult] = Json.format[CorrectionResult]
Json.format[EditOperation]
}
private val answerSelectionResultFormat: Format[AnswerSelectionResult] = Json.format[AnswerSelectionResult]
val completeCorrectionResultFormat: Format[CorrectionResult] = {
implicit val eof: Format[EditOperation] = editOperationFormat
implicit val asrf: Format[AnswerSelectionResult] = answerSelectionResultFormat
Json.format[CorrectionResult]
}
// Flashcard
private implicit val choiceAnswerFormat: Format[ChoiceAnswer] = Json.format[ChoiceAnswer]
private val choiceAnswerFormat: Format[ChoiceAnswer] = Json.format[ChoiceAnswer]
private val blanksAnswerFragmentFormat: Format[BlanksAnswerFragment] = Json.format[BlanksAnswerFragment]
val flashcardToAnswerFormat: Format[FlashcardToAnswer] = {
implicit val caf: Format[ChoiceAnswer] = choiceAnswerFormat
private implicit val blanksAnswerFragmentFormat: Format[BlanksAnswerFragment] = Json.format[BlanksAnswerFragment]
implicit val baff: Format[BlanksAnswerFragment] = blanksAnswerFragmentFormat
val flashcardToAnswerFormat: Format[FlashcardToAnswer] = Json.format[FlashcardToAnswer]
Json.format[FlashcardToAnswer]
}
}
......@@ -31,19 +31,16 @@ trait TableQueries {
val frontToSend = if (frontToBack) front else back
val frontHintToSend = if (frontToBack) frontHint else backHint
val currentTries = maybeOldAnswer.map {
oldAnswer => if (oldAnswer.isActive) oldAnswer.wrongTries else 0
}.getOrElse(0)
val currentBucket = maybeOldAnswer.map(_.bucket)
Some(
FlashcardToAnswer(
cardId, collId, courseId, cardType,
frontToSend, frontHintToSend, frontToBack,
frontToSend,
frontHintToSend,
frontToBack,
blanksAnswersForDbFlashcard,
choiceAnswersForDBFlashcard,
currentTries,
currentBucket
currentTries = maybeOldAnswer.map { oa => if (oa.isActive) oa.wrongTries else 0 }.getOrElse(0),
currentBucket = maybeOldAnswer.map(_.bucket)
)
)
}
......
......@@ -9,7 +9,7 @@ lazy val root = (project in file(".")).enablePlugins(PlayScala)
TwirlKeys.templateImports += "model.TemplateConsts._"
scalaVersion := "2.12.8"
scalaVersion := "2.13.0"
updateOptions := updateOptions.value.withCachedResolution(cachedResoluton = true)
resolveFromWebjarsNodeModulesDir := true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment