👔 Finish early draft of model

main
Alexis Drai 1 year ago
parent 2021ec5db4
commit 0238268d34

@ -1,3 +1,5 @@
package fr.uca.iut.urbandictionarylight.model
data class Definition (var content: String, var upvotes: UInt, var example: String){}
data class Definition(val content: String, var upvotes: UInt = 0u, val example: String) {
fun upvote() { upvotes++ }
}

@ -1,5 +1,59 @@
package fr.uca.iut.urbandictionarylight.model
class Entry (val phrase: String){
val definitions: MutableSet<Definition> = mutableSetOf()
import fr.uca.iut.urbandictionarylight.utils.Sorting
class Entry(val phrase: String) {
private val definitions: MutableSet<Definition> = mutableSetOf()
fun createDefinition(definition: Definition) {
if (definition.content.isNotBlank() && definition.example.isNotBlank()) {
definitions.add(definition)
}
}
fun readDefinition(id: Int): Definition {
// TODO implement once ORM is in place
return Definition(
content = "poopy butt",
example = "Yeah, that's right -- poopy butt. This method hasn't been implemented yet."
)
}
fun readAllDefinitions() = definitions.toSet()
// TODO implement
fun readAllDefinitions(criterion: Sorting): Set<Definition> {
when (criterion) {
Sorting.ASC -> {
print("implement asc sorting!")
return readAllDefinitions()
}
Sorting.DESC -> {
print("implement desc sorting!")
return readAllDefinitions()
}
else -> return readAllDefinitions()
}
}
fun updateDefinition(definition: Definition) {
// TODO implement once ORM is in place
// removeDefinition(definition.id)
createDefinition(definition)
}
// TODO throw this away soon
fun updateDefinition(old: Definition, new: Definition) {
deleteDefinition(old)
createDefinition(new)
}
fun deleteDefinition(definition: Definition) {
definitions.remove(definition)
}
fun deleteDefinition(id: Int) {
// TODO implement once ORM is in place
// definitions.removeIf { def -> id == def.id }
}
}

@ -0,0 +1,5 @@
package fr.uca.iut.urbandictionarylight.utils
public enum class Sorting {
ASC, DESC
}
Loading…
Cancel
Save