parent
0238268d34
commit
d57b9eabe2
@ -1,5 +1,6 @@
|
||||
package fr.uca.iut.urbandictionarylight.model
|
||||
|
||||
data class Definition(val content: String, var upvotes: UInt = 0u, val example: String) {
|
||||
data class Definition(val content: String, val example: String) {
|
||||
var upvotes: UInt = 0u
|
||||
fun upvote() { upvotes++ }
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package fr.uca.iut.urbandictionarylight.model
|
||||
|
||||
class Dictionary {
|
||||
private val entries: MutableSet<Entry> = mutableSetOf()
|
||||
|
||||
fun createEntry(entry: Entry) {
|
||||
if (entry.phrase.isNotBlank() && entry.readAllDefinitions().isNotEmpty()) {
|
||||
entries.add(entry)
|
||||
}
|
||||
}
|
||||
|
||||
fun readEntry(id: Int): Entry {
|
||||
// TODO implement once ORM is in place
|
||||
return Entry(phrase = "womp womp -- WIP").also { e -> e.createDefinition(e.readDefinition(-1)) }
|
||||
}
|
||||
|
||||
fun readAllEntries() = entries.toSet()
|
||||
|
||||
fun updateEntry(entry: Entry) {
|
||||
// TODO implement once ORM is in place
|
||||
// removeEntry(entry.id)
|
||||
createEntry(entry)
|
||||
}
|
||||
|
||||
// TODO throw this away soon
|
||||
fun updateEntry(old: Entry, new: Entry) {
|
||||
deleteEntry(old)
|
||||
createEntry(new)
|
||||
}
|
||||
|
||||
fun deleteEntry(entry: Entry) {
|
||||
entries.remove(entry)
|
||||
}
|
||||
|
||||
fun deleteEntry(id: Int) {
|
||||
// TODO implement once ORM is in place
|
||||
// entries.removeIf { e -> id == e.id }
|
||||
}
|
||||
|
||||
// TODO ? redefine equals and hashset ?
|
||||
}
|
Loading…
Reference in new issue