Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Björn Eyselein
wuekabel
Commits
957f5a1a
Commit
957f5a1a
authored
May 22, 2019
by
Björn Eyselein
Browse files
Small updates db
parent
cd29da73
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/model/Models.scala
View file @
957f5a1a
...
...
@@ -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
)
...
...
app/model/persistence/PersistenceModels.scala
View file @
957f5a1a
...
...
@@ -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
}
app/model/persistence/TableDefs.scala
View file @
957f5a1a
...
...
@@ -64,7 +64,7 @@ class TableDefs @Inject()(override protected val dbConfigProvider: DatabaseConfi
// Views
abstract
class
FlashcardToDoView
[
T
<:
FlashcardTo
Do
Data
](
tag
:
Tag
,
tableName
:
String
)
extends
Table
[
T
](
tag
,
tableName
)
{
abstract
class
FlashcardToDoView
[
T
<:
FlashcardTo
Answer
Data
](
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
FlashcardsTo
Repeat
View
(
tag
:
Tag
)
extends
FlashcardToDoView
[
FlashcardTo
Repeat
Data
](
tag
,
"flashcards_to_
repeat
"
)
{
class
FlashcardsTo
Learn
View
(
tag
:
Tag
)
extends
FlashcardToDoView
[
FlashcardTo
Answer
Data
](
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
[
FlashcardTo
Repeat
Data
]
=
(
cardId
,
collId
,
courseId
,
username
)
<>
(
FlashcardTo
Repeat
Data
.
tupled
,
FlashcardTo
Repeat
Data
.
unapply
)
override
def
*
:
ProvenShape
[
FlashcardTo
Answer
Data
]
=
(
cardId
,
collId
,
courseId
,
username
,
leftToRight
)
<>
(
FlashcardTo
Answer
Data
.
tupled
,
FlashcardTo
Answer
Data
.
unapply
)
}
...
...
app/model/persistence/TableQueries.scala
View file @
957f5a1a
...
...
@@ -11,7 +11,7 @@ trait TableQueries {
// Helper methods
private
def
flashcardToDoFilter
(
fctd
:
FlashcardToDoView
[
_
<:
FlashcardTo
Do
Data
],
collection
:
Collection
,
user
:
User
)
:
Rep
[
Boolean
]
=
private
def
flashcardToDoFilter
(
fctd
:
FlashcardToDoView
[
_
<:
FlashcardTo
Answer
Data
],
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
:
FlashcardTo
Learn
Data
)
=>
futureFlashcardById
(
fcId
.
courseId
,
fcId
.
collId
,
fcId
.
cardId
)
case
Some
(
fcId
:
FlashcardTo
Answer
Data
)
=>
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
:
FlashcardTo
Repeat
Data
)
=>
futureFlashcardById
(
fcId
.
courseId
,
fcId
.
collId
,
fcId
.
cardId
)
case
Some
(
fcId
:
FlashcardTo
Answer
Data
)
=>
futureFlashcardById
(
fcId
.
courseId
,
fcId
.
collId
,
fcId
.
cardId
)
}
def
futureFlashcardsToRepeatCount
(
user
:
User
)
:
Future
[
Int
]
=
db
.
run
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment