Commit 957f5a1a authored by Björn Eyselein's avatar Björn Eyselein
Browse files

Small updates db

parent cd29da73
......@@ -96,7 +96,7 @@ final case class FlashcardIdentifier(cardId: Int, collId: Int, courseId: Int) {
final case class UserAnsweredFlashcard(username: String, cardId: Int, collId: Int, courseId: Int, bucket: Int, dateAnswered: LocalDate, correct: Boolean, tries: Int) {
def cardIdentifier: FlashcardIdentifier = FlashcardIdentifier(cardId, collId, courseId)
// def cardIdentifier: FlashcardIdentifier = FlashcardIdentifier(cardId, collId, courseId)
def isActive: Boolean = dateAnswered.until(LocalDate.now(), ChronoUnit.DAYS) < Math.pow(3, bucket - 1)
......
......@@ -21,16 +21,8 @@ final case class DBFlashcard(cardId: Int, collId: Int, courseId: Int, cardType:
final case class DBCompleteFlashcard(flashcard: DBFlashcard, choiceAnswers: Seq[ChoiceAnswer], blanksAnswers: Seq[BlanksAnswerFragment])
trait FlashcardToDoData {
val cardId : Int
val collId : Int
val courseId: Int
val username: String
final case class FlashcardToAnswerData(cardId: Int, collId: Int, courseId: Int, username: String, leftToRight: Boolean) {
def cardIdentifier: FlashcardIdentifier = FlashcardIdentifier(cardId, collId, courseId)
}
final case class FlashcardToLearnData(cardId: Int, collId: Int, courseId: Int, username: String) extends FlashcardToDoData
final case class FlashcardToRepeatData(cardId: Int, collId: Int, courseId: Int, username: String) extends FlashcardToDoData
}
......@@ -64,7 +64,7 @@ class TableDefs @Inject()(override protected val dbConfigProvider: DatabaseConfi
// Views
abstract class FlashcardToDoView[T <: FlashcardToDoData](tag: Tag, tableName: String) extends Table[T](tag, tableName) {
abstract class FlashcardToDoView[T <: FlashcardToAnswerData](tag: Tag, tableName: String) extends Table[T](tag, tableName) {
def cardId: Rep[Int] = column[Int]("card_id")
......@@ -74,22 +74,19 @@ class TableDefs @Inject()(override protected val dbConfigProvider: DatabaseConfi
def username: Rep[String] = column[String](usernameName)
}
class FlashcardsToLearnView(tag: Tag) extends FlashcardToDoView[FlashcardToLearnData](tag, "flashcards_to_learn") {
override def * : ProvenShape[FlashcardToLearnData] = (cardId, collId, courseId, username) <> (FlashcardToLearnData.tupled, FlashcardToLearnData.unapply)
def leftToRight: Rep[Boolean] = column[Boolean]("left_to_right")
}
class FlashcardsToRepeatView(tag: Tag) extends FlashcardToDoView[FlashcardToRepeatData](tag, "flashcards_to_repeat") {
class FlashcardsToLearnView(tag: Tag) extends FlashcardToDoView[FlashcardToAnswerData](tag, "flashcards_to_learn") {
// def correct: Rep[Boolean] = column[Boolean](correctName)
override def * : ProvenShape[FlashcardToAnswerData] = (cardId, collId, courseId, username, leftToRight) <> (FlashcardToAnswerData.tupled, FlashcardToAnswerData.unapply)
// def tries: Rep[Int] = column[Int](triesName)
}
class FlashcardsToRepeatView(tag: Tag) extends FlashcardToDoView[FlashcardToAnswerData](tag, "flashcards_to_repeat") {
override def * : ProvenShape[FlashcardToRepeatData] = (cardId, collId, courseId, username) <> (FlashcardToRepeatData.tupled, FlashcardToRepeatData.unapply)
override def * : ProvenShape[FlashcardToAnswerData] = (cardId, collId, courseId, username, leftToRight) <> (FlashcardToAnswerData.tupled, FlashcardToAnswerData.unapply)
}
......
......@@ -11,7 +11,7 @@ trait TableQueries {
// Helper methods
private def flashcardToDoFilter(fctd: FlashcardToDoView[_ <: FlashcardToDoData], collection: Collection, user: User): Rep[Boolean] =
private def flashcardToDoFilter(fctd: FlashcardToDoView[_ <: FlashcardToAnswerData], collection: Collection, user: User): Rep[Boolean] =
fctd.collId === collection.id && fctd.courseId === collection.courseId && fctd.username === user.username
// FlashcardToLearn View
......@@ -34,13 +34,13 @@ trait TableQueries {
def futureMaybeNextFlashcardToLearn(user: User, course: Course, collection: Collection): Future[Option[Flashcard]] =
db.run(flashcardsToLearnTQ.filter(flashcardToDoFilter(_, collection, user)).result.headOption).flatMap {
case None => Future.successful(None)
case Some(fcId: FlashcardToLearnData) => futureFlashcardById(fcId.courseId, fcId.collId, fcId.cardId)
case Some(fcId: FlashcardToAnswerData) => futureFlashcardById(fcId.courseId, fcId.collId, fcId.cardId)
}
def futureMaybeNextFlashcardToRepeat(user: User): Future[Option[Flashcard]] =
db.run(flashcardsToRepeatTQ.filter(_.username === user.username).result.headOption).flatMap {
case None => Future.successful(None)
case Some(fcId: FlashcardToRepeatData) => futureFlashcardById(fcId.courseId, fcId.collId, fcId.cardId)
case Some(fcId: FlashcardToAnswerData) => futureFlashcardById(fcId.courseId, fcId.collId, fcId.cardId)
}
def futureFlashcardsToRepeatCount(user: User): Future[Int] = db.run(
......
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